Ticket #4599: jjj.patch
File jjj.patch, 3.8 KB (added by , 12 years ago) |
---|
-
bp-core/bp-core-catchuri.php
342 342 * @return false|int The user ID of the matched user, or false. 343 343 */ 344 344 function bp_core_load_template( $templates ) { 345 global $ post, $bp, $wp_query, $wpdb;345 global $wpdb; 346 346 347 // Get BuddyPress instance 348 $bp = buddypress(); 349 347 350 // Determine if the root object WP page exists for this request 348 351 // 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] ) ) ) 351 354 return false; 352 }353 }354 355 355 // Set the root object as the current wp_query-ied item356 $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 page364 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 370 356 // Fetch each template and add the php suffix 371 357 $filtered_templates = array(); 372 foreach ( (array) $templates as $template ) {358 foreach ( (array) $templates as $template ) 373 359 $filtered_templates[] = $template . '.php'; 374 }375 360 376 361 // Filter the template locations so that plugins can alter where they are located 377 362 $located_template = apply_filters( 'bp_located_template', locate_template( (array) $filtered_templates, false ), $filtered_templates ); 378 363 if ( !empty( $located_template ) ) { 379 364 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(); 385 366 386 367 do_action( 'bp_core_pre_load_template', $located_template ); 387 368 … … 399 380 // We know where we are, so reset important $wp_query bits here early. 400 381 // The rest will be done by bp_theme_compat_reset_post() later. 401 382 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(); 406 384 } 407 385 408 386 do_action( 'bp_setup_theme_compat' ); … … 410 388 } 411 389 412 390 /** 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 */ 400 function _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 /** 413 430 * bp_core_catch_profile_uri() 414 431 * 415 432 * If the extended profiles component is not installed we still need