Make WordPress Core

Changeset 21288


Ignore:
Timestamp:
07/20/2012 01:54:42 PM (12 years ago)
Author:
nacin
Message:

Clarify the return value of has_filter() and has_action(). It returns a boolean if only the first argument is specified. If the second argument is specified, it returns false or an integer, which means it may return a non-boolean value that evaluates to false (so, 0), so you should take care to use the === operator.

Correct the function definition of remove_filter() and remove_action(), which 'accepted' an $accepted_args argument, but did not require or use it.

fixes #19417.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/plugin.php

    r21287 r21288  
    8181 *
    8282 * @param string $tag The name of the filter hook.
    83  * @param callback $function_to_check optional. If specified, return the priority of that function on this hook or false if not attached.
    84  * @return int|boolean Optionally returns the priority on that hook for the specified function.
     83 * @param callback $function_to_check optional.
     84 * @return mixed If $function_to_check is omitted, returns boolean for whether the hook has anything registered.
     85 *  When checking a specific function, the priority of that hook is returned, or false if the function is not attached.
     86 *  When using the $function_to_check argument, this function may return a non-boolean value that evaluates to false
     87 *  (e.g.) 0, so use the === operator for testing the return value.
    8588 */
    8689function has_filter($tag, $function_to_check = false) {
     
    252255 * @return boolean Whether the function existed before it was removed.
    253256 */
    254 function remove_filter($tag, $function_to_remove, $priority = 10, $accepted_args = 1) {
     257function remove_filter( $tag, $function_to_remove, $priority = 10 ) {
    255258    $function_to_remove = _wp_filter_build_unique_id($tag, $function_to_remove, $priority);
    256259
     
    495498 *
    496499 * @param string $tag The name of the action hook.
    497  * @param callback $function_to_check optional. If specified, return the priority of that function on this hook or false if not attached.
    498  * @return int|boolean Optionally returns the priority on that hook for the specified function.
     500 * @param callback $function_to_check optional.
     501 * @return mixed If $function_to_check is omitted, returns boolean for whether the hook has anything registered.
     502 *  When checking a specific function, the priority of that hook is returned, or false if the function is not attached.
     503 *  When using the $function_to_check argument, this function may return a non-boolean value that evaluates to false
     504 *  (e.g.) 0, so use the === operator for testing the return value.
    499505 */
    500506function has_action($tag, $function_to_check = false) {
     
    516522 * @param callback $function_to_remove The name of the function which should be removed.
    517523 * @param int $priority optional The priority of the function (default: 10).
    518  * @param int $accepted_args optional. The number of arguments the function accepts (default: 1).
    519524 * @return boolean Whether the function is removed.
    520525 */
    521 function remove_action($tag, $function_to_remove, $priority = 10, $accepted_args = 1) {
    522     return remove_filter($tag, $function_to_remove, $priority, $accepted_args);
     526function remove_action( $tag, $function_to_remove, $priority = 10 ) {
     527    return remove_filter( $tag, $function_to_remove, $priority );
    523528}
    524529
Note: See TracChangeset for help on using the changeset viewer.