Skip to:
Content

BuddyPress.org

Ticket #5810: 5810.02.patch

File 5810.02.patch, 1.8 KB (added by r-a-y, 12 years ago)

Updated patch for trunk.

  • src/bp-core/bp-core-catchuri.php

     
    342342function bp_core_load_template( $templates ) {
    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 );
     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;
    358369        }
    359370
     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 );
     377
    360378        // Fetch each template and add the php suffix
    361379        $filtered_templates = array();
    362380        foreach ( (array) $templates as $template ) {