[wp-trac] [WordPress Trac] #50245: extend functionality to stop further actions on hook on a priority range

WordPress Trac noreply at wordpress.org
Mon May 25 13:40:44 UTC 2020


#50245: extend functionality to stop further actions on hook on a priority range
--------------------------+--------------------------------------------
 Reporter:  Alignak       |       Owner:  (none)
     Type:  enhancement   |      Status:  assigned
 Priority:  normal        |   Milestone:  Awaiting Review
Component:  Cache API     |     Version:
 Severity:  normal        |  Resolution:
 Keywords:  dev-feedback  |     Focuses:  performance, coding-standards
--------------------------+--------------------------------------------

Comment (by apedog):

 This is a support question.
 The functionality you want already exists.
 You can do that with code like this.
 Hook your function really early ({{{PHP_INT_MIN}}}/{{{PHP_INT_MAX}}} is a
 bit excessive and might not even be consistent across different systems.
 You should avoid using that.)
 And have a look at {{{wp-includes/wp-class-hook.php}}} for more methods
 that might be useful.
 {{{#!php
 <?php
 add_action( 'your_hook', 'custom_filter_remover', -10 );
 function custom_filter_remover(){
         global $wp_filter;
         $hook_name = 'your_hook';
         $actual_hook = $wp_filter[$hook_name];

         foreach ( $actual_hook->callbacks as $priority => $callbacks ){
                 foreach ($callbacks as $the_){

                         if ( $the_['function'] ==
 'function_i_dont_want_to_remove' )
                                 continue;
                         if ($priority >= 10 || $priority <= -10 )
                                 continue;

                         remove_filter( $hook_name, $the_['function'],
 $priority );
                 }
         }
 }
 }}}

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


More information about the wp-trac mailing list