[wp-trac] [WordPress Trac] #24691: apply_filters() does not execute lower priority filters when recursively called

WordPress Trac noreply at wordpress.org
Thu Jul 4 22:48:25 UTC 2013


#24691: apply_filters() does not execute lower priority filters when recursively
called
--------------------------+-----------------------------
 Reporter:  Magenta Cuda  |      Owner:
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Shortcodes    |    Version:  3.5.2
 Severity:  normal        |   Keywords:  needs-patch
--------------------------+-----------------------------
 Consider:

 {{{
 add_filter( 'the_content', function( $content ) {
     return $content . ';filter 11 applied';
 }, 11 );

 add_filter( 'the_content', function( $content ) {
     if ( strpos( $content,'###' ) !== FALSE ) { return apply_filters(
 'the_content', '+++' ); }
     return $content . ';filter 10 applied';
 } );

 }}}

 returns "... +++;filter 10 applied;filter 11 applied" instead of "...
 +++;filter 10 applied;filter 11 applied;filter 11 applied" as expected
 when called with post_content containing "###".

 I think the problem is apply_filters() manipulates the internal array
 pointer using next() of the global $wp_filter[ $tag ] so the second call
 leaves the internal array pointer at the end. To test this I restored the
 internal array pointer as follows.

 {{{
     # save internal array pointer
     $key = key( $wp_filter['the_content'] );
     reset( $wp_filter[ $tag ] );
     ...
     do {
         foreach( (array) current($wp_filter[$tag]) as $the_ )
             ...
     } while ( next($wp_filter[$tag]) !== false );

     # restore internal array pointer
     for( end( $wp_filter['the_content'] ); key( $wp_filter['the_content']
 ) != $key; prev( $wp_filter['the_content'] ) ) { }

 }}}

 That does seem to work. The problem may be somewhat important as the
 do_shortcode() filter runs at priority 11 which is how I originally
 encountered the problem.

--
Ticket URL: <http://core.trac.wordpress.org/ticket/24691>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list