Changeset 5043
- Timestamp:
- 07/18/2013 10:27:16 AM (13 years ago)
- Location:
- trunk/includes
- Files:
-
- 3 edited
-
common/shortcodes.php (modified) (2 diffs)
-
core/template-functions.php (modified) (1 diff)
-
core/theme-compat.php (modified) (18 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/includes/common/shortcodes.php
r5020 r5043 156 156 bbp_set_query_name( $query_name ); 157 157 158 // Remove 'bbp_replace_the_content' filter to prevent infinite loops159 remove_filter( 'the_content', 'bbp_replace_the_content' );160 161 158 // Start output buffer 162 159 ob_start(); … … 173 170 private function end() { 174 171 175 // Put output into usable variable 176 $output = ob_get_contents(); 177 178 // Unset globals 179 $this->unset_globals(); 180 181 // Flush the output buffer 182 ob_end_clean(); 172 // Unset globals 173 $this->unset_globals(); 183 174 184 175 // Reset the query name 185 176 bbp_reset_query_name(); 186 177 187 // Add 'bbp_replace_the_content' filter back (@see $this::start()) 188 add_filter( 'the_content', 'bbp_replace_the_content' ); 189 190 return $output; 178 // Return and flush the output buffer 179 return ob_get_clean(); 191 180 } 192 181 -
trunk/includes/core/template-functions.php
r5002 r5043 201 201 202 202 return (array) apply_filters( 'bbp_get_template_stack', $stack ) ; 203 } 204 205 /** 206 * Get a template part in an output buffer, and return it 207 * 208 * @since bbPress (r5043) 209 * 210 * @param string $slug 211 * @param string $name 212 * @return string 213 */ 214 function bbp_buffer_template_part( $slug, $name = null, $echo = true ) { 215 ob_start(); 216 217 bbp_get_template_part( $slug, $name ); 218 219 // Get the output buffer contents 220 $output = ob_get_clean(); 221 222 // Echo or return the output buffer contents 223 if ( true === $echo ) { 224 echo $output; 225 } else { 226 return $output; 227 } 203 228 } 204 229 -
trunk/includes/core/theme-compat.php
r5042 r5043 444 444 return $template; 445 445 446 // Define local variable(s) 447 $bbp_shortcodes = bbpress()->shortcodes; 448 449 // Bail if shortcodes are unset somehow 450 if ( !is_a( $bbp_shortcodes, 'BBP_Shortcodes' ) ) 451 return $template; 452 446 453 /** Users *************************************************************/ 447 454 … … 453 460 'post_author' => 0, 454 461 'post_date' => 0, 455 'post_content' => '',462 'post_content' => bbp_buffer_template_part( 'content', 'single-user', false ), 456 463 'post_type' => '', 457 464 'post_title' => bbp_get_displayed_user_field( 'display_name' ), … … 466 473 } elseif ( bbp_is_forum_archive() ) { 467 474 475 // Page exists where this archive should be 476 $page = bbp_get_page_by_path( bbp_get_root_slug() ); 477 if ( !empty( $page ) ) { 478 $new_content = apply_filters( 'the_content', $page->post_content ); 479 $new_title = apply_filters( 'the_title', $page->post_title ); 480 481 // Use the topics archive 482 } elseif ( 'topics' === bbp_show_on_root() ) { 483 $new_content = $bbp_shortcodes->display_topic_index(); 484 $new_title = bbp_get_topic_archive_title(); 485 486 // No page so show the archive 487 } else { 488 $new_content = $bbp_shortcodes->display_forum_index(); 489 $new_title = bbp_get_forum_archive_title(); 490 } 491 468 492 // Reset post 469 493 bbp_theme_compat_reset_post( array( 470 494 'ID' => 0, 471 'post_title' => bbp_get_forum_archive_title(),495 'post_title' => $new_title, 472 496 'post_author' => 0, 473 497 'post_date' => 0, 474 'post_content' => '',498 'post_content' => $new_content, 475 499 'post_type' => bbp_get_forum_post_type(), 476 500 'post_status' => bbp_get_public_status_id(), … … 480 504 481 505 // Single Forum 482 } elseif ( bbp_is_forum_edit() || bbp_is_single_forum()) {506 } elseif ( bbp_is_forum_edit() ) { 483 507 484 508 // Reset post … … 488 512 'post_author' => bbp_get_forum_author_id(), 489 513 'post_date' => 0, 490 'post_content' => get_post_field( 'post_content', bbp_get_forum_id()),514 'post_content' => $bbp_shortcodes->display_forum_form(), 491 515 'post_type' => bbp_get_forum_post_type(), 492 516 'post_status' => bbp_get_forum_visibility(), … … 495 519 ) ); 496 520 521 } elseif ( bbp_is_single_forum() ) { 522 523 // Reset post 524 bbp_theme_compat_reset_post( array( 525 'ID' => bbp_get_forum_id(), 526 'post_title' => bbp_get_forum_title(), 527 'post_author' => bbp_get_forum_author_id(), 528 'post_date' => 0, 529 'post_content' => $bbp_shortcodes->display_forum( array( 'id' => bbp_get_forum_id() ) ), 530 'post_type' => bbp_get_forum_post_type(), 531 'post_status' => bbp_get_forum_visibility(), 532 'is_single' => true, 533 'comment_status' => 'closed' 534 ) ); 535 497 536 /** Topics ************************************************************/ 498 537 499 538 // Topic archive 500 539 } elseif ( bbp_is_topic_archive() ) { 540 541 // Page exists where this archive should be 542 $page = bbp_get_page_by_path( bbp_get_topic_archive_slug() ); 543 if ( !empty( $page ) ) { 544 $new_content = apply_filters( 'the_content', $page->post_content ); 545 546 // No page so show the archive 547 } else { 548 $new_content = $bbp_shortcodes->display_topic_index(); 549 } 501 550 502 551 // Reset post … … 506 555 'post_author' => 0, 507 556 'post_date' => 0, 508 'post_content' => '',557 'post_content' => $new_content, 509 558 'post_type' => bbp_get_topic_post_type(), 510 559 'post_status' => bbp_get_public_status_id(), … … 516 565 } elseif ( bbp_is_topic_edit() || bbp_is_single_topic() ) { 517 566 567 // Split 568 if ( bbp_is_topic_split() ) { 569 $new_content = bbp_buffer_template_part( 'form', 'topic-split', false ); 570 571 // Merge 572 } elseif ( bbp_is_topic_merge() ) { 573 $new_content = bbp_buffer_template_part( 'form', 'topic-merge', false ); 574 575 // Edit 576 } elseif ( bbp_is_topic_edit() ) { 577 $new_content = $bbp_shortcodes->display_topic_form(); 578 579 // Single 580 } else { 581 $new_content = $bbp_shortcodes->display_topic( array( 'id' => bbp_get_topic_id() ) ); 582 } 583 518 584 // Reset post 519 585 bbp_theme_compat_reset_post( array( … … 522 588 'post_author' => bbp_get_topic_author_id(), 523 589 'post_date' => 0, 524 'post_content' => get_post_field( 'post_content', bbp_get_topic_id() ),590 'post_content' => $new_content, 525 591 'post_type' => bbp_get_topic_post_type(), 526 592 'post_status' => bbp_get_topic_status(), … … 540 606 'post_author' => 0, 541 607 'post_date' => 0, 542 'post_content' => '',608 'post_content' => $bbp_shortcodes->display_reply_index(), 543 609 'post_type' => bbp_get_reply_post_type(), 544 610 'post_status' => bbp_get_public_status_id(), … … 548 614 // Single Reply 549 615 } elseif ( bbp_is_reply_edit() || bbp_is_single_reply() ) { 616 617 // Move 618 if ( bbp_is_reply_move() ) { 619 $new_content = bbp_buffer_template_part( 'form', 'reply-move', false ); 620 621 // Edit 622 } elseif ( bbp_is_reply_edit() ) { 623 $new_content = $bbp_shortcodes->display_reply_form(); 624 625 // Single 626 } else { 627 $new_content = $bbp_shortcodes->display_reply( array( 'id' => get_the_ID() ) ); 628 } 550 629 551 630 // Reset post … … 555 634 'post_author' => bbp_get_reply_author_id(), 556 635 'post_date' => 0, 557 'post_content' => get_post_field( 'post_content', bbp_get_reply_id() ),636 'post_content' => $new_content, 558 637 'post_type' => bbp_get_reply_post_type(), 559 638 'post_status' => bbp_get_reply_status(), … … 571 650 'post_author' => 0, 572 651 'post_date' => 0, 573 'post_content' => '',652 'post_content' => $bbp_shortcodes->display_view( array( 'id' => get_query_var( 'bbp_view' ) ) ), 574 653 'post_type' => '', 575 654 'post_status' => bbp_get_public_status_id(), … … 587 666 'post_author' => 0, 588 667 'post_date' => 0, 589 'post_content' => '',668 'post_content' => $bbp_shortcodes->display_search( array( 'search' => get_query_var( 'bbp_search' ) ) ), 590 669 'post_type' => '', 591 670 'post_status' => bbp_get_public_status_id(), … … 601 680 set_query_var( 'bbp_topic_tag', get_query_var( 'term' ) ); 602 681 682 // Show topics of tag 683 if ( bbp_is_topic_tag() ) { 684 $new_content = $bbp_shortcodes->display_topics_of_tag( array( 'id' => bbp_get_topic_tag_id() ) ); 685 686 // Edit topic tag 687 } elseif ( bbp_is_topic_tag_edit() ) { 688 $new_content = $bbp_shortcodes->display_topic_tag_form(); 689 } 690 603 691 // Reset the post with our new title 604 692 bbp_theme_compat_reset_post( array( … … 606 694 'post_author' => 0, 607 695 'post_date' => 0, 608 'post_content' => '',696 'post_content' => $new_content, 609 697 'post_type' => '', 610 698 'post_title' => sprintf( __( 'Topic Tag: %s', 'bbpress' ), '<span>' . bbp_get_topic_tag_name() . '</span>' ), … … 646 734 */ 647 735 } elseif ( bbp_is_theme_compat_active() ) { 736 bbp_remove_all_filters( 'the_content' ); 737 648 738 $template = bbp_get_theme_compat_templates(); 649 650 // Hook onto the start and end of the loop, and prepare to replace the651 // main section of the_content() output.652 add_action( 'loop_start', 'bbp_theme_compat_main_loop_start', 9999 );653 add_action( 'loop_end', 'bbp_theme_compat_main_loop_end', -9999 );654 739 } 655 740 … … 657 742 } 658 743 659 /**660 * Replaces the_content() if the post_type being displayed is one that would661 * normally be handled by bbPress, but proper single page templates do not662 * exist in the currently active theme.663 *664 * Note that we do *not* currently use is_main_query() here. This is because so665 * many existing themes either use query_posts() or fail to use wp_reset_query()666 * when running queries before the main loop, causing theme compat to fail. We667 * do use in_the_loop() though, so we can narrow the scope down to the actual668 * main page content area.669 *670 * @since bbPress (r3034)671 * @param string $content672 * @return type673 */674 function bbp_replace_the_content( $content = '' ) {675 676 // Bail if not the main loop where theme compat is happening677 if ( ! bbp_do_theme_compat() )678 return $content;679 680 // Define local variable(s)681 $new_content = '';682 $bbp_shortcodes = bbpress()->shortcodes;683 684 // Bail if shortcodes are unset somehow685 if ( !is_a( $bbp_shortcodes, 'BBP_Shortcodes' ) )686 return $content;687 688 // Set theme compat to false early, to avoid recursion from nested calls to689 // the_content() that execute before theme compat has unhooked itself.690 bbp_set_theme_compat_active( false );691 692 // Use shortcode API to display forums/topics/replies because they are693 // already output buffered and ready to fit inside the_content694 695 /** Users *************************************************************/696 697 // Profile View698 if ( bbp_is_single_user_edit() || bbp_is_single_user() ) {699 ob_start();700 701 bbp_get_template_part( 'content', 'single-user' );702 703 $new_content = ob_get_clean();704 705 /** Forums ************************************************************/706 707 // Forum archive708 } elseif ( bbp_is_forum_archive() ) {709 710 // Page exists where this archive should be711 $page = bbp_get_page_by_path( bbp_get_root_slug() );712 if ( !empty( $page ) ) {713 714 // Restore previously unset filters715 bbp_restore_all_filters( 'the_content' );716 717 // Remove 'bbp_replace_the_content' filter to prevent infinite loops718 remove_filter( 'the_content', 'bbp_replace_the_content' );719 720 // Start output buffer721 ob_start();722 723 // Grab the content of this page724 $new_content = apply_filters( 'the_content', $page->post_content );725 726 // Clean up the buffer727 ob_end_clean();728 729 // Add 'bbp_replace_the_content' filter back (@see $this::start())730 add_filter( 'the_content', 'bbp_replace_the_content' );731 732 // Use the topics archive733 } elseif ( 'topics' === bbp_show_on_root() ) {734 $new_content = $bbp_shortcodes->display_topic_index();735 736 // No page so show the archive737 } else {738 $new_content = $bbp_shortcodes->display_forum_index();739 }740 741 // Forum Edit742 } elseif ( bbp_is_forum_edit() ) {743 $new_content = $bbp_shortcodes->display_forum_form();744 745 // Single Forum746 } elseif ( bbp_is_single_forum() ) {747 $new_content = $bbp_shortcodes->display_forum( array( 'id' => get_the_ID() ) );748 749 /** Topics ************************************************************/750 751 // Topic archive752 } elseif ( bbp_is_topic_archive() ) {753 754 // Page exists where this archive should be755 $page = bbp_get_page_by_path( bbp_get_topic_archive_slug() );756 if ( !empty( $page ) ) {757 758 // Restore previously unset filters759 bbp_restore_all_filters( 'the_content' );760 761 // Remove 'bbp_replace_the_content' filter to prevent infinite loops762 remove_filter( 'the_content', 'bbp_replace_the_content' );763 764 // Start output buffer765 ob_start();766 767 // Grab the content of this page768 $new_content = apply_filters( 'the_content', $page->post_content );769 770 // Clean up the buffer771 ob_end_clean();772 773 // Add 'bbp_replace_the_content' filter back (@see $this::start())774 add_filter( 'the_content', 'bbp_replace_the_content' );775 776 // No page so show the archive777 } else {778 $new_content = $bbp_shortcodes->display_topic_index();779 }780 781 // Topic Edit782 } elseif ( bbp_is_topic_edit() ) {783 784 // Split785 if ( bbp_is_topic_split() ) {786 ob_start();787 788 bbp_get_template_part( 'form', 'topic-split' );789 790 $new_content = ob_get_clean();791 792 // Merge793 } elseif ( bbp_is_topic_merge() ) {794 ob_start();795 796 bbp_get_template_part( 'form', 'topic-merge' );797 798 $new_content = ob_get_clean();799 800 // Edit801 } else {802 $new_content = $bbp_shortcodes->display_topic_form();803 }804 805 // Single Topic806 } elseif ( bbp_is_single_topic() ) {807 $new_content = $bbp_shortcodes->display_topic( array( 'id' => get_the_ID() ) );808 809 /** Replies ***********************************************************/810 811 // Reply archive812 } elseif ( is_post_type_archive( bbp_get_reply_post_type() ) ) {813 //$new_content = $bbp_shortcodes->display_reply_index();814 815 // Reply Edit816 } elseif ( bbp_is_reply_edit() ) {817 818 // Move819 if ( bbp_is_reply_move() ) {820 ob_start();821 822 bbp_get_template_part( 'form', 'reply-move' );823 824 $new_content = ob_get_clean();825 826 // Edit827 } else {828 $new_content = $bbp_shortcodes->display_reply_form();829 }830 831 // Single Reply832 } elseif ( bbp_is_single_reply() ) {833 $new_content = $bbp_shortcodes->display_reply( array( 'id' => get_the_ID() ) );834 835 /** Views *************************************************************/836 837 } elseif ( bbp_is_single_view() ) {838 $new_content = $bbp_shortcodes->display_view( array( 'id' => get_query_var( 'bbp_view' ) ) );839 840 /** Search ************************************************************/841 842 } elseif ( bbp_is_search() ) {843 $new_content = $bbp_shortcodes->display_search( array( 'search' => get_query_var( 'bbp_search' ) ) );844 845 /** Topic Tags ********************************************************/846 847 // Show topics of tag848 } elseif ( bbp_is_topic_tag() ) {849 $new_content = $bbp_shortcodes->display_topics_of_tag( array( 'id' => bbp_get_topic_tag_id() ) );850 851 // Edit topic tag852 } elseif ( bbp_is_topic_tag_edit() ) {853 $new_content = $bbp_shortcodes->display_topic_tag_form();854 }855 856 // Juggle the content around and try to prevent unsightly comments857 if ( !empty( $new_content ) && ( $new_content !== $content ) ) {858 859 // Set the content to be the new content860 $content = apply_filters( 'bbp_replace_the_content', $new_content, $content );861 862 // Clean up after ourselves863 unset( $new_content );864 865 // Reset the $post global866 wp_reset_postdata();867 }868 869 // Return possibly hi-jacked content870 return $content;871 }872 873 874 /**875 * Helper function to conditionally toggle the_content filters in the main876 * query loop. Aids with theme compatibility.877 *878 * @since bbPress (r4972)879 * @internal Used only by theme compatibilty880 * @see bp_template_include_theme_compat()881 * @see bp_theme_compat_main_loop_end()882 */883 function bbp_theme_compat_main_loop_start() {884 885 // Bail if not the main loop where theme compat is happening886 if ( ! bbp_do_theme_compat() )887 return;888 889 // Remove all of the filters from the_content890 bbp_remove_all_filters( 'the_content' );891 892 // Make sure we replace the content893 add_filter( 'the_content', 'bbp_replace_the_content' );894 }895 896 /**897 * Helper function to conditionally toggle the_content filters in the main898 * query loop. Aids with theme compatibility.899 *900 * @since bbPress (r4972)901 * @internal Used only by theme compatibilty902 * @see bbp_template_include_theme_compat()903 * @see bbp_theme_compat_main_loop_start()904 */905 function bbp_theme_compat_main_loop_end() {906 907 // Bail if not the main loop where theme compat is happening908 if ( ! bbp_do_theme_compat() )909 return;910 911 // Put all the filters back912 bbp_restore_all_filters( 'the_content' );913 }914 915 744 /** Helpers *******************************************************************/ 916 917 /**918 * Are we replacing the_content919 *920 * @since bbPres (r4975)921 * @return bool922 */923 function bbp_do_theme_compat() {924 return (bool) ( ! bbp_is_template_included() && in_the_loop() && bbp_is_theme_compat_active() );925 }926 745 927 746 /**
Note: See TracChangeset
for help on using the changeset viewer.