[wp-trac] [WordPress Trac] #17817: do_action/apply_filters/etc. recursion on same filter kills underlying call
WordPress Trac
noreply at wordpress.org
Sun Oct 4 20:12:38 UTC 2015
#17817: do_action/apply_filters/etc. recursion on same filter kills underlying call
-------------------------------------------------+-------------------------
Reporter: kernfel | Owner: nacin
Type: defect (bug) | Status: reviewing
Priority: normal | Milestone: 4.4
Component: Plugins | Version: 2.2
Severity: normal | Resolution:
Keywords: has-unit-tests has-patch needs- | Focuses:
testing |
-------------------------------------------------+-------------------------
Comment (by jbrinley):
Thanks for testing, @ocean90. Those errors are disheartening. There's
really no way to be 100% backwards compatible with something that touches
so deeply into the internals of `$wp_filter`. bbPress could be revised to
work with both the old and the new `$wp_filter` with code such as:
{{{
function bbp_get_template_stack() {
global $wp_filter, $merged_filters, $wp_current_filter;
// Setup some default variables
$tag = 'bbp_template_stack';
$args = $stack = array();
// Add 'bbp_template_stack' to the current filter array
$wp_current_filter[] = $tag;
if ( class_exists( 'WP_Hook' ) ) {
$filter = $wp_filter[ $tag ]->callbacks;
} else {
$filter = &$wp_filter[ $tag ];
// Sort
if ( ! isset( $merged_filters[ $tag ] ) ) {
ksort( $filter );
$merged_filters[ $tag ] = true;
}
}
// Ensure we're always at the beginning of the filter array
reset( $filter );
// Loop through 'bbp_template_stack' filters, and call callback
functions
do {
foreach ( (array) current( $filter ) as $the_ ) {
if ( ! is_null( $the_['function'] ) ) {
$args[1] = $stack;
$stack[] = call_user_func_array(
$the_['function'], array_slice( $args, 1, (int) $the_['accepted_args'] )
);
}
}
} while ( next( $filter ) !== false );
// Remove 'bbp_template_stack' from the current filter array
array_pop( $wp_current_filter );
// Remove empties and duplicates
$stack = array_unique( array_filter( $stack ) );
return (array) apply_filters( 'bbp_get_template_stack', $stack ) ;
}
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/17817#comment:158>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list