Skip to:
Content

BuddyPress.org

Changeset 8932


Ignore:
Timestamp:
08/17/2014 10:12:10 AM (5 years ago)
Author:
djpaul
Message:

Fixes a regression in r8821 in rbp_core_load_template() which was preventing the correct parent page being highlighted in WP nav menus.

This change reinstates the page look up and post globals as before r8821. Overall, these changes are still a net benefit as an uncached SQL query has been removed. See #5241 for background.

Fixes #5810

File:
1 edited

Legend:

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

    r8821 r8932  
    343343    global $wp_query;
    344344
    345     // reset post if not on a directory page
    346     // if we're not on a directory page, this means we're faking a page and we
    347     // need to reset the post to avoid notices
    348     if ( ! bp_is_directory() ) {
    349         bp_theme_compat_reset_post( array(
    350             'ID'          => 0,
    351             'is_404'      => true,
    352             'post_status' => 'publish',
    353         ) );
    354 
    355         // need to set theme compat to false since the reset post function
    356         // automatically sets theme compat to true
    357         bp_set_theme_compat_active( false );
    358     }
     345    // check if BP page belongs to, or is a child of, a BP directory page
     346    $page_id = false;
     347    foreach ( (array) buddypress()->pages as $page ) {
     348        if ( $page->name == buddypress()->unfiltered_uri[buddypress()->unfiltered_uri_offset] ) {
     349            $page_id = $page->id;
     350            break;
     351        }
     352    }
     353
     354    // Set up reset post args
     355    $reset_post_args = array(
     356        'is_404'      => true,
     357        'post_status' => 'publish',
     358    );
     359
     360    // BP page exists - fill in the $wp_query->post object
     361    //
     362    // bp_theme_compat_reset_post() looks at the $wp_query->post object to fill in
     363    // the post globals
     364    if ( ! empty( $page_id ) ) {
     365        $wp_query->post = get_post( $page_id );
     366        $reset_post_args['ID'] = $page_id;
     367    } else {
     368        $reset_post_args['ID'] = 0;
     369    }
     370
     371    // Reset the post
     372    bp_theme_compat_reset_post( $reset_post_args );
     373
     374    // Set theme compat to false since the reset post function automatically sets
     375    // theme compat to true
     376    bp_set_theme_compat_active( false );
    359377
    360378    // Fetch each template and add the php suffix
Note: See TracChangeset for help on using the changeset viewer.