Make WordPress Core

Changeset 4177


Ignore:
Timestamp:
09/08/2006 11:19:29 PM (17 years ago)
Author:
ryan
Message:

do_action and apply_filters arg passing sanity from mdawaffe. fixes #3116

File:
1 edited

Legend:

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

    r4176 r4177  
    2727    global $wp_filter;
    2828
    29     $args = array_slice(func_get_args(), 2);
     29    $args = array($string);
     30    for ( $a = 2; $a < func_num_args(); $a++ )
     31        $args[] = func_get_arg($a);
    3032
    3133    merge_filters($tag);
     
    3840            foreach($functions as $function) {
    3941
    40                 $all_args = array_merge(array($string), $args);
    4142                $function_name = $function['function'];
    4243                $accepted_args = $function['accepted_args'];
    4344
    44                 if ( $accepted_args == 1 )
    45                     $the_args = array($string);
    46                 elseif ( $accepted_args > 1 )
    47                     $the_args = array_slice($all_args, 0, $accepted_args);
     45                if ( $accepted_args > 0 )
     46                    $the_args = array_slice($args, 0, $accepted_args);
    4847                elseif ( $accepted_args == 0 )
    4948                    $the_args = NULL;
    5049                else
    51                     $the_args = $all_args;
     50                    $the_args = $args;
    5251
    5352                $string = call_user_func_array($function_name, $the_args);
     
    103102function do_action($tag, $arg = '') {
    104103    global $wp_filter;
    105     $args = array($arg);
     104    $args = array();
     105    if ( is_array($arg) && 1 == count($arg) && is_object($arg[0]) ) // array(&$this)
     106        $args[] =& $arg[0];
     107    else
     108        $args[] = $arg;
    106109    for ( $a = 2; $a < func_num_args(); $a++ )
    107         $args[] = func_get_args($a);
     110        $args[] = func_get_arg($a);
    108111
    109112    merge_filters($tag);
     
    119122                $accepted_args = $function['accepted_args'];
    120123
    121                 if ( $accepted_args == 1 ) {
    122                     $the_args = array($arg);
    123                 } elseif ( $accepted_args > 1 ) {
     124                if ( $accepted_args > 0 )
    124125                    $the_args = array_slice($args, 0, $accepted_args);
    125                 } elseif ( $accepted_args == 0 ) {
     126                elseif ( $accepted_args == 0 )
    126127                    $the_args = NULL;
    127                 } else {
     128                else
    128129                    $the_args = $args;
    129                 }
    130130
    131131                $string = call_user_func_array($function_name, $the_args);
Note: See TracChangeset for help on using the changeset viewer.