Skip to:
Content

bbPress.org

Changeset 5944


Ignore:
Timestamp:
10/27/2015 09:49:24 AM (4 years ago)
Author:
netweb
Message:

Core: Support for WP_Hook in bbp_get_template_stack()

The proposed WP_Hook #WP17817 breaks backward compatibility for plugins that
attempt to manipulate $wp_filter in certain ways. For bbPress, it means
that we cannot directly modify the callbacks that are currently registered as
an array at $wp_filter[ $tag ], in bbp_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 #2871

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/includes/core/template-functions.php

    r5908 r5944  
    315315    $wp_current_filter[] = $tag;
    316316
    317     // Bail if no stack setup
    318     if ( empty( $wp_filter[ $tag ] ) ) {
    319         return array();
    320     }
    321 
    322     // Sort
    323     if ( ! isset( $merged_filters[ $tag ] ) ) {
    324         ksort( $wp_filter[ $tag ] );
    325         $merged_filters[ $tag ] = true;
     317    if ( class_exists( 'WP_Hook' ) ) {
     318        $filter = $wp_filter[ $tag ]->callbacks;
     319    } else {
     320        $filter = &$wp_filter[ $tag ];
     321
     322        // Sort
     323        if ( ! isset( $merged_filters[ $tag ] ) ) {
     324            ksort( $filter );
     325            $merged_filters[ $tag ] = true;
     326        }
    326327    }
    327328
    328329    // Ensure we're always at the beginning of the filter array
    329     reset( $wp_filter[ $tag ] );
     330    reset( $filter );
    330331
    331332    // Loop through 'bbp_template_stack' filters, and call callback functions
    332333    do {
    333         foreach ( (array) current( $wp_filter[ $tag ] ) as $the_ ) {
     334        foreach ( (array) current( $filter ) as $the_ ) {
    334335            if ( ! is_null( $the_['function'] ) ) {
    335336                $args[1] = $stack;
     
    337338            }
    338339        }
    339     } while ( next( $wp_filter[ $tag ] ) !== false );
     340    } while ( next( $filter ) !== false );
    340341
    341342    // Remove 'bbp_template_stack' from the current filter array
Note: See TracChangeset for help on using the changeset viewer.