Skip to:
Content

BuddyPress.org

Ticket #4599: jjj.patch

File jjj.patch, 3.8 KB (added by johnjamesjacoby, 12 years ago)

I'm not paying attention to what I'm doing

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

     
    342342 * @return false|int The user ID of the matched user, or false.
    343343 */
    344344function bp_core_load_template( $templates ) {
    345         global $post, $bp, $wp_query, $wpdb;
     345        global $wpdb;
    346346
     347        // Get BuddyPress instance
     348        $bp = buddypress();
     349
    347350        // Determine if the root object WP page exists for this request
    348351        // note: get_page_by_path() breaks non-root pages
    349         if ( !empty( $bp->unfiltered_uri_offset ) ) {
    350                 if ( !$page_exists = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM {$wpdb->posts} WHERE post_name = %s", $bp->unfiltered_uri[$bp->unfiltered_uri_offset] ) ) ) {
     352        if ( !empty( $bp->unfiltered_uri_offset ) )
     353                if ( !$page_exists = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM {$wpdb->posts} WHERE post_name = %s", $bp->unfiltered_uri[$bp->unfiltered_uri_offset] ) ) )
    351354                        return false;
    352                 }
    353         }
    354355
    355         // Set the root object as the current wp_query-ied item
    356         $object_id = 0;
    357         foreach ( (array) $bp->pages as $page ) {
    358                 if ( $page->name == $bp->unfiltered_uri[$bp->unfiltered_uri_offset] ) {
    359                         $object_id = $page->id;
    360                 }
    361         }
    362 
    363         // Make the queried/post object an actual valid page
    364         if ( !empty( $object_id ) ) {
    365                 $wp_query->queried_object    = &get_post( $object_id );
    366                 $wp_query->queried_object_id = $object_id;
    367                 $post                        = $wp_query->queried_object;
    368         }
    369 
    370356        // Fetch each template and add the php suffix
    371357        $filtered_templates = array();
    372         foreach ( (array) $templates as $template ) {
     358        foreach ( (array) $templates as $template )
    373359                $filtered_templates[] = $template . '.php';
    374         }
    375360
    376361        // Filter the template locations so that plugins can alter where they are located
    377362        $located_template = apply_filters( 'bp_located_template', locate_template( (array) $filtered_templates, false ), $filtered_templates );
    378363        if ( !empty( $located_template ) ) {
    379364
    380                 // Template was located, lets set this as a valid page and not a 404.
    381                 status_header( 200 );
    382                 $wp_query->is_page     = true;
    383                 $wp_query->is_singular = true;
    384                 $wp_query->is_404      = false;                 
     365                _bp_core_force_queried_object();
    385366
    386367                do_action( 'bp_core_pre_load_template', $located_template );
    387368
     
    399380                // We know where we are, so reset important $wp_query bits here early.
    400381                // The rest will be done by bp_theme_compat_reset_post() later.
    401382                if ( is_buddypress() ) {
    402                         status_header( 200 );
    403                         $wp_query->is_page     = true;
    404                         $wp_query->is_singular = true;
    405                         $wp_query->is_404      = false;                 
     383                        _bp_core_force_queried_object();
    406384                }
    407385
    408386                do_action( 'bp_setup_theme_compat' );
     
    410388}
    411389
    412390/**
     391 * A private function to overload the queried object when BuddyPress is
     392 * overloading WordPress's template loader.
     393 *
     394 * Do not use this in your plugins or themes.
     395 *
     396 * @since BuddyPress (1.7)
     397 * @global WP_Post $post
     398 * @global WP_Query $wp_query
     399 */
     400function _bp_core_force_queried_object() {
     401        global $post, $wp_query;
     402
     403        // Get BuddyPress instance
     404        $bp = buddypress();
     405
     406        // Set the root object as the current wp_query-ied item
     407        $object_id = 0;
     408        foreach ( (array) $bp->pages as $page )
     409                if ( $page->name == $bp->unfiltered_uri[$bp->unfiltered_uri_offset] )
     410                        $object_id = $page->id;
     411
     412        // Make the queried/post object an actual valid page
     413        if ( !empty( $object_id ) ) {
     414                $wp_query->queried_object    = &get_post( $object_id );
     415                $wp_query->queried_object_id = $object_id;
     416                $post                        = $wp_query->queried_object;
     417        }
     418
     419        // Reset $wp_query globals
     420        $wp_query->is_page     = true;
     421        $wp_query->is_singular = true;
     422        $wp_query->is_home     = false;
     423        $wp_query->is_404      = false;
     424
     425        // We know we've found a template
     426        status_header( 200 );
     427}
     428
     429/**
    413430 * bp_core_catch_profile_uri()
    414431 *
    415432 * If the extended profiles component is not installed we still need