[wp-trac] [WordPress Trac] #34334: Add a dynamic version of the admin_print_footer_scripts hook

WordPress Trac noreply at wordpress.org
Sat Oct 17 18:40:59 UTC 2015


#34334: Add a dynamic version of the admin_print_footer_scripts hook
-------------------------+------------------------------
 Reporter:  tfrommen     |       Owner:
     Type:  enhancement  |      Status:  new
 Priority:  normal       |   Milestone:  Awaiting Review
Component:  General      |     Version:
 Severity:  trivial      |  Resolution:
 Keywords:  has-patch    |     Focuses:
-------------------------+------------------------------

Comment (by tfrommen):

 Replying to [comment:2 swissspidy]:
 > Why not pass the `$hook_suffix` as a parameter then?

 For two reasons:

 '''1. It's easier to use.'''

 If I want to do something for a specific admin page only, I just can do
 this:

 {{{
 add_action( 'admin_print_footer_scripts-some_admin_page', function () {
     // Whatever it is that I want to do
 } );
 }}}

 With a generic hook that gets the `$hook_suffix` passed as parameter, I
 still need to check on my own:

 {{{
 add_action( 'admin_print_footer_scripts', function ( $hook_suffix ) {
     if ( 'some_admin_page' !== $hook_suffix ) {
         return;
     }

     // Whatever it is that I want to do
 } );
 }}}

 '''2. Less overhead.'''

 Let's say I have 42 distinct admin pages (yes, that number is fictional
 :)), and I want to do individual things for each of these pages. With a
 generic hook (having the `$hook_suffx` as parameter), '''on every
 single''' admin page (even the ones I'm not interested in) all of my 42
 functions are called. Every single one checks what the hook suffix is -
 and maybe one (and only one) will take action.

 Having a dynamic action, only the function that will actually do something
 will be called.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/34334#comment:3>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list