[wp-trac] [WordPress Trac] #22218: Extra add_action() Parameter

WordPress Trac noreply at wordpress.org
Thu Oct 18 14:18:44 UTC 2012


#22218: Extra add_action() Parameter
-------------------------+------------------------------
 Reporter:  dgwyer       |       Owner:
     Type:  enhancement  |      Status:  new
 Priority:  normal       |   Milestone:  Awaiting Review
Component:  General      |     Version:  3.4.2
 Severity:  normal       |  Resolution:
 Keywords:  2nd-opinion  |
-------------------------+------------------------------
Changes (by scribu):

 * keywords:   => 2nd-opinion
 * type:  defect (bug) => enhancement


Comment:

 You could use a wrapper class:

 {{{
 class My_Functor {

   function __construct( $cb, $args ) {
     $this->cb = $cb;
     $this->args = $args;
   }

   function invoke() {
     $args = func_get_args();
     return call_user_func_array( $this->cb, array_merge( $args,
 $this->args ) );
   }
 }

 $extra_args = array( 'value1', 'value2', 'value3' );
 add_action( 'some_hook', array( new My_Functor( 'my_callback', $extra_args
 ), 'invoke' ) );
 }}}

 This way, we can keep add_action() blazing fast for the normal case.

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/22218#comment:1>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list