Ticket #5231: has_filter_with_arg.diff
File has_filter_with_arg.diff, 5.8 KB (added by , 18 years ago) |
---|
-
wp-includes/plugin.php
79 79 } 80 80 81 81 /** 82 * Check if any filter has been registered for a hook. Optionally returns the priority on that hook for the specified function. 83 * @package WordPress 84 * @subpackage Plugin 85 * @since 2.4 86 * @global array $wp_filter Stores all of the filters 87 * 88 * @param string $tag The name of the filter hook. 89 * @param callback $function_to_check optional. If specified, return the priority of that function on this hook or false if not attached. 90 * @return int|boolean 91 */ 92 function has_filter($tag, $function_to_check = false) { 93 global $wp_filter; 94 95 $has = !empty($wp_filter[$tag]); 96 if ( false === $function_to_check || false == $has ) 97 return $has; 98 99 if ( !$idx = _wp_filter_build_unique_id($tag, $function_to_check, false, 'filter') ) 100 return false; 101 102 foreach ( array_keys($wp_filter[$tag]) as $priority ) { 103 if ( isset($wp_filter[$tag][$priority][$idx]) ) 104 return $priority; 105 } 106 107 return false; 108 } 109 110 /** 82 111 * Call the functions added to a filter hook. 83 112 * 84 113 * The callback functions attached to filter hook <tt>$tag</tt> are invoked by … … 180 209 181 210 if ( true === $r) { 182 211 unset($GLOBALS['wp_filter'][$tag][$priority][$function_to_remove]); 212 if ( !count($GLOBALS['wp_filter'][$tag][$priority]) ) 213 unset($GLOBALS['wp_filter'][$tag][$priority]); 183 214 unset($GLOBALS['merged_filters'][$tag]); 184 215 } 185 216 … … 325 356 * @see do_action() This function is identical, but the arguments passed to 326 357 * the functions hooked to <tt>$tag</tt> are supplied using an array. 327 358 * 328 * @uses merge_filters()329 *330 359 * @package WordPress 331 360 * @subpackage Plugin 332 361 * @since 2.1 … … 377 406 } 378 407 379 408 /** 409 * Check if any action has been registered for a hook. Optionally returns the priority on that hook for the specified function. 410 * @package WordPress 411 * @subpackage Plugin 412 * @since 2.4 413 * @global array $wp_action Stores all of the actions 414 * 415 * @param string $tag The name of the action hook. 416 * @param callback $function_to_check optional. If specified, return the priority of that function on this hook or false if not attached. 417 * @return int|boolean 418 */ 419 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; 435 } 436 437 /** 380 438 * Removes a function from a specified action hook. 381 439 * 382 440 * This function removes a function attached to a specified action hook. This 383 441 * method can be used to remove default functions attached to a specific filter 384 442 * hook and possibly replace them with a substitute. 385 443 * 386 * @uses remove_filter() Uses remove_filter to remove actions added.387 *388 444 * @package WordPress 389 445 * @subpackage Plugin 390 446 * @since 1.5 … … 402 458 403 459 if ( true === $r) { 404 460 unset($GLOBALS['wp_action'][$tag][$priority][$function_to_remove]); 461 if ( !count($GLOBALS['wp_action'][$tag][$priority]) ) 462 unset($GLOBALS['wp_action'][$tag][$priority]); 405 463 unset($GLOBALS['merged_actions'][$tag]); 406 464 } 407 465 … … 513 571 * @global array $wp_filter Storage for all of the filters and actions 514 572 * @param string $tag Used in counting how many hooks were applied 515 573 * @param string|array $function Used for creating unique id 516 * @param int $priority Used in counting how many hooks were applied574 * @param int|bool $priority Used in counting how many hooks were applied. If === false and $function is an object reference, we return the unique id only if it already has one, false otherwise. 517 575 * @param string $type filter or action 518 576 * @return string Unique ID for usage as array key 519 577 */ … … 528 586 else if (is_object($function[0]) ) { 529 587 $obj_idx = get_class($function[0]).$function[1]; 530 588 if ( !isset($function[0]->wp_filter_id) ) { 589 if ( false === $priority ) 590 return false; 531 591 if ( 'filter' == $type ) 532 592 $count = count((array)$wp_filter[$tag][$priority]); 533 593 else -
wp-includes/classes.php
238 238 } 239 239 240 240 // query_string filter deprecated. Use request filter instead. 241 global $wp_filter; 242 if ( isset($wp_filter['query_string']) ) { // Don't bother filtering and parsing if no plugins are hooked in. 241 if ( has_filter('query_string') ) { // Don't bother filtering and parsing if no plugins are hooked in. 243 242 $this->query_string = apply_filters('query_string', $this->query_string); 244 243 parse_str($this->query_string, $this->query_vars); 245 244 } -
wp-settings.php
20 20 21 21 wp_unregister_GLOBALS(); 22 22 23 unset( $wp_filter, $ cache_lastcommentmodified, $cache_lastpostdate );23 unset( $wp_filter, $wp_action, $cache_lastcommentmodified, $cache_lastpostdate ); 24 24 25 25 if ( ! isset($blog_id) ) 26 26 $blog_id = 1; -
wp-admin/includes/plugin.php
329 329 } 330 330 331 331 function get_plugin_page_hook( $plugin_page, $parent_page ) { 332 global $wp_filter;333 334 332 $hook = get_plugin_page_hookname( $plugin_page, $parent_page ); 335 if ( isset( $wp_filter[$hook] ))333 if ( has_action($hook) ) 336 334 return $hook; 337 335 else 338 336 return null;