Changeset 6751 for trunk/src/includes/core/abstraction.php
- Timestamp:
- 12/08/2017 02:09:08 PM (9 years ago)
- File:
-
- 1 edited
-
trunk/src/includes/core/abstraction.php (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/includes/core/abstraction.php
r6739 r6751 74 74 } 75 75 76 /** Globals *******************************************************************/ 77 76 78 /** 77 79 * Lookup and return a global variable … … 144 146 return bbp_get_global_object( 'wpdb', 'WPDB' ); 145 147 } 148 149 /** Pagination ****************************************************************/ 146 150 147 151 /** … … 302 306 } 303 307 308 /** Multisite *****************************************************************/ 309 304 310 /** 305 311 * Is this a large bbPress installation? … … 359 365 * @since 2.6.0 bbPress (r6733) 360 366 */ 361 function bbp_restore_current_site( ) {367 function bbp_restore_current_site() { 362 368 363 369 // Switch back to the original site … … 365 371 restore_current_blog(); 366 372 } 373 } 374 375 /** Interception **************************************************************/ 376 377 /** 378 * Generate a default intercept value. 379 * 380 * @since 2.6.0 381 * 382 * @staticvar mixed $rand Null by default, random string on first call 383 * 384 * @return string 385 */ 386 function bbp_default_intercept() { 387 static $rand = null; 388 389 // Generate a new random and unique string 390 if ( null === $rand ) { 391 392 // If ext/hash is not present, compat.php's hash_hmac() does not support sha256. 393 $algo = function_exists( 'hash' ) 394 ? 'sha256' 395 : 'sha1'; 396 397 // Old WP installs may not have AUTH_SALT defined. 398 $salt = defined( 'AUTH_SALT' ) && AUTH_SALT 399 ? AUTH_SALT 400 : (string) wp_rand(); 401 402 // Create unique ID 403 $rand = hash_hmac( $algo, uniqid( $salt, true ), $salt ); 404 } 405 406 // Return random string (from locally static variable) 407 return $rand; 408 } 409 410 /** 411 * Whether a value has been intercepted 412 * 413 * @since 2.6.0 414 * 415 * @param bool $value 416 */ 417 function bbp_is_intercepted( $value = '' ) { 418 return ( bbp_default_intercept() === $value ); 419 } 420 421 /** 422 * Allow interception of a method or function call. 423 * 424 * @since 2.6.0 425 * 426 * @param string $action Typically the name of the caller function 427 * @param array $args Typically the results of caller function func_get_args() 428 * 429 * @return mixed Intercept results. Default bbp_default_intercept(). 430 */ 431 function bbp_maybe_intercept( $action = '', $args = array() ) { 432 433 // Backwards compatibility juggle 434 $hook = ( false === strpos( $action, 'pre_' ) ) 435 ? "pre_{$action}" 436 : $action; 437 438 // Sanitize the hook same 439 $key = sanitize_key( $hook ); 440 441 // Default return value 442 $default = bbp_default_intercept(); 443 444 // Filter and return 445 return apply_filters( $key, $default, extract( (array) $args ) ); 367 446 } 368 447
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)