Make WordPress Core

Ticket #14671: 14671.002.diff

File 14671.002.diff, 4.5 KB (added by markjaquith, 15 years ago)
  • wp-includes/plugin.php

     
    5959 * @param string $tag The name of the filter to hook the $function_to_add to.
    6060 * @param callback $function_to_add The name of the function to be called when the filter is applied.
    6161 * @param int $priority optional. Used to specify the order in which the functions associated with a particular action are executed (default: 10). Lower numbers correspond with earlier execution, and functions with the same priority are executed in the order in which they were added to the action.
    62  * @param int $accepted_args optional. The number of arguments the function accept (default 1).
     62 * @param int $accepted_args optional. The number of arguments the function accept (default: 1 for internal php functions, 100 for user function).
    6363 * @return boolean true
    6464 */
    65 function add_filter($tag, $function_to_add, $priority = 10, $accepted_args = 1) {
     65function add_filter($tag, $function_to_add, $priority = 10, $accepted_args = NULL) {
    6666        global $wp_filter, $merged_filters;
    6767
    6868        $idx = _wp_filter_build_unique_id($tag, $function_to_add, $priority);
     69        if ( NULL === $accepted_args && is_string( $function_to_add ) && is_internal_php_function( $function_to_add ) )
     70                $accepted_args = 1;
     71        elseif ( NULL === $accepted_args )
     72                $accepted_args = 100;
    6973        $wp_filter[$tag][$priority][$idx] = array('function' => $function_to_add, 'accepted_args' => $accepted_args);
    7074        unset( $merged_filters[ $tag ] );
    7175        return true;
     
    173177        return $value;
    174178}
    175179
     180function is_internal_php_function( $function_name ) {
     181        global $php_internal_functions;
     182        if ( !isset( $php_internal_functions ) ) {
     183                $functions = get_defined_functions();
     184                $php_internal_functions = array_flip( $functions['internal'] );
     185        }
     186        return isset( $php_internal_functions[$function_name] );
     187}
     188
    176189/**
    177190 * Execute functions hooked on a specific filter hook, specifying arguments in an array.
    178191 *
     
    244257 * @param string $tag The filter hook to which the function to be removed is hooked.
    245258 * @param callback $function_to_remove The name of the function which should be removed.
    246259 * @param int $priority optional. The priority of the function (default: 10).
    247  * @param int $accepted_args optional. The number of arguments the function accpets (default: 1).
    248260 * @return boolean Whether the function existed before it was removed.
    249261 */
    250 function remove_filter($tag, $function_to_remove, $priority = 10, $accepted_args = 1) {
     262function remove_filter( $tag, $function_to_remove, $priority = 10 ) {
    251263        $function_to_remove = _wp_filter_build_unique_id($tag, $function_to_remove, $priority);
    252264
    253265        $r = isset($GLOBALS['wp_filter'][$tag][$priority][$function_to_remove]);
     
    319331 * @param string $tag The name of the action to which the $function_to_add is hooked.
    320332 * @param callback $function_to_add The name of the function you wish to be called.
    321333 * @param int $priority optional. Used to specify the order in which the functions associated with a particular action are executed (default: 10). Lower numbers correspond with earlier execution, and functions with the same priority are executed in the order in which they were added to the action.
    322  * @param int $accepted_args optional. The number of arguments the function accept (default 1).
     334 * @param int $accepted_args optional. The number of arguments the function accept (default: 1 for internal php functions, 100 for user functions).
    323335 */
    324 function add_action($tag, $function_to_add, $priority = 10, $accepted_args = 1) {
     336function add_action($tag, $function_to_add, $priority = 10, $accepted_args = NULL) {
    325337        return add_filter($tag, $function_to_add, $priority, $accepted_args);
    326338}
    327339
     
    507519 * @param string $tag The action hook to which the function to be removed is hooked.
    508520 * @param callback $function_to_remove The name of the function which should be removed.
    509521 * @param int $priority optional The priority of the function (default: 10).
    510  * @param int $accepted_args optional. The number of arguments the function accpets (default: 1).
    511522 * @return boolean Whether the function is removed.
    512523 */
    513 function remove_action($tag, $function_to_remove, $priority = 10, $accepted_args = 1) {
    514         return remove_filter($tag, $function_to_remove, $priority, $accepted_args);
     524function remove_action( $tag, $function_to_remove, $priority = 10 ) {
     525        return remove_filter( $tag, $function_to_remove, $priority );
    515526}
    516527
    517528/**