Skip to:
Content

BuddyPress.org

Changeset 10279


Ignore:
Timestamp:
10/15/2015 02:27:16 AM (4 years ago)
Author:
boonebgorges
Message:

Support for WP_Hook in bp_get_template_stack().

The proposed WP_Hook #WP17817 breaks backward compatibility for plugins that
attempt to manipulate $wp_filter in certain ways. For BuddyPress, it means
that we cannot directly modify the callbacks that are currently registered as
an array at $wp_filter[ $tag ], in bp_get_template_stack(). Instead, when
WP_Hook is not available, we assign the callbacks to a variable (leveraging
WP_Hook's ArrayAccess) and manipulate the variable.

Props jbrinley.
Fixes #6649.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-core/bp-core-template-loader.php

    r10166 r10279  
    213213
    214214    // Sort
    215     if ( ! isset( $merged_filters[ $tag ] ) ) {
    216         ksort( $wp_filter[$tag] );
    217         $merged_filters[ $tag ] = true;
     215    if ( class_exists( 'WP_Hook' ) ) {
     216        $filter = $wp_filter[ $tag ]->callbacks;
     217    } else {
     218        $filter = &$wp_filter[ $tag ];
     219
     220        if ( ! isset( $merged_filters[ $tag ] ) ) {
     221            ksort( $filter );
     222            $merged_filters[ $tag ] = true;
     223        }
    218224    }
    219225
    220226    // Ensure we're always at the beginning of the filter array
    221     reset( $wp_filter[ $tag ] );
     227    reset( $filter );
    222228
    223229    // Loop through 'bp_template_stack' filters, and call callback functions
    224230    do {
    225         foreach( (array) current( $wp_filter[$tag] ) as $the_ ) {
     231        foreach( (array) current( $filter ) as $the_ ) {
    226232            if ( ! is_null( $the_['function'] ) ) {
    227233                $args[1] = $stack;
     
    229235            }
    230236        }
    231     } while ( next( $wp_filter[$tag] ) !== false );
     237    } while ( next( $filter ) !== false );
    232238
    233239    // Remove 'bp_template_stack' from the current filter array
Note: See TracChangeset for help on using the changeset viewer.