[wp-trac] [WordPress Trac] #16749: Hooks alter/break array-formatted callbacks

WordPress Trac wp-trac at lists.automattic.com
Fri Mar 4 17:33:49 UTC 2011


#16749: Hooks alter/break array-formatted callbacks
--------------------------+-----------------------------
 Reporter:  Veraxus       |      Owner:
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  General       |    Version:  3.1
 Severity:  major         |   Keywords:
--------------------------+-----------------------------
 When hooking to static methods of a class (plugin, theme, etc), there are
 two possible formats:

 {{{array('class','method')}}} '''or''' {{{'class::method'}}}

 The prior works on PHP 4+, where the latter requires PHP 5.2.3+

 The problem is that any time I try to use an array-formatted callback with
 a WordPress hook (for maximum compatibility), PHP throws an invalid
 callback error for wp-includes/plugin.php.

 It turns out that the array ultimately being passed to
 {{{call_user_func_array()}}} always has an integer {{{1}}} appended to the
 array... thus making the callback invalid as {{{call_user_func_array()}}}
 is now being sent this:

 {{{ array('class','function',1) }}}

 '''String-formatted callbacks work perfectly, but array-formatted
 callbacks are altered and therefore broken.''' This can be fixed by adding
 the following check to four different functions in plugin.php
 ({{{apply_filters()}}}, {{{apply_filters_ref_array()}}},
 {{{do_action()}}}, and {{{do_action_ref_array()}}}), but I'm not sure this
 is the "best" solution.

 Here's the "corrective" check:

 {{{
 if(is_array($the_['function']) && isset($the_['function'][2])){
    unset($the_['function'][2]);
 }
 }}}

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/16749>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list