[wp-trac] [WordPress Trac] #20776: Improve callback verification while executing hooks
WordPress Trac
wp-trac at lists.automattic.com
Tue May 29 13:52:22 UTC 2012
#20776: Improve callback verification while executing hooks
-------------------------+-----------------------------
Reporter: ericlewis | Owner:
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Plugins | Version:
Severity: normal | Keywords: has-patch
-------------------------+-----------------------------
When executing hooks, we currently have a simple callback verification:
{{{
if ( !is_null($the_['function']) )
call_user_func_array($the_['function'],
array_slice($args, 0, (int) $the_['accepted_args']));
}}}
This works in most cases, if everything is coded properly in the theme /
plugins. However, there are cases when a bad callback makes it through
this validation, such as dropping this in a theme or plugin:
{{{
add_action('init', array( NULL, 'method') );
}}}
Will cause an error you may be familiar with:
Warning: call_user_func_array() [function.call-user-func-array]: First
argument is expected to be a valid callback, 'Array' was given in
/path/to/wp/wp-includes/plugin.php on line 405.
Which can be a tricky issue to debug.
I suggest using the is_callable() php function for verification instead,
which should remove this warning from ever showing up.
--
Ticket URL: <http://core.trac.wordpress.org/ticket/20776>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list