[wp-trac] [WordPress Trac] #22218: Extra add_action() Parameter
WordPress Trac
noreply at wordpress.org
Thu Oct 18 13:36:48 UTC 2012
#22218: Extra add_action() Parameter
-----------------------------+--------------------------
Reporter: dgwyer | Type: defect (bug)
Status: new | Priority: normal
Milestone: Awaiting Review | Component: General
Version: 3.4.2 | Severity: normal
Keywords: |
-----------------------------+--------------------------
Unless I am missing something really obvious here, this ticket makes a lot
of sense to me.
---
There have been many instances where I have wanted to optionally pass my
own parameters to hook callback functions, that __haven't__ been specified
in the hooks {{{do_actions()}}} function call.
It would be hugely beneficial to also be able to pass in an array (say) as
an extra parameter when using {{{add_action()}}}. Something like:
{{{
$extra_args = array( 'value1', 'value2', 'value3' );
add_action( $hook, $callback, $priority, $accepted_args, $extra_args );
}}}
Then, in the callback function the {{{$extra_args}}} array would be
accessible as well as any {{{$accepted_args}}} parameters. Maybe make it
easy to access by always making it the last parameter?
{{{
function my_callback($wp1, $wp2, $args) {
//$args[0] = 'value1';
//$args[1] = 'value2';
//$args[2] = 'value3';
}
$extra_args = array( 'value1', 'value2', 'value3' );
add_action( 'some_hook', 'my_callback', 10, 2, $accepted_args, $extra_args
);
}}}
Note: I know I can achieve the same thing using global vars, but I don't
really want to define them unnecessarily when using a parameter would make
more sense.
--
Ticket URL: <http://core.trac.wordpress.org/ticket/22218>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list