Changeset 4975
- Timestamp:
- 05/30/2013 06:26:19 AM (12 years ago)
- Location:
- trunk/includes/core
- Files:
-
- 2 edited
-
template-loader.php (modified) (1 diff)
-
theme-compat.php (modified) (19 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/includes/core/template-loader.php
r4579 r4975 109 109 endif; 110 110 111 // bbPress template file exists 111 // A bbPress template file was located, so override the WordPress template 112 // and use it to switch off bbPress's theme compatibility. 112 113 if ( !empty( $new_template ) ) { 113 114 // Override the WordPress template with a bbPress one 115 $template = $new_template; 116 117 // @see: bbp_template_include_theme_compat() 118 bbpress()->theme_compat->bbpress_template = true; 114 $template = bbp_set_template_included( $new_template ); 119 115 } 120 116 121 117 return apply_filters( 'bbp_template_include_theme_supports', $template ); 118 } 119 120 /** 121 * Set the included template 122 * 123 * @since bbPress (r4975) 124 * @param mixed $template Default false 125 * @return mixed False if empty. Template name if template included 126 */ 127 function bbp_set_template_included( $template = false ) { 128 bbpress()->theme_compat->bbpress_template = $template; 129 130 return bbpress()->theme_compat->bbpress_template; 131 } 132 133 /** 134 * Is a bbPress template being included? 135 * 136 * @since bbPress (r4975) 137 * @return bool True if yes, false if no 138 */ 139 function bbp_is_template_included() { 140 return ! empty( bbpress()->theme_compat->bbpress_template ); 122 141 } 123 142 -
trunk/includes/core/theme-compat.php
r4972 r4975 46 46 * 'url' => URL to theme 47 47 * ); 48 * @var array 48 * @var array 49 49 */ 50 50 private $_data = array(); … … 298 298 global $wp_query, $post; 299 299 300 // Default arguments301 $defaults = array(302 'ID' => -9999,303 'post_status' => bbp_get_public_status_id(),304 'post_author' => 0,305 'post_parent' => 0,306 'post_type' => 'page',307 'post_date' => 0,308 'post_date_gmt' => 0,309 'post_modified' => 0,310 'post_modified_gmt' => 0,311 'post_content' => '',312 'post_title' => '',313 'post_excerpt' => '',314 'post_content_filtered' => '',315 'post_mime_type' => '',316 'post_password' => '',317 'post_name' => '',318 'guid' => '',319 'menu_order' => 0,320 'pinged' => '',321 'to_ping' => '',322 'ping_status' => '',323 'comment_status' => 'closed',324 'comment_count' => 0,325 326 'is_404' => false,327 'is_page' => false,328 'is_single' => false,329 'is_archive' => false,330 'is_tax' => false,331 );332 333 300 // Switch defaults if post is set 334 if ( isset( $wp_query->post ) ) { 335 $d efaults =array(301 if ( isset( $wp_query->post ) ) { 302 $dummy = bbp_parse_args( $args, array( 336 303 'ID' => $wp_query->post->ID, 337 304 'post_status' => $wp_query->post->post_status, … … 357 324 'comment_status' => $wp_query->post->comment_status, 358 325 'comment_count' => $wp_query->post->comment_count, 359 360 'is_404' => false, 361 'is_page' => false, 362 'is_single' => false, 363 'is_archive' => false, 364 'is_tax' => false, 365 ); 366 } 367 $dummy = bbp_parse_args( $args, $defaults, 'theme_compat_reset_post' ); 368 369 // Clear out the post related globals 370 unset( $wp_query->posts ); 371 unset( $wp_query->post ); 372 unset( $post ); 373 374 // Setup the dummy post object 375 $wp_query->post = new stdClass; 376 $wp_query->post->ID = $dummy['ID']; 377 $wp_query->post->post_status = $dummy['post_status']; 378 $wp_query->post->post_author = $dummy['post_author']; 379 $wp_query->post->post_parent = $dummy['post_parent']; 380 $wp_query->post->post_type = $dummy['post_type']; 381 $wp_query->post->post_date = $dummy['post_date']; 382 $wp_query->post->post_date_gmt = $dummy['post_date_gmt']; 383 $wp_query->post->post_modified = $dummy['post_modified']; 384 $wp_query->post->post_modified_gmt = $dummy['post_modified_gmt']; 385 $wp_query->post->post_content = $dummy['post_content']; 386 $wp_query->post->post_title = $dummy['post_title']; 387 $wp_query->post->post_excerpt = $dummy['post_excerpt']; 388 $wp_query->post->post_content_filtered = $dummy['post_content_filtered']; 389 $wp_query->post->post_mime_type = $dummy['post_mime_type']; 390 $wp_query->post->post_password = $dummy['post_password']; 391 $wp_query->post->post_name = $dummy['post_name']; 392 $wp_query->post->guid = $dummy['guid']; 393 $wp_query->post->menu_order = $dummy['menu_order']; 394 $wp_query->post->pinged = $dummy['pinged']; 395 $wp_query->post->to_ping = $dummy['to_ping']; 396 $wp_query->post->ping_status = $dummy['ping_status']; 397 $wp_query->post->comment_status = $dummy['comment_status']; 398 $wp_query->post->comment_count = $dummy['comment_count']; 326 'filter' => $wp_query->post->filter, 327 328 'is_404' => false, 329 'is_page' => false, 330 'is_single' => false, 331 'is_archive' => false, 332 'is_tax' => false, 333 ), 'theme_compat_reset_post' ); 334 } else { 335 $dummy = bbp_parse_args( $args, array( 336 'ID' => -9999, 337 'post_status' => bbp_get_public_status_id(), 338 'post_author' => 0, 339 'post_parent' => 0, 340 'post_type' => 'page', 341 'post_date' => 0, 342 'post_date_gmt' => 0, 343 'post_modified' => 0, 344 'post_modified_gmt' => 0, 345 'post_content' => '', 346 'post_title' => '', 347 'post_excerpt' => '', 348 'post_content_filtered' => '', 349 'post_mime_type' => '', 350 'post_password' => '', 351 'post_name' => '', 352 'guid' => '', 353 'menu_order' => 0, 354 'pinged' => '', 355 'to_ping' => '', 356 'ping_status' => '', 357 'comment_status' => 'closed', 358 'comment_count' => 0, 359 'filter' => 'raw', 360 361 'is_404' => false, 362 'is_page' => false, 363 'is_single' => false, 364 'is_archive' => false, 365 'is_tax' => false, 366 ), 'theme_compat_reset_post' ); 367 } 368 369 // Bail if dummy post is empty 370 if ( empty( $dummy ) ) { 371 return; 372 } 399 373 400 374 // Set the $post global 401 $post = $wp_query->post; 402 403 // Setup the dummy post loop 404 $wp_query->posts[0] = $wp_query->post; 375 $post = new WP_Post( (object) $dummy ); 376 377 // Copy the new post global into the main $wp_query 378 $wp_query->post = $post; 379 $wp_query->posts = array( $post ); 405 380 406 381 // Prevent comments form from appearing … … 412 387 $wp_query->is_tax = $dummy['is_tax']; 413 388 389 // Clean up the dummy post 390 unset( $dummy ); 391 414 392 /** 415 393 * Force the header back to 200 status if not a deliberate 404 … … 417 395 * @see http://bbpress.trac.wordpress.org/ticket/1973 418 396 */ 419 if ( ! $wp_query->is_404() ) 397 if ( ! $wp_query->is_404() ) { 420 398 status_header( 200 ); 399 } 421 400 422 401 // If we are resetting a post, we are in theme compat 423 bbp_set_theme_compat_active( );402 bbp_set_theme_compat_active( true ); 424 403 } 425 404 … … 642 621 * 643 622 * We do this after the above checks to prevent incorrect 404 body classes 644 * and header statuses .623 * and header statuses, as well as to set the post global as needed. 645 624 * 646 625 * @see http://bbpress.trac.wordpress.org/ticket/1478/ 647 626 */ 648 if ( !empty( bbpress()->theme_compat->bbpress_template ) )627 if ( bbp_is_template_included() ) { 649 628 return $template; 650 629 … … 662 641 * should be coded without superfluous mark-up and logic (prev/next 663 642 * navigation, comments, date/time, etc...) 664 * 643 * 665 644 * Hook into the 'bbp_get_bbpress_template' to override the array of 666 645 * possible templates, or 'bbp_bbpress_template' to override the result. 667 646 */ 668 if ( bbp_is_theme_compat_active() ) { 669 670 // Hook to the beginning of the main post loop to remove all filters 671 // from the_content as late as possible. 647 } elseif ( bbp_is_theme_compat_active() ) { 648 $template = bbp_get_theme_compat_templates(); 649 650 // Hook onto the start and end of the loop, and prepare to replace the 651 // main section of the_content() output. 672 652 add_action( 'loop_start', 'bbp_theme_compat_main_loop_start', 9999 ); 673 674 // Hook to the end of the main post loop to restore all filters to675 // the_content as early as possible.676 653 add_action( 'loop_end', 'bbp_theme_compat_main_loop_end', -9999 ); 677 678 // Find the appropriate template file679 $template = bbp_get_theme_compat_templates();680 654 } 681 655 … … 700 674 function bbp_replace_the_content( $content = '' ) { 701 675 702 // Bail if not inside the query loop703 if ( ! in_the_loop() )676 // Bail if not the main loop where theme compat is happening 677 if ( ! bbp_do_theme_compat() ) 704 678 return $content; 705 679 706 $bbp = bbpress();707 708 680 // Define local variable(s) 709 $new_content = ''; 681 $new_content = ''; 682 $bbp_shortcodes = bbpress()->shortcodes; 710 683 711 684 // Bail if shortcodes are unset somehow 712 if ( !is_a( $bbp ->shortcodes, 'BBP_Shortcodes' ) )685 if ( !is_a( $bbp_shortcodes, 'BBP_Shortcodes' ) ) 713 686 return $content; 687 688 // Set theme compat to false early, to avoid recursion from nested calls to 689 // the_content() that execute before theme compat has unhooked itself. 690 bbp_set_theme_compat_active( false ); 714 691 715 692 // Use shortcode API to display forums/topics/replies because they are … … 724 701 bbp_get_template_part( 'content', 'single-user' ); 725 702 726 $new_content = ob_get_contents(); 727 728 ob_end_clean(); 703 $new_content = ob_get_clean(); 729 704 730 705 /** Forums ************************************************************/ … … 757 732 // Use the topics archive 758 733 } elseif ( 'topics' === bbp_show_on_root() ) { 759 $new_content = $bbp ->shortcodes->display_topic_index();734 $new_content = $bbp_shortcodes->display_topic_index(); 760 735 761 736 // No page so show the archive 762 737 } else { 763 $new_content = $bbp ->shortcodes->display_forum_index();738 $new_content = $bbp_shortcodes->display_forum_index(); 764 739 } 765 740 766 741 // Forum Edit 767 742 } elseif ( bbp_is_forum_edit() ) { 768 $new_content = $bbp ->shortcodes->display_forum_form();743 $new_content = $bbp_shortcodes->display_forum_form(); 769 744 770 745 // Single Forum 771 746 } elseif ( bbp_is_single_forum() ) { 772 $new_content = $bbp ->shortcodes->display_forum( array( 'id' => get_the_ID() ) );747 $new_content = $bbp_shortcodes->display_forum( array( 'id' => get_the_ID() ) ); 773 748 774 749 /** Topics ************************************************************/ … … 801 776 // No page so show the archive 802 777 } else { 803 $new_content = $bbp ->shortcodes->display_topic_index();778 $new_content = $bbp_shortcodes->display_topic_index(); 804 779 } 805 780 … … 813 788 bbp_get_template_part( 'form', 'topic-split' ); 814 789 815 $new_content = ob_get_contents(); 816 817 ob_end_clean(); 790 $new_content = ob_get_clean(); 818 791 819 792 // Merge … … 823 796 bbp_get_template_part( 'form', 'topic-merge' ); 824 797 825 $new_content = ob_get_contents(); 826 827 ob_end_clean(); 798 $new_content = ob_get_clean(); 828 799 829 800 // Edit 830 801 } else { 831 $new_content = $bbp ->shortcodes->display_topic_form();802 $new_content = $bbp_shortcodes->display_topic_form(); 832 803 } 833 804 834 805 // Single Topic 835 806 } elseif ( bbp_is_single_topic() ) { 836 $new_content = $bbp ->shortcodes->display_topic( array( 'id' => get_the_ID() ) );807 $new_content = $bbp_shortcodes->display_topic( array( 'id' => get_the_ID() ) ); 837 808 838 809 /** Replies ***********************************************************/ … … 840 811 // Reply archive 841 812 } elseif ( is_post_type_archive( bbp_get_reply_post_type() ) ) { 842 //$new_content = $bbp ->shortcodes->display_reply_index();813 //$new_content = $bbp_shortcodes->display_reply_index(); 843 814 844 815 // Reply Edit 845 816 } elseif ( bbp_is_reply_edit() ) { 846 817 847 818 // Move 848 819 if ( bbp_is_reply_move() ) { … … 851 822 bbp_get_template_part( 'form', 'reply-move' ); 852 823 853 $new_content = ob_get_contents(); 854 855 ob_end_clean(); 856 824 $new_content = ob_get_clean(); 825 857 826 // Edit 858 827 } else { 859 $new_content = $bbp ->shortcodes->display_reply_form();828 $new_content = $bbp_shortcodes->display_reply_form(); 860 829 } 861 830 862 831 // Single Reply 863 832 } elseif ( bbp_is_single_reply() ) { 864 $new_content = $bbp ->shortcodes->display_reply( array( 'id' => get_the_ID() ) );833 $new_content = $bbp_shortcodes->display_reply( array( 'id' => get_the_ID() ) ); 865 834 866 835 /** Views *************************************************************/ 867 836 868 837 } elseif ( bbp_is_single_view() ) { 869 $new_content = $bbp ->shortcodes->display_view( array( 'id' => get_query_var( 'bbp_view' ) ) );838 $new_content = $bbp_shortcodes->display_view( array( 'id' => get_query_var( 'bbp_view' ) ) ); 870 839 871 840 /** Search ************************************************************/ 872 841 873 842 } elseif ( bbp_is_search() ) { 874 $new_content = $bbp ->shortcodes->display_search( array( 'search' => get_query_var( 'bbp_search' ) ) );843 $new_content = $bbp_shortcodes->display_search( array( 'search' => get_query_var( 'bbp_search' ) ) ); 875 844 876 845 /** Topic Tags ********************************************************/ … … 878 847 // Show topics of tag 879 848 } elseif ( bbp_is_topic_tag() ) { 880 $new_content = $bbp ->shortcodes->display_topics_of_tag( array( 'id' => bbp_get_topic_tag_id() ) );849 $new_content = $bbp_shortcodes->display_topics_of_tag( array( 'id' => bbp_get_topic_tag_id() ) ); 881 850 882 851 // Edit topic tag 883 852 } elseif ( bbp_is_topic_tag_edit() ) { 884 $new_content = $bbp ->shortcodes->display_topic_tag_form();853 $new_content = $bbp_shortcodes->display_topic_tag_form(); 885 854 } 886 855 887 856 // Juggle the content around and try to prevent unsightly comments 888 if ( !empty( $new_content ) && ( $new_content != $content ) ) {857 if ( !empty( $new_content ) && ( $new_content !== $content ) ) { 889 858 890 859 // Set the content to be the new content … … 914 883 function bbp_theme_compat_main_loop_start() { 915 884 916 // Bail if not the main query917 if ( ! in_the_loop() )885 // Bail if not the main loop where theme compat is happening 886 if ( ! bbp_do_theme_compat() ) 918 887 return; 919 888 … … 936 905 function bbp_theme_compat_main_loop_end() { 937 906 938 // Bail if not the main query939 if ( ! in_the_loop() )907 // Bail if not the main loop where theme compat is happening 908 if ( ! bbp_do_theme_compat() ) 940 909 return; 941 910 … … 945 914 946 915 /** Helpers *******************************************************************/ 916 917 /** 918 * Are we replacing the_content 919 * 920 * @since bbPres (r4975) 921 * @return bool 922 */ 923 function bbp_do_theme_compat() { 924 return (bool) ( ! bbp_is_template_included() && in_the_loop() && bbp_is_theme_compat_active() ); 925 } 947 926 948 927 /**
Note: See TracChangeset
for help on using the changeset viewer.