Changeset 6324
- Timestamp:
- 11/08/2007 01:05:43 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/plugin.php
r6320 r6324 73 73 global $wp_filter, $merged_filters; 74 74 75 $idx = _wp_filter_build_unique_id($tag, $function_to_add, $priority , 'filter');75 $idx = _wp_filter_build_unique_id($tag, $function_to_add, $priority); 76 76 $wp_filter[$tag][$priority][$idx] = array('function' => $function_to_add, 'accepted_args' => $accepted_args); 77 77 unset( $merged_filters[ $tag ] ); … … 97 97 return $has; 98 98 99 if ( !$idx = _wp_filter_build_unique_id($tag, $function_to_check, false , 'filter') )99 if ( !$idx = _wp_filter_build_unique_id($tag, $function_to_check, false) ) 100 100 return false; 101 101 … … 139 139 global $wp_filter, $merged_filters, $wp_current_filter; 140 140 141 $args = array(); 141 142 @$wp_current_filter[] = $tag; 142 143 … … 144 145 if ( isset($wp_filter['all']) ) { 145 146 reset( $wp_filter['all'] ); 147 $args = func_get_args(); 146 148 do { 147 149 foreach ( (array) current($wp_filter['all']) as $the_ ) 148 150 if ( !is_null($the_['function']) ) 149 $value = call_user_func_array($the_['function'], $value);151 call_user_func_array($the_['function'], $args); 150 152 151 153 } while ( next($wp_filter['all']) !== false ); … … 166 168 reset( $wp_filter[ $tag ] ); 167 169 168 $args = func_get_args(); 170 if ( empty($args) ) 171 $args = func_get_args(); 169 172 170 173 do { … … 204 207 */ 205 208 function remove_filter($tag, $function_to_remove, $priority = 10, $accepted_args = 1) { 206 $function_to_remove = _wp_filter_build_unique_id($tag, $function_to_remove, $priority , 'filter');209 $function_to_remove = _wp_filter_build_unique_id($tag, $function_to_remove, $priority); 207 210 208 211 $r = isset($GLOBALS['wp_filter'][$tag][$priority][$function_to_remove]); … … 248 251 */ 249 252 function add_action($tag, $function_to_add, $priority = 10, $accepted_args = 1) { 250 global $wp_ action, $merged_actions;251 252 $idx = _wp_filter_build_unique_id($tag, $function_to_add, $priority , 'action');253 $wp_ action[$tag][$priority][$idx] = array('function' => $function_to_add, 'accepted_args' => $accepted_args);254 unset( $merged_ actions[ $tag ] );253 global $wp_filter, $merged_filters; 254 255 $idx = _wp_filter_build_unique_id($tag, $function_to_add, $priority); 256 $wp_filter[$tag][$priority][$idx] = array('function' => $function_to_add, 'accepted_args' => $accepted_args); 257 unset( $merged_filters[ $tag ] ); 255 258 return true; 256 259 } … … 280 283 */ 281 284 function do_action($tag, $arg = '') { 282 global $wp_ action, $wp_actions, $wp_current_filter;285 global $wp_filter, $wp_actions, $wp_current_filter; 283 286 284 287 if ( is_array($wp_actions) ) … … 286 289 else 287 290 $wp_actions = array($tag); 291 292 @$wp_current_filter[] = $tag; 293 294 // Do 'all' actions first 295 if ( isset($wp_filter['all']) ) { 296 reset( $wp_filter['all'] ); 297 $all_args = func_get_args(); 298 do { 299 foreach( (array) current($wp_filter['all']) as $the_ ) 300 if ( !is_null($the_['function']) ) 301 call_user_func_array($the_['function'], $all_args); 302 303 } while ( next($wp_filter['all']) !== false ); 304 } 305 306 if ( !isset($wp_filter[$tag]) ) { 307 array_pop($wp_current_filter); 308 return; 309 } 288 310 289 311 $args = array(); … … 295 317 $args[] = func_get_arg($a); 296 318 297 @$wp_current_filter[] = $tag;298 299 // Do 'all' actions first300 if ( isset($wp_action['all']) ) {301 do {302 foreach( (array) current($wp_action['all']) as $the_ )303 if ( !is_null($the_['function']) )304 call_user_func_array($the_['function'], $args[0]);305 306 } while ( next($wp_action['all']) !== false );307 }308 309 if ( !isset($wp_action[$tag]) ) {310 array_pop($wp_current_filter);311 return;312 }313 314 319 // Sort 315 if ( !isset( $merged_ actions[ $tag ] ) ) {316 reset($wp_ action[$tag]);317 uksort($wp_ action[$tag], "strnatcasecmp");318 $merged_ actions[ $tag ] = true;319 } 320 321 reset( $wp_ action[ $tag ] );320 if ( !isset( $merged_filters[ $tag ] ) ) { 321 reset($wp_filter[$tag]); 322 uksort($wp_filter[$tag], "strnatcasecmp"); 323 $merged_filters[ $tag ] = true; 324 } 325 326 reset( $wp_filter[ $tag ] ); 322 327 323 328 do { 324 foreach ( (array) current($wp_ action[$tag]) as $the_ )329 foreach ( (array) current($wp_filter[$tag]) as $the_ ) 325 330 if ( !is_null($the_['function']) ) 326 331 call_user_func_array($the_['function'], array_slice($args, 0, (int) $the_['accepted_args'])); 327 332 328 } while ( next($wp_ action[$tag]) !== false );333 } while ( next($wp_filter[$tag]) !== false ); 329 334 330 335 array_pop($wp_current_filter); … … 368 373 */ 369 374 function do_action_ref_array($tag, $args) { 370 global $wp_ action, $wp_actions;375 global $wp_filter, $wp_actions; 371 376 372 377 if ( !is_array($wp_actions) ) … … 376 381 377 382 // Do 'all' actions first 378 if ( isset($wp_action['all']) ) { 383 if ( isset($wp_filter['all']) ) { 384 reset( $wp_filter['all'] ); 385 $all_args = func_get_args(); 379 386 do { 380 foreach( (array) current($wp_ action['all']) as $the_ )387 foreach( (array) current($wp_filter['all']) as $the_ ) 381 388 if ( !is_null($the_['function']) ) 382 call_user_func_array($the_['function'], $a rgs[0]);383 384 } while ( next($wp_ action['all']) !== false );385 } 386 387 if ( !isset($wp_ action[$tag]) )389 call_user_func_array($the_['function'], $all_args); 390 391 } while ( next($wp_filter['all']) !== false ); 392 } 393 394 if ( !isset($wp_filter[$tag]) ) 388 395 return; 389 396 390 397 // Sort 391 if ( !isset( $merged_ actions[ $tag ] ) ) {392 reset($wp_ action[$tag]);393 uksort($wp_ action[$tag], "strnatcasecmp");394 $merged_ actions[ $tag ] = true;395 } 396 397 reset( $wp_ action[ $tag ] );398 if ( !isset( $merged_filters[ $tag ] ) ) { 399 reset($wp_filter[$tag]); 400 uksort($wp_filter[$tag], "strnatcasecmp"); 401 $merged_filters[ $tag ] = true; 402 } 403 404 reset( $wp_filter[ $tag ] ); 398 405 399 406 do { 400 foreach( (array) current($wp_ action[$tag]) as $the_ )407 foreach( (array) current($wp_filter[$tag]) as $the_ ) 401 408 if ( !is_null($the_['function']) ) 402 409 call_user_func_array($the_['function'], array_slice($args, 0, (int) $the_['accepted_args'])); 403 410 404 } while ( next($wp_ action[$tag]) !== false );411 } while ( next($wp_filter[$tag]) !== false ); 405 412 406 413 } … … 411 418 * @subpackage Plugin 412 419 * @since 2.4 413 * @global array $wp_ actionStores all of the actions420 * @global array $wp_filter Stores all of the actions 414 421 * 415 422 * @param string $tag The name of the action hook. … … 418 425 */ 419 426 function has_action($tag, $function_to_check = false) { 420 global $wp_action; 421 422 $has = !empty($wp_action[$tag]); 423 if ( false === $function_to_check || false == $has ) 424 return $has; 425 426 if ( !$idx = _wp_filter_build_unique_id($tag, $function_to_check, false, 'action') ) 427 return false; 428 429 foreach ( array_keys($wp_action[$tag]) as $priority ) { 430 if ( isset($wp_action[$tag][$priority][$idx]) ) 431 return $priority; 432 } 433 434 return false; 427 return has_filter($tag, $function_to_check); 435 428 } 436 429 … … 453 446 */ 454 447 function remove_action($tag, $function_to_remove, $priority = 10, $accepted_args = 1) { 455 $function_to_remove = _wp_filter_build_unique_id($tag, $function_to_remove, $priority, 'action'); 456 457 $r = isset($GLOBALS['wp_action'][$tag][$priority][$function_to_remove]); 458 459 if ( true === $r) { 460 unset($GLOBALS['wp_action'][$tag][$priority][$function_to_remove]); 461 if ( empty($GLOBALS['wp_action'][$tag][$priority]) ) 462 unset($GLOBALS['wp_action'][$tag][$priority]); 463 unset($GLOBALS['merged_actions'][$tag]); 464 } 465 466 return $r; 448 return remove_filter($tag, $function_to_remove, $priority, $accepted_args); 467 449 } 468 450 … … 576 558 * @return string Unique ID for usage as array key 577 559 */ 578 function _wp_filter_build_unique_id($tag, $function, $priority , $type)560 function _wp_filter_build_unique_id($tag, $function, $priority) 579 561 { 580 global $wp_filter , $wp_action;562 global $wp_filter; 581 563 582 564 // If function then just skip all of the tests and not overwrite the following. … … 589 571 if ( false === $priority ) 590 572 return false; 591 if ( 'filter' == $type ) 592 $count = count((array)$wp_filter[$tag][$priority]); 593 else 594 $count = count((array)$wp_action[$tag][$priority]); 573 $count = count((array)$wp_filter[$tag][$priority]); 595 574 $function[0]->wp_filter_id = $count; 596 575 $obj_idx .= $count;
Note: See TracChangeset
for help on using the changeset viewer.