Make WordPress Core

Ticket #14671: 14671.3.diff

File 14671.3.diff, 4.6 KB (added by jacobsantos, 15 years ago)

Corrections to 14671.002.diff : PHPdoc for new function. Lowercase constant usage. Don't define max arguments, use null instead.

  • 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).
    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
    6972        $wp_filter[$tag][$priority][$idx] = array('function' => $function_to_add, 'accepted_args' => $accepted_args);
    7073        unset( $merged_filters[ $tag ] );
    7174        return true;
     
    174177}
    175178
    176179/**
     180 * Whether function name is internal to PHP.
     181 *
     182 * @package WordPress
     183 * @since 3.1
     184 *
     185 * @global array $php_internal_functions
     186 * @param string $function_name
     187 * @return bool
     188 */
     189function is_internal_php_function( $function_name ) {
     190        global $php_internal_functions;
     191        if ( !isset( $php_internal_functions ) ) {
     192                $functions = get_defined_functions();
     193                $php_internal_functions = array_flip( $functions['internal'] );
     194        }
     195        return isset( $php_internal_functions[$function_name] );
     196}
     197
     198/**
    177199 * Execute functions hooked on a specific filter hook, specifying arguments in an array.
    178200 *
    179201 * @see apply_filters() This function is identical, but the arguments passed to the
     
    244266 * @param string $tag The filter hook to which the function to be removed is hooked.
    245267 * @param callback $function_to_remove The name of the function which should be removed.
    246268 * @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).
    248269 * @return boolean Whether the function existed before it was removed.
    249270 */
    250 function remove_filter($tag, $function_to_remove, $priority = 10, $accepted_args = 1) {
     271function remove_filter( $tag, $function_to_remove, $priority = 10 ) {
    251272        $function_to_remove = _wp_filter_build_unique_id($tag, $function_to_remove, $priority);
    252273
    253274        $r = isset($GLOBALS['wp_filter'][$tag][$priority][$function_to_remove]);
     
    319340 * @param string $tag The name of the action to which the $function_to_add is hooked.
    320341 * @param callback $function_to_add The name of the function you wish to be called.
    321342 * @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).
     343 * @param int $accepted_args Optional. The number of arguments the function accept (default: 1 for internal php functions).
    323344 */
    324 function add_action($tag, $function_to_add, $priority = 10, $accepted_args = 1) {
     345function add_action($tag, $function_to_add, $priority = 10, $accepted_args = null) {
    325346        return add_filter($tag, $function_to_add, $priority, $accepted_args);
    326347}
    327348
     
    507528 * @param string $tag The action hook to which the function to be removed is hooked.
    508529 * @param callback $function_to_remove The name of the function which should be removed.
    509530 * @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).
    511531 * @return boolean Whether the function is removed.
    512532 */
    513 function remove_action($tag, $function_to_remove, $priority = 10, $accepted_args = 1) {
    514         return remove_filter($tag, $function_to_remove, $priority, $accepted_args);
     533function remove_action( $tag, $function_to_remove, $priority = 10 ) {
     534        return remove_filter( $tag, $function_to_remove, $priority );
    515535}
    516536
    517537/**