[wp-trac] [WordPress Trac] #24429: Provide a way to deprecate and/or rename hooks

WordPress Trac noreply at wordpress.org
Mon May 27 05:03:23 UTC 2013


#24429: Provide a way to deprecate and/or rename hooks
-------------------------+------------------------
 Reporter:  ryanve       |       Owner:
     Type:  enhancement  |      Status:  closed
 Priority:  normal       |   Milestone:
Component:  Plugins      |     Version:
 Severity:  normal       |  Resolution:  duplicate
 Keywords:               |
-------------------------+------------------------

Comment (by nacin):

 The idea here is still too heavy, though. If you want to prove me wrong,
 go profile it using Xdebug + KCachegrind.

 The idea is not wholly without merit, but it not only adds CPU cycles, but
 also complexity to an ultimately very simple API.

 Here's a way it could be made lighter:
 {{{
 function register_hook_alias( $alias, $actual_hook ) {
     global $hook_aliases;
     $hook_aliases[ $alias ] = $actual_hook;
 }

 function add_filter( $tag, ... ) {
    global $hook_aliases;
    if ( isset( $hook_aliases[ $tag ] ) )
       $tag = $hook_aliases[ $tag ];
 }
 }}}

 But, that is *still* heavy. Why call isset() another few thousand times
 per page, when this functionality likely won't be used?

 Something like register_hook_alias() could work, but this would need to
 happen on execution time. Something more like this:
 {{{
 function register_hook_alias( $alias, $actual_hook ) {
    global $hook_aliases;
    if ( isset( $hook_aliases[ $actual_hook ] ) )
       $hook_aliases[ $actual_hook ][] = $alias;
    else
       $hook_aliases[ $actual_hook ] = array( $alias );
 }

 function apply_filters( $tag, ... ) {
      global $hook_aliases;
      if ( isset( $hook_alises[ $tag ] ) ) {
        // Merge...
 }}}

 But this is still more code for fairly little gain. Core doesn't rename
 filters, and I need only three fingers to count up the number of core
 filters that are marked with a `// deprecated` comment.

 I still think this should go through #10441, given it is an established
 ticket.

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


More information about the wp-trac mailing list