Skip to:
Content

BuddyPress.org

Changeset 8821


Ignore:
Timestamp:
08/13/2014 03:20:55 AM (12 years ago)
Author:
r-a-y
Message:

In bp_core_load_template(), reset post globals if we're on a non-directory page.

If we're on a non-directory page, we are faking a WordPress page, so we
must reset the WordPress post globals to avoid notices from appearing. The
reset is done with the bp_theme_compat_reset_post() function and notably
fixes notices when the root profiles feature is toggled.

Commit also removes an unnecessary database query to determine whether
we're on a BuddyPress directory page. WordPress should have already made
this determination before BuddyPress has reached this point in
bp_core_load_template().

Fixes #5241.

File:
1 edited

Legend:

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

    r8820 r8821  
    341341 */
    342342function bp_core_load_template( $templates ) {
    343         global $post, $bp, $wp_query, $wpdb;
    344 
    345         // Determine if the root object WP page exists for this request
    346         // note: get_page_by_path() breaks non-root pages
    347         if ( !empty( $bp->unfiltered_uri_offset ) ) {
    348                 if ( !$page_exists = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM {$wpdb->posts} WHERE post_name = %s", $bp->unfiltered_uri[$bp->unfiltered_uri_offset] ) ) ) {
    349                         return false;
    350                 }
    351         }
    352 
    353         // Set the root object as the current wp_query-ied item
    354         $object_id = 0;
    355         foreach ( (array) $bp->pages as $page ) {
    356                 if ( $page->name == $bp->unfiltered_uri[$bp->unfiltered_uri_offset] ) {
    357                         $object_id = $page->id;
    358                 }
    359         }
    360 
    361         // Make the queried/post object an actual valid page
    362         if ( !empty( $object_id ) ) {
    363                 $wp_query->queried_object    = get_post( $object_id );
    364                 $wp_query->queried_object_id = $object_id;
    365                 $wp_query->post              = $wp_query->queried_object;
    366                 $post                        = $wp_query->queried_object;
     343        global $wp_query;
     344
     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 );
    367358        }
    368359
Note: See TracChangeset for help on using the changeset viewer.