Changeset 55160
- Timestamp:
- 01/29/2023 04:24:02 PM (22 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/includes/abstract-testcase.php
r55148 r55160 320 320 321 321 /** 322 * Saves the action and filter-related globals so they can be restored later. 323 * 324 * Stores $wp_actions, $wp_current_filter, and $wp_filter on a class variable 325 * so they can be restored on tear_down() using _restore_hooks(). 326 * 322 * Saves the hook-related globals so they can be restored later. 323 * 324 * Stores $wp_filter, $wp_actions, $wp_filters, and $wp_current_filter 325 * on a class variable so they can be restored on tear_down() using _restore_hooks(). 326 * 327 * @global array $wp_filter 327 328 * @global array $wp_actions 329 * @global array $wp_filters 328 330 * @global array $wp_current_filter 329 * @global array $wp_filter330 331 */ 331 332 protected function _backup_hooks() { 332 $globals = array( 'wp_actions', 'wp_current_filter' ); 333 self::$hooks_saved['wp_filter'] = array(); 334 335 foreach ( $GLOBALS['wp_filter'] as $hook_name => $hook_object ) { 336 self::$hooks_saved['wp_filter'][ $hook_name ] = clone $hook_object; 337 } 338 339 $globals = array( 'wp_actions', 'wp_filters', 'wp_current_filter' ); 340 333 341 foreach ( $globals as $key ) { 334 342 self::$hooks_saved[ $key ] = $GLOBALS[ $key ]; 335 343 } 336 self::$hooks_saved['wp_filter'] = array();337 foreach ( $GLOBALS['wp_filter'] as $hook_name => $hook_object ) {338 self::$hooks_saved['wp_filter'][ $hook_name ] = clone $hook_object;339 }340 344 } 341 345 … … 344 348 * so that future tests aren't affected by hooks set during this last test. 345 349 * 350 * @global array $wp_filter 346 351 * @global array $wp_actions 352 * @global array $wp_filters 347 353 * @global array $wp_current_filter 348 * @global array $wp_filter349 354 */ 350 355 protected function _restore_hooks() { 351 $globals = array( 'wp_actions', 'wp_current_filter' ); 356 if ( isset( self::$hooks_saved['wp_filter'] ) ) { 357 $GLOBALS['wp_filter'] = array(); 358 359 foreach ( self::$hooks_saved['wp_filter'] as $hook_name => $hook_object ) { 360 $GLOBALS['wp_filter'][ $hook_name ] = clone $hook_object; 361 } 362 } 363 364 $globals = array( 'wp_actions', 'wp_filters', 'wp_current_filter' ); 365 352 366 foreach ( $globals as $key ) { 353 367 if ( isset( self::$hooks_saved[ $key ] ) ) { 354 368 $GLOBALS[ $key ] = self::$hooks_saved[ $key ]; 355 }356 }357 if ( isset( self::$hooks_saved['wp_filter'] ) ) {358 $GLOBALS['wp_filter'] = array();359 foreach ( self::$hooks_saved['wp_filter'] as $hook_name => $hook_object ) {360 $GLOBALS['wp_filter'][ $hook_name ] = clone $hook_object;361 369 } 362 370 }
Note: See TracChangeset
for help on using the changeset viewer.