Ticket #5021: 5021.6.patch
File 5021.6.patch, 10.9 KB (added by , 11 years ago) |
---|
-
bp-core/bp-core-template-loader.php
211 211 add_filter( 'the_content', 'bp_replace_the_content' ); 212 212 213 213 // Get the output buffer contents 214 $output = ob_get_c ontents();214 $output = ob_get_clean(); 215 215 216 // Flush the output buffer217 ob_end_clean();218 219 216 // Echo or return the output buffer contents 220 217 if ( true === $echo ) { 221 218 echo $output; … … 341 338 // Look for root BuddyPress template files in parent/child themes 342 339 $new_template = apply_filters( 'bp_get_root_template', false, $template ); 343 340 344 // BuddyPress template file exists 341 // A BuddyPress template file was located, so override the WordPress 342 // template and use it to switch off BuddyPress's theme compatibility. 345 343 if ( !empty( $new_template ) ) { 346 347 // Override the WordPress template with a BuddyPress one 348 $template = $new_template; 349 350 // @see: bp_template_include_theme_compat() 351 buddypress()->theme_compat->found_template = true; 344 $template = bbp_set_template_included( $new_template ); 352 345 } 353 346 354 347 return apply_filters( 'bp_template_include_theme_supports', $template ); 355 348 } 356 349 357 350 /** 351 * Set the included template 352 * 353 * @since BuddyPress (1.8) 354 * @param mixed $template Default false 355 * @return mixed False if empty. Template name if template included 356 */ 357 function bp_set_template_included( $template = false ) { 358 buddypress()->theme_compat->found_template = $template; 359 360 return buddypress()->theme_compat->found_template; 361 } 362 363 /** 364 * Is a BuddyPress template being included? 365 * 366 * @since BuddyPress (1.8) 367 * @return bool True if yes, false if no 368 */ 369 function bp_is_template_included() { 370 return ! empty( buddypress()->theme_compat->found_template ); 371 } 372 373 /** 358 374 * Attempt to load a custom BuddyPress functions file, similar to each themes 359 375 * functions.php file. 360 376 * -
bp-core/bp-core-theme-compatibility.php
348 348 function bp_theme_compat_reset_post( $args = array() ) { 349 349 global $wp_query, $post; 350 350 351 // Default arguments352 $defaults = array(353 'ID' => -9999,354 'post_status' => 'publish',355 'post_author' => 0,356 'post_parent' => 0,357 'post_type' => 'page',358 'post_date' => 0,359 'post_date_gmt' => 0,360 'post_modified' => 0,361 'post_modified_gmt' => 0,362 'post_content' => '',363 'post_title' => '',364 'post_category' => 0,365 'post_excerpt' => '',366 'post_content_filtered' => '',367 'post_mime_type' => '',368 'post_password' => '',369 'post_name' => '',370 'guid' => '',371 'menu_order' => 0,372 'pinged' => '',373 'to_ping' => '',374 'ping_status' => '',375 'comment_status' => 'closed',376 'comment_count' => 0,377 378 'is_404' => false,379 'is_page' => false,380 'is_single' => false,381 'is_archive' => false,382 'is_tax' => false,383 );384 385 351 // Switch defaults if post is set 386 352 if ( isset( $wp_query->post ) ) { 387 $d efaults =array(353 $dummy = bbp_parse_args( $args, array( 388 354 'ID' => $wp_query->post->ID, 389 355 'post_status' => $wp_query->post->post_status, 390 356 'post_author' => $wp_query->post->post_author, … … 408 374 'ping_status' => $wp_query->post->ping_status, 409 375 'comment_status' => $wp_query->post->comment_status, 410 376 'comment_count' => $wp_query->post->comment_count, 377 'filter' => $wp_query->post->filter, 411 378 412 'is_404' => false, 413 'is_page' => false, 414 'is_single' => false, 415 'is_archive' => false, 416 'is_tax' => false, 417 ); 379 'is_404' => false, 380 'is_page' => false, 381 'is_single' => false, 382 'is_archive' => false, 383 'is_tax' => false, 384 ) ); 385 } else { 386 $dummy = wp_parse_args( $args, array( 387 'ID' => -9999, 388 'post_status' => bbp_get_public_status_id(), 389 'post_author' => 0, 390 'post_parent' => 0, 391 'post_type' => 'page', 392 'post_date' => 0, 393 'post_date_gmt' => 0, 394 'post_modified' => 0, 395 'post_modified_gmt' => 0, 396 'post_content' => '', 397 'post_title' => '', 398 'post_excerpt' => '', 399 'post_content_filtered' => '', 400 'post_mime_type' => '', 401 'post_password' => '', 402 'post_name' => '', 403 'guid' => '', 404 'menu_order' => 0, 405 'pinged' => '', 406 'to_ping' => '', 407 'ping_status' => '', 408 'comment_status' => 'closed', 409 'comment_count' => 0, 410 'filter' => 'raw', 411 412 'is_404' => false, 413 'is_page' => false, 414 'is_single' => false, 415 'is_archive' => false, 416 'is_tax' => false, 417 ) ); 418 418 } 419 $dummy = wp_parse_args( $args, $defaults ); //, 'theme_compat_reset_post' );420 419 421 // Clear out the post related globals422 unset( $wp_query->posts );423 unset( $wp_query->post );424 unset( $post );420 // Bail if dummy post is empty 421 if ( empty( $dummy ) ) { 422 return; 423 } 425 424 426 // Setup the dummy post object427 $wp_query->post = new stdClass;428 $wp_query->post->ID = $dummy['ID'];429 $wp_query->post->post_status = $dummy['post_status'];430 $wp_query->post->post_author = $dummy['post_author'];431 $wp_query->post->post_parent = $dummy['post_parent'];432 $wp_query->post->post_type = $dummy['post_type'];433 $wp_query->post->post_date = $dummy['post_date'];434 $wp_query->post->post_date_gmt = $dummy['post_date_gmt'];435 $wp_query->post->post_modified = $dummy['post_modified'];436 $wp_query->post->post_modified_gmt = $dummy['post_modified_gmt'];437 $wp_query->post->post_content = $dummy['post_content'];438 $wp_query->post->post_title = $dummy['post_title'];439 $wp_query->post->post_excerpt = $dummy['post_excerpt'];440 $wp_query->post->post_content_filtered = $dummy['post_content_filtered'];441 $wp_query->post->post_mime_type = $dummy['post_mime_type'];442 $wp_query->post->post_password = $dummy['post_password'];443 $wp_query->post->post_name = $dummy['post_name'];444 $wp_query->post->guid = $dummy['guid'];445 $wp_query->post->menu_order = $dummy['menu_order'];446 $wp_query->post->pinged = $dummy['pinged'];447 $wp_query->post->to_ping = $dummy['to_ping'];448 $wp_query->post->ping_status = $dummy['ping_status'];449 $wp_query->post->comment_status = $dummy['comment_status'];450 $wp_query->post->comment_count = $dummy['comment_count'];451 452 425 // Set the $post global 453 $post = $wp_query->post;426 $post = new WP_Post( (object) $dummy ); 454 427 455 // Setup the dummy post loop 456 $wp_query->posts[0] = $wp_query->post; 428 // Copy the new post global into the main $wp_query 429 $wp_query->post = $post; 430 $wp_query->posts = array( $post ); 457 431 458 432 // Prevent comments form from appearing 459 433 $wp_query->post_count = 1; … … 463 437 $wp_query->is_archive = $dummy['is_archive']; 464 438 $wp_query->is_tax = $dummy['is_tax']; 465 439 440 // Clean up the dummy post 441 unset( $dummy ); 442 443 /** 444 * Force the header back to 200 status if not a deliberate 404 445 * 446 * @see http://bbpress.trac.wordpress.org/ticket/1973 447 */ 448 if ( ! $wp_query->is_404() ) { 449 status_header( 200 ); 450 } 451 466 452 // If we are resetting a post, we are in theme compat 467 bp_set_theme_compat_active( );453 bp_set_theme_compat_active( true ); 468 454 } 469 455 470 456 /** … … 523 509 * possible templates, or 'bp_buddypress_template' to override the result. 524 510 */ 525 511 if ( bp_is_theme_compat_active() ) { 512 $template = bp_get_theme_compat_templates(); 526 513 527 // Hook to the beginning of the main post loop to remove all filters 528 // from the_content as late as possible. 529 add_action( 'loop_start', 'bp_theme_compat_main_loop_start', 9999 ); 514 add_filter( 'the_content', 'bp_replace_the_content' ); 530 515 531 // Hook to the end of the main post loop to restore all filters to532 // the_content as early as possible.533 add_action( 'loop_end', 'bp_theme_compat_main_loop_end', -9999 );534 535 516 // Add BuddyPress's head action to wp_head 536 517 if ( ! has_action( 'wp_head', 'bp_head' ) ) { 537 518 add_action( 'wp_head', 'bp_head' ); 538 519 } 539 540 // Find the appropriate template file541 $template = bp_get_theme_compat_templates();542 520 } 543 521 544 522 return apply_filters( 'bp_template_include_theme_compat', $template ); … … 555 533 */ 556 534 function bp_replace_the_content( $content = '' ) { 557 535 558 if ( ! in_the_loop() ) 536 // Bail if not the main loop where theme compat is happening 537 if ( ! bp_do_theme_compat() ) 559 538 return $content; 560 539 540 // Set theme compat to false early, to avoid recursion from nested calls to 541 // the_content() that execute before theme compat has unhooked itself. 542 bp_set_theme_compat_active( false ); 543 544 // Do we have new content to replace the old content? 561 545 $new_content = apply_filters( 'bp_replace_the_content', $content ); 562 546 563 547 // Juggle the content around and try to prevent unsightly comments 564 if ( !empty( $new_content ) && ( $new_content != $content ) ) {548 if ( !empty( $new_content ) && ( $new_content !== $content ) ) { 565 549 566 550 // Set the content to be the new content 567 551 $content = $new_content; … … 578 562 } 579 563 580 564 /** 581 * Helper function to conditionally toggle the_content filters in the main 582 * query loop. Aids with theme compatibility. 565 * Are we replacing the_content 583 566 * 584 567 * @since BuddyPress (1.8) 585 * @internal Used only by theme compatibilty 586 * @see bp_template_include_theme_compat() 587 * @see bp_theme_compat_main_loop_end() 568 * @return bool 588 569 */ 589 function bp_theme_compat_main_loop_start() { 590 591 // Bail if not the main query 592 if ( ! in_the_loop() ) 593 return; 594 595 // Remove all of the filters from the_content 596 bp_remove_all_filters( 'the_content' ); 597 598 // Make sure we replace the content 599 add_filter( 'the_content', 'bp_replace_the_content' ); 570 function bp_do_theme_compat() { 571 return (bool) ( ! bp_is_template_included() && in_the_loop() && bp_is_theme_compat_active() ); 600 572 } 601 573 602 /**603 * Helper function to conditionally toggle the_content filters in the main604 * query loop. Aids with theme compatibility.605 *606 * @since BuddyPress (1.8)607 * @internal Used only by theme compatibilty608 * @see bp_template_include_theme_compat()609 * @see bp_theme_compat_main_loop_start()610 */611 function bp_theme_compat_main_loop_end() {612 613 // Bail if not the main query614 if ( ! in_the_loop() )615 return;616 617 // Put all the filters back618 bp_restore_all_filters( 'the_content' );619 }620 621 574 /** Filters *******************************************************************/ 622 575 623 576 /**