Changeset 3623
- Timestamp:
- 11/20/2011 12:57:43 AM (14 years ago)
- Location:
- branches/plugin
- Files:
-
- 4 edited
-
bbp-admin/bbp-admin.php (modified) (1 diff)
-
bbp-admin/bbp-metaboxes.php (modified) (1 diff)
-
bbp-includes/bbp-core-compatibility.php (modified) (36 diffs)
-
bbp-includes/bbp-core-shortcodes.php (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/plugin/bbp-admin/bbp-admin.php
r3586 r3623 389 389 * 390 390 * @uses current_user_can() To check notice should be displayed. 391 * @uses current_theme_supports() To check theme for bbPress support392 391 */ 393 392 public function activation_notice() { 394 global $bbp, $pagenow; 395 396 // Bail if not on admin theme page 397 if ( 'themes.php' != $pagenow ) 398 return; 399 400 // Bail if user cannot change the theme 401 if ( !current_user_can( 'switch_themes' ) ) 402 return; 403 404 // Set $bbp->theme_compat to true to bypass nag 405 if ( !empty( $bbp->theme_compat->theme ) && !current_theme_supports( 'bbpress' ) ) : ?> 406 407 <div id="message" class="updated fade"> 408 <p style="line-height: 150%"><?php printf( __( "Your active theme does not include bbPress template files. Your forums are using the default styling included with bbPress.", 'bbpress' ), admin_url( 'themes.php' ), admin_url( 'theme-install.php?type=tag&s=bbpress&tab=search' ) ) ?></p> 409 </div> 410 411 <?php endif; 393 // @todo - something fun 412 394 } 413 395 -
branches/plugin/bbp-admin/bbp-metaboxes.php
r3563 r3623 209 209 <div class="versions"> 210 210 211 <p>212 <?php213 if ( current_theme_supports( 'bbpress' ) )214 _e( 'Theme is using <strong>custom bbPress</strong> styling.', 'bbpress' );215 else216 _e( 'Theme is using <strong>default bbPress</strong> styling.', 'bbpress' );217 ?>218 </p>219 220 211 <span id="wp-version-message"> 221 212 <?php printf( __( 'You are using <span class="b">bbPress %s</span>.', 'bbpress' ), bbp_get_version() ); ?> -
branches/plugin/bbp-includes/bbp-core-compatibility.php
r3615 r3623 66 66 * @global bbPress $bbp 67 67 * @param BBP_Theme_Compat $theme 68 * @uses current_theme_supports()69 68 */ 70 69 function bbp_setup_theme_compat( $theme = '' ) { … … 72 71 73 72 // Check if current theme supports bbPress 74 if ( empty( $bbp->theme_compat->theme ) && !current_theme_supports( 'bbpress' )) {73 if ( empty( $bbp->theme_compat->theme ) ) { 75 74 if ( empty( $theme ) ) { 76 75 $theme = new BBP_Theme_Compat(); … … 92 91 * 93 92 * @uses bbp_set_compat_theme_dir() Set the compatable theme to bbp-twentyten 94 * @uses current_theme_supports() Check bbPress theme support95 93 * @uses wp_enqueue_style() Enqueue the bbp-twentyten default CSS 96 94 * @uses wp_enqueue_script() Enqueue the bbp-twentyten default topic JS … … 98 96 function bbp_theme_compat_enqueue_css() { 99 97 100 // Check if current theme supports bbPress 101 if ( !current_theme_supports( 'bbpress' ) ) { 102 103 // Version of CSS 104 $version = bbp_get_theme_compat_version(); 105 106 // Right to left 107 if ( is_rtl() ) { 108 wp_enqueue_style( 'bbpress-style', bbp_get_theme_compat_url() . '/css/bbpress-rtl.css', '', $version, 'screen' ); 109 110 // Left to right 111 } else { 112 wp_enqueue_style( 'bbpress-style', bbp_get_theme_compat_url() . '/css/bbpress.css', '', $version, 'screen' ); 113 } 98 // Version of CSS 99 $version = bbp_get_theme_compat_version(); 100 101 // Right to left 102 if ( is_rtl() ) { 103 wp_enqueue_style( 'bbpress-style', bbp_get_theme_compat_url() . '/css/bbpress-rtl.css', '', $version, 'screen' ); 104 105 // Left to right 106 } else { 107 wp_enqueue_style( 'bbpress-style', bbp_get_theme_compat_url() . '/css/bbpress.css', '', $version, 'screen' ); 114 108 } 115 109 } … … 117 111 /** 118 112 * Adds bbPress theme support to any active WordPress theme 119 *120 * This function is really cool because it's responsible for managing the121 * theme compatability layer when the current theme does not support bbPress.122 * It uses the current_theme_supports() WordPress function to see if 'bbpress'123 * is explicitly supported. If not, it will directly load the requested template124 * part using load_template(). If so, it proceeds with using get_template_part()125 * as per normal, and no one is the wiser.126 113 * 127 114 * @since bbPress (r3032) … … 129 116 * @param string $slug 130 117 * @param string $name Optional. Default null 131 * @uses current_theme_supports()118 * @uses bbp_locate_template() 132 119 * @uses load_template() 133 120 * @uses get_template_part() … … 135 122 function bbp_get_template_part( $slug, $name = null ) { 136 123 137 // Current theme does not support bbPress, so we need to do some heavy 138 // lifting to see if a bbPress template is needed in the current context 139 if ( !current_theme_supports( 'bbpress' ) ) 140 load_template( bbp_get_theme_compat_dir() . '/' . $slug . '-' . $name . '.php', false ); 141 142 // Current theme supports bbPress to proceed as usual 143 else 144 get_template_part( $slug, $name ); 145 124 do_action( 'get_template_part_' . $slug, $slug, $name ); 125 126 $templates = array(); 127 if ( isset( $name ) ) 128 $templates[] = $slug . '-' . $name . '.php'; 129 130 $templates[] = $slug . '.php'; 131 132 return bbp_locate_template( $templates, true, false ); 133 } 134 135 /** 136 * Retrieve the name of the highest priority template file that exists. 137 * 138 * Searches in the STYLESHEETPATH before TEMPLATEPATH so that themes which 139 * inherit from a parent theme can just overload one file. If the template is 140 * not found in either of those, it looks in the theme-compat folder last. 141 * 142 * @since bbPres (r3618) 143 * 144 * @param string|array $template_names Template file(s) to search for, in order. 145 * @param bool $load If true the template file will be loaded if it is found. 146 * @param bool $require_once Whether to require_once or require. Default true. 147 * Has no effect if $load is false. 148 * @return string The template filename if one is located. 149 */ 150 function bbp_locate_template( $template_names, $load = false, $require_once = true ) { 151 152 // No file found yet 153 $located = false; 154 155 // Try to find a template file 156 foreach ( (array) $template_names as $template_name ) { 157 158 // Continue if template is empty 159 if ( empty( $template_name ) ) 160 continue; 161 162 // Check child theme first 163 if ( file_exists( STYLESHEETPATH . '/' . $template_name ) ) { 164 $located = STYLESHEETPATH . '/' . $template_name; 165 break; 166 167 // Check parent theme next 168 } else if ( file_exists( TEMPLATEPATH . '/' . $template_name ) ) { 169 $located = TEMPLATEPATH . '/' . $template_name; 170 break; 171 172 // Check theme compatibility last 173 } else if ( file_exists( bbp_get_theme_compat_dir() . '/' . $template_name ) ) { 174 $located = bbp_get_theme_compat_dir() . '/' . $template_name; 175 break; 176 } 177 } 178 179 if ( ( true == $load ) && !empty( $located ) ) 180 load_template( $located, $require_once ); 181 182 return $located; 146 183 } 147 184 … … 303 340 function bbp_theme_compat_reset_post( $args = array() ) { 304 341 global $wp_query, $post; 305 306 // Why would you ever want to do this otherwise?307 if ( current_theme_supports( 'bbpress' ) )308 wp_die( __( 'Hands off, partner!', 'bbpress' ) );309 342 310 343 // Default arguments … … 390 423 * 391 424 * @uses bbp_get_displayed_user_id() 425 * @uses bbp_locate_template() 392 426 * @uses apply_filters() 393 427 * … … 424 458 $templates = bbp_set_theme_compat_templates( $templates ); 425 459 426 $template = locate_template( $templates, false, false );460 $template = bbp_locate_template( $templates, false, false ); 427 461 $template = bbp_set_theme_compat_template( $template ); 428 462 … … 435 469 * @since bbPress (r3311) 436 470 * 437 * @uses $displayed 471 * @uses bbp_get_displayed_user_id() 472 * @uses bbp_locate_template() 438 473 * @uses apply_filters() 439 474 * … … 475 510 $templates = bbp_set_theme_compat_templates( $templates ); 476 511 477 $template = locate_template( $templates, false, false );512 $template = bbp_locate_template( $templates, false, false ); 478 513 $template = bbp_set_theme_compat_template( $template ); 479 514 … … 487 522 * 488 523 * @uses bbp_get_view_id() 524 * @uses bbp_locate_template() 489 525 * @uses apply_filters() 490 526 * … … 520 556 $templates = bbp_set_theme_compat_templates( $templates ); 521 557 522 $template = locate_template( $templates, false, false );558 $template = bbp_locate_template( $templates, false, false ); 523 559 $template = bbp_set_theme_compat_template( $template ); 524 560 … … 532 568 * 533 569 * @uses bbp_get_topic_post_type() 570 * @uses bbp_locate_template() 534 571 * @uses apply_filters() 535 572 * … … 555 592 $templates = bbp_set_theme_compat_templates( $templates ); 556 593 557 $template = locate_template( $templates, false, false );594 $template = bbp_locate_template( $templates, false, false ); 558 595 $template = bbp_set_theme_compat_template( $template ); 559 596 … … 567 604 * 568 605 * @uses bbp_get_topic_post_type() 606 * @uses bbp_locate_template() 569 607 * @uses apply_filters() 570 608 * … … 590 628 $templates = bbp_set_theme_compat_templates( $templates ); 591 629 592 $template = locate_template( $templates, false, false );630 $template = bbp_locate_template( $templates, false, false ); 593 631 $template = bbp_set_theme_compat_template( $template ); 594 632 … … 602 640 * 603 641 * @uses bbp_get_topic_post_type() 642 * @uses bbp_locate_template() 604 643 * @uses apply_filters() 605 644 * … … 620 659 $templates = bbp_set_theme_compat_templates( $templates ); 621 660 622 $template = locate_template( $templates, false, false );661 $template = bbp_locate_template( $templates, false, false ); 623 662 $template = bbp_set_theme_compat_template( $template ); 624 663 … … 632 671 * 633 672 * @uses bbp_get_topic_post_type() 673 * @uses bbp_locate_template() 634 674 * @uses apply_filters() 635 675 * … … 650 690 $templates = bbp_set_theme_compat_templates( $templates ); 651 691 652 $template = locate_template( $templates, false, false );692 $template = bbp_locate_template( $templates, false, false ); 653 693 $template = bbp_set_theme_compat_template( $template ); 654 694 … … 662 702 * 663 703 * @uses bbp_get_reply_post_type() 704 * @uses bbp_locate_template() 664 705 * @uses apply_filters() 665 706 * … … 685 726 $templates = bbp_set_theme_compat_templates( $templates ); 686 727 687 $template = locate_template( $templates, false, false );728 $template = bbp_locate_template( $templates, false, false ); 688 729 $template = bbp_set_theme_compat_template( $template ); 689 730 … … 697 738 * 698 739 * @uses bbp_get_topic_tag_tax_id() 740 * @uses bbp_locate_template() 699 741 * @uses apply_filters() 700 742 * … … 720 762 $templates = bbp_set_theme_compat_templates( $templates ); 721 763 722 $template = locate_template( $templates, false, false );764 $template = bbp_locate_template( $templates, false, false ); 723 765 $template = bbp_set_theme_compat_template( $template ); 724 766 … … 732 774 * 733 775 * @uses bbp_get_topic_tag_tax_id() 776 * @uses bbp_locate_template() 734 777 * @uses apply_filters() 735 778 * … … 764 807 $templates = bbp_set_theme_compat_templates( $templates ); 765 808 766 $template = locate_template( $templates, false, false );809 $template = bbp_locate_template( $templates, false, false ); 767 810 $template = bbp_set_theme_compat_template( $template ); 768 811 … … 776 819 * 777 820 * @uses apply_filters() 778 * @uses bbp_set_theme_compat_templates(); 821 * @uses bbp_set_theme_compat_templates() 822 * @uses bbp_locate_template() 779 823 * 780 824 * @return type … … 793 837 $templates = bbp_set_theme_compat_templates( $templates ); 794 838 795 $template = locate_template( $templates, false, false );839 $template = bbp_locate_template( $templates, false, false ); 796 840 $template = bbp_set_theme_compat_template( $template ); 797 841 … … 812 856 * @param string $template 813 857 * 814 * @uses current_theme_supports() To check if theme supports bbPress815 858 * @uses bbp_is_single_user() To check if page is single user 816 859 * @uses bbp_get_single_user_template() To get user template … … 835 878 function bbp_template_include_theme_supports( $template = '' ) { 836 879 837 // Current theme supports bbPress 838 if ( current_theme_supports( 'bbpress' ) ) { 839 840 // Viewing a user 841 if ( bbp_is_single_user() && ( $new_template = bbp_get_single_user_template() ) ) : 842 843 // Editing a user 844 elseif ( bbp_is_single_user_edit() && ( $new_template = bbp_get_single_user_edit_template() ) ) : 845 846 // Single View 847 elseif ( bbp_is_single_view() && ( $new_template = bbp_get_single_view_template() ) ) : 848 849 // Forum edit 850 elseif ( bbp_is_forum_edit() && ( $new_template = bbp_get_forum_edit_template() ) ) : 851 852 // Topic merge 853 elseif ( bbp_is_topic_merge() && ( $new_template = bbp_get_topic_merge_template() ) ) : 854 855 // Topic split 856 elseif ( bbp_is_topic_split() && ( $new_template = bbp_get_topic_split_template() ) ) : 857 858 // Topic edit 859 elseif ( bbp_is_topic_edit() && ( $new_template = bbp_get_topic_edit_template() ) ) : 860 861 // Editing a reply 862 elseif ( bbp_is_reply_edit() && ( $new_template = bbp_get_reply_edit_template() ) ) : 863 864 // Viewing a topic tag 865 elseif ( bbp_is_topic_tag() && ( $new_template = bbp_get_topic_tag_template() ) ) : 866 867 // Editing a topic tag 868 elseif ( bbp_is_topic_tag_edit() && ( $new_template = bbp_get_topic_tag_edit_template() ) ) : 869 endif; 870 871 // Custom template file exists 872 $template = !empty( $new_template ) ? $new_template : $template; 873 } 880 // Viewing a user 881 if ( bbp_is_single_user() && ( $new_template = bbp_get_single_user_template() ) ) : 882 883 // Editing a user 884 elseif ( bbp_is_single_user_edit() && ( $new_template = bbp_get_single_user_edit_template() ) ) : 885 886 // Single View 887 elseif ( bbp_is_single_view() && ( $new_template = bbp_get_single_view_template() ) ) : 888 889 // Topic edit 890 elseif ( bbp_is_forum_edit() && ( $new_template = bbp_get_forum_edit_template() ) ) : 891 892 // Topic merge 893 elseif ( bbp_is_topic_merge() && ( $new_template = bbp_get_topic_merge_template() ) ) : 894 895 // Topic split 896 elseif ( bbp_is_topic_split() && ( $new_template = bbp_get_topic_split_template() ) ) : 897 898 // Topic edit 899 elseif ( bbp_is_topic_edit() && ( $new_template = bbp_get_topic_edit_template() ) ) : 900 901 // Editing a reply 902 elseif ( bbp_is_reply_edit() && ( $new_template = bbp_get_reply_edit_template() ) ) : 903 904 // Viewing a topic tag 905 elseif ( bbp_is_topic_tag() && ( $new_template = bbp_get_topic_tag_template() ) ) : 906 907 // Editing a topic tag 908 elseif ( bbp_is_topic_tag_edit() && ( $new_template = bbp_get_topic_tag_edit_template() ) ) : 909 endif; 910 911 // Custom template file exists 912 $template = !empty( $new_template ) ? $new_template : $template; 874 913 875 914 return apply_filters( 'bbp_template_include_theme_supports', $template ); … … 882 921 */ 883 922 function bbp_template_include_theme_compat( $template = '' ) { 884 global $bbp; 885 886 if ( !current_theme_supports( 'bbpress' ) || ( !empty( $bbp->theme_compat->templates ) && empty( $bbp->theme_compat->template ) ) ) { 887 888 /** Users *************************************************************/ 889 890 if ( bbp_is_single_user() || bbp_is_single_user_edit() ) { 891 892 // Reset post 893 bbp_theme_compat_reset_post( array( 894 'post_title' => esc_attr( bbp_get_displayed_user_field( 'display_name' ) ), 895 'comment_status' => 'closed' 896 ) ); 897 898 /** Forums ************************************************************/ 899 900 // Single forum edit 901 } elseif ( bbp_is_forum_edit() ) { 902 903 // Reset post 904 bbp_theme_compat_reset_post( array( 905 'ID' => bbp_get_forum_id(), 906 'post_title' => bbp_get_forum_title(), 907 //'post_author' => bbp_get_forum_author_id(), 908 'post_date' => 0, 909 'post_content' => get_post_field( 'post_content', bbp_get_forum_id() ), 910 'post_type' => bbp_get_forum_post_type(), 911 'post_status' => bbp_get_forum_status(), 912 'is_single' => true, 913 'comment_status' => 'closed' 914 ) ); 915 916 // Forum archive 917 } elseif ( bbp_is_forum_archive() ) { 918 919 // Reset post 920 bbp_theme_compat_reset_post( array( 921 'ID' => 0, 922 'post_title' => bbp_get_forum_archive_title(), 923 'post_author' => 0, 924 'post_date' => 0, 925 'post_content' => '', 926 'post_type' => bbp_get_forum_post_type(), 927 'post_status' => bbp_get_public_status_id(), 928 'is_archive' => true, 929 'comment_status' => 'closed' 930 ) ); 931 932 /** Topics ************************************************************/ 933 934 // Topic archive 935 } elseif ( bbp_is_topic_archive() ) { 936 937 // Reset post 938 bbp_theme_compat_reset_post( array( 939 'ID' => 0, 940 'post_title' => bbp_get_topic_archive_title(), 941 'post_author' => 0, 942 'post_date' => 0, 943 'post_content' => '', 944 'post_type' => bbp_get_topic_post_type(), 945 'post_status' => bbp_get_public_status_id(), 946 'is_archive' => true, 947 'comment_status' => 'closed' 948 ) ); 949 950 // Single topic 951 } elseif ( bbp_is_topic_edit() || bbp_is_topic_split() || bbp_is_topic_merge() ) { 952 953 // Reset post 954 bbp_theme_compat_reset_post( array( 955 'ID' => bbp_get_topic_id(), 956 'post_title' => bbp_get_topic_title(), 957 'post_author' => bbp_get_topic_author_id(), 958 'post_date' => 0, 959 'post_content' => get_post_field( 'post_content', bbp_get_topic_id() ), 960 'post_type' => bbp_get_topic_post_type(), 961 'post_status' => bbp_get_topic_status(), 962 'is_single' => true, 963 'comment_status' => 'closed' 964 ) ); 965 966 /** Replies ***********************************************************/ 967 968 // Reply archive 969 } elseif ( is_post_type_archive( bbp_get_reply_post_type() ) ) { 970 971 // Reset post 972 bbp_theme_compat_reset_post( array( 973 'ID' => 0, 974 'post_title' => __( 'Replies', 'bbpress' ), 975 'post_author' => 0, 976 'post_date' => 0, 977 'post_content' => '', 978 'post_type' => bbp_get_reply_post_type(), 979 'post_status' => bbp_get_public_status_id(), 980 'comment_status' => 'closed' 981 ) ); 982 983 // Single reply 984 } elseif ( bbp_is_reply_edit() ) { 985 986 // Reset post 987 bbp_theme_compat_reset_post( array( 988 'ID' => bbp_get_reply_id(), 989 'post_title' => bbp_get_reply_title(), 990 'post_author' => bbp_get_reply_author_id(), 991 'post_date' => 0, 992 'post_content' => get_post_field( 'post_content', bbp_get_reply_id() ), 993 'post_type' => bbp_get_reply_post_type(), 994 'post_status' => bbp_get_reply_status(), 995 'comment_status' => 'closed' 996 ) ); 997 998 /** Views *************************************************************/ 999 1000 } elseif ( bbp_is_single_view() ) { 1001 1002 // Reset post 1003 bbp_theme_compat_reset_post( array( 1004 'ID' => 0, 1005 'post_title' => bbp_get_view_title(), 1006 'post_author' => 0, 1007 'post_date' => 0, 1008 'post_content' => '', 1009 'post_type' => '', 1010 'post_status' => bbp_get_public_status_id(), 1011 'comment_status' => 'closed' 1012 ) ); 1013 1014 1015 /** Topic Tags ********************************************************/ 1016 1017 } elseif ( bbp_is_topic_tag_edit() ) { 1018 1019 // Stash the current term in a new var 1020 set_query_var( 'bbp_topic_tag', get_query_var( 'term' ) ); 1021 1022 // Reset the post with our new title 1023 bbp_theme_compat_reset_post( array( 1024 'post_title' => sprintf( __( 'Topic Tag: %s', 'bbpress' ), '<span>' . bbp_get_topic_tag_name() . '</span>' ) 1025 ) ); 1026 1027 } elseif ( bbp_is_topic_tag() ) { 1028 1029 // Stash the current term in a new var 1030 set_query_var( 'bbp_topic_tag', get_query_var( 'term' ) ); 1031 1032 // Reset the post with our new title 1033 bbp_theme_compat_reset_post( array( 1034 'post_title' => sprintf( __( 'Topic Tag: %s', 'bbpress' ), '<span>' . bbp_get_topic_tag_name() . '</span>' ) 1035 ) ); 1036 1037 /** Single Forums/Topics/Replies **************************************/ 1038 1039 } elseif ( bbp_is_custom_post_type() ) { 1040 bbp_set_theme_compat_active(); 1041 } 1042 1043 /** 1044 * If we are relying on bbPress's built in theme compatibility to load 1045 * the proper content, we need to intercept the_content, replace the 1046 * output, and display ours instead. 1047 * 1048 * To do this, we first remove all filters from 'the_content' and hook 1049 * our own function into it, which runs a series of checks to determine 1050 * the context, and then uses the built in shortcodes to output the 1051 * correct results. 1052 * 1053 * We default to using page.php, since it's most likely to exist and 1054 * should be coded to work without superfluous elements and logic, like 1055 * prev/next navigation, comments, date/time, etc... You can hook into 1056 * the 'bbp_template_include' filter to override page.php. 1057 */ 1058 if ( bbp_is_theme_compat_active() ) { 1059 1060 // Remove all filters from the_content 1061 bbp_remove_all_filters( 'the_content' ); 1062 1063 // Add a filter on the_content late, which we will later remove 1064 add_filter( 'the_content', 'bbp_replace_the_content' ); 1065 1066 // Find the appropriate template file 1067 $template = bbp_get_theme_compat_templates(); 1068 } 923 924 /** Users *************************************************************/ 925 926 if ( bbp_is_single_user() || bbp_is_single_user_edit() ) { 927 928 // Reset post 929 bbp_theme_compat_reset_post( array( 930 'post_title' => esc_attr( bbp_get_displayed_user_field( 'display_name' ) ), 931 'comment_status' => 'closed' 932 ) ); 933 934 /** Forums ************************************************************/ 935 936 // Single forum edit 937 } elseif ( bbp_is_forum_edit() ) { 938 939 // Reset post 940 bbp_theme_compat_reset_post( array( 941 'ID' => bbp_get_forum_id(), 942 'post_title' => bbp_get_forum_title(), 943 //'post_author' => bbp_get_forum_author_id(), 944 'post_date' => 0, 945 'post_content' => get_post_field( 'post_content', bbp_get_forum_id() ), 946 'post_type' => bbp_get_forum_post_type(), 947 'post_status' => bbp_get_forum_status(), 948 'is_single' => true, 949 'comment_status' => 'closed' 950 ) ); 951 952 // Forum archive 953 } elseif ( bbp_is_forum_archive() ) { 954 955 // Reset post 956 bbp_theme_compat_reset_post( array( 957 'ID' => 0, 958 'post_title' => bbp_get_forum_archive_title(), 959 'post_author' => 0, 960 'post_date' => 0, 961 'post_content' => '', 962 'post_type' => bbp_get_forum_post_type(), 963 'post_status' => bbp_get_public_status_id(), 964 'is_archive' => true, 965 'comment_status' => 'closed' 966 ) ); 967 968 /** Topics ************************************************************/ 969 970 // Topic archive 971 } elseif ( bbp_is_topic_archive() ) { 972 973 // Reset post 974 bbp_theme_compat_reset_post( array( 975 'ID' => 0, 976 'post_title' => bbp_get_topic_archive_title(), 977 'post_author' => 0, 978 'post_date' => 0, 979 'post_content' => '', 980 'post_type' => bbp_get_topic_post_type(), 981 'post_status' => bbp_get_public_status_id(), 982 'is_archive' => true, 983 'comment_status' => 'closed' 984 ) ); 985 986 // Single topic 987 } elseif ( bbp_is_topic_edit() || bbp_is_topic_split() || bbp_is_topic_merge() ) { 988 989 // Reset post 990 bbp_theme_compat_reset_post( array( 991 'ID' => bbp_get_topic_id(), 992 'post_title' => bbp_get_topic_title(), 993 'post_author' => bbp_get_topic_author_id(), 994 'post_date' => 0, 995 'post_content' => get_post_field( 'post_content', bbp_get_topic_id() ), 996 'post_type' => bbp_get_topic_post_type(), 997 'post_status' => bbp_get_topic_status(), 998 'is_single' => true, 999 'comment_status' => 'closed' 1000 ) ); 1001 1002 /** Replies ***********************************************************/ 1003 1004 // Reply archive 1005 } elseif ( is_post_type_archive( bbp_get_reply_post_type() ) ) { 1006 1007 // Reset post 1008 bbp_theme_compat_reset_post( array( 1009 'ID' => 0, 1010 'post_title' => __( 'Replies', 'bbpress' ), 1011 'post_author' => 0, 1012 'post_date' => 0, 1013 'post_content' => '', 1014 'post_type' => bbp_get_reply_post_type(), 1015 'post_status' => bbp_get_public_status_id(), 1016 'comment_status' => 'closed' 1017 ) ); 1018 1019 // Single reply 1020 } elseif ( bbp_is_reply_edit() ) { 1021 1022 // Reset post 1023 bbp_theme_compat_reset_post( array( 1024 'ID' => bbp_get_reply_id(), 1025 'post_title' => bbp_get_reply_title(), 1026 'post_author' => bbp_get_reply_author_id(), 1027 'post_date' => 0, 1028 'post_content' => get_post_field( 'post_content', bbp_get_reply_id() ), 1029 'post_type' => bbp_get_reply_post_type(), 1030 'post_status' => bbp_get_reply_status(), 1031 'comment_status' => 'closed' 1032 ) ); 1033 1034 /** Views *************************************************************/ 1035 1036 } elseif ( bbp_is_single_view() ) { 1037 1038 // Reset post 1039 bbp_theme_compat_reset_post( array( 1040 'ID' => 0, 1041 'post_title' => bbp_get_view_title(), 1042 'post_author' => 0, 1043 'post_date' => 0, 1044 'post_content' => '', 1045 'post_type' => '', 1046 'post_status' => bbp_get_public_status_id(), 1047 'comment_status' => 'closed' 1048 ) ); 1049 1050 1051 /** Topic Tags ********************************************************/ 1052 1053 } elseif ( bbp_is_topic_tag_edit() ) { 1054 1055 // Stash the current term in a new var 1056 set_query_var( 'bbp_topic_tag', get_query_var( 'term' ) ); 1057 1058 // Reset the post with our new title 1059 bbp_theme_compat_reset_post( array( 1060 'post_title' => sprintf( __( 'Topic Tag: %s', 'bbpress' ), '<span>' . bbp_get_topic_tag_name() . '</span>' ) 1061 ) ); 1062 1063 } elseif ( bbp_is_topic_tag() ) { 1064 1065 // Stash the current term in a new var 1066 set_query_var( 'bbp_topic_tag', get_query_var( 'term' ) ); 1067 1068 // Reset the post with our new title 1069 bbp_theme_compat_reset_post( array( 1070 'post_title' => sprintf( __( 'Topic Tag: %s', 'bbpress' ), '<span>' . bbp_get_topic_tag_name() . '</span>' ) 1071 ) ); 1072 1073 /** Single Forums/Topics/Replies **************************************/ 1074 1075 } elseif ( bbp_is_custom_post_type() ) { 1076 bbp_set_theme_compat_active(); 1077 } 1078 1079 /** 1080 * If we are relying on bbPress's built in theme compatibility to load 1081 * the proper content, we need to intercept the_content, replace the 1082 * output, and display ours instead. 1083 * 1084 * To do this, we first remove all filters from 'the_content' and hook 1085 * our own function into it, which runs a series of checks to determine 1086 * the context, and then uses the built in shortcodes to output the 1087 * correct results. 1088 * 1089 * We default to using page.php, since it's most likely to exist and 1090 * should be coded to work without superfluous elements and logic, like 1091 * prev/next navigation, comments, date/time, etc... You can hook into 1092 * the 'bbp_template_include' filter to override page.php. 1093 */ 1094 if ( bbp_is_theme_compat_active() ) { 1095 1096 // Remove all filters from the_content 1097 bbp_remove_all_filters( 'the_content' ); 1098 1099 // Add a filter on the_content late, which we will later remove 1100 add_filter( 'the_content', 'bbp_replace_the_content' ); 1101 1102 // Find the appropriate template file 1103 $template = bbp_get_theme_compat_templates(); 1069 1104 } 1070 1105 … … 1086 1121 function bbp_replace_the_content( $content = '' ) { 1087 1122 1088 // Current theme does not support bbPress, so we need to do some heavy 1089 // lifting to see if a bbPress template is needed in the current context 1090 if ( !current_theme_supports( 'bbpress' ) ) { 1091 1092 // Use the $post global to check it's post_type 1093 global $bbp; 1094 1095 // Define local variable(s) 1096 $new_content = ''; 1097 1098 // Remove the filter that was added in bbp_template_include() 1099 remove_filter( 'the_content', 'bbp_replace_the_content' ); 1100 1101 // Bail if shortcodes are unset somehow 1102 if ( empty( $bbp->shortcodes ) ) 1103 return $content; 1104 1105 // Use shortcode API to display forums/topics/replies because they are 1106 // already output buffered and ready to fit inside the_content 1107 1108 /** Users *************************************************************/ 1109 1110 // Profile View 1111 if ( bbp_is_single_user() ) { 1123 // Use the $post global to check it's post_type 1124 global $bbp; 1125 1126 // Define local variable(s) 1127 $new_content = ''; 1128 1129 // Remove the filter that was added in bbp_template_include() 1130 remove_filter( 'the_content', 'bbp_replace_the_content' ); 1131 1132 // Bail if shortcodes are unset somehow 1133 if ( !is_a( $bbp->shortcodes, 'BBP_Shortcodes' ) ) 1134 return $content; 1135 1136 // Use shortcode API to display forums/topics/replies because they are 1137 // already output buffered and ready to fit inside the_content 1138 1139 /** Users *************************************************************/ 1140 1141 // Profile View 1142 if ( bbp_is_single_user() ) { 1143 ob_start(); 1144 1145 bbp_get_template_part( 'bbpress/content', 'single-user' ); 1146 1147 $new_content = ob_get_contents(); 1148 1149 ob_end_clean(); 1150 1151 // Profile Edit 1152 } elseif ( bbp_is_single_user_edit() ) { 1153 ob_start(); 1154 1155 bbp_get_template_part( 'bbpress/content', 'single-user-edit' ); 1156 1157 $new_content = ob_get_contents(); 1158 1159 ob_end_clean(); 1160 1161 /** Forums ************************************************************/ 1162 1163 // Reply Edit 1164 } elseif ( bbp_is_forum_edit() ) { 1165 $new_content = $bbp->shortcodes->display_forum_form(); 1166 1167 // Forum archive 1168 } elseif ( bbp_is_forum_archive() ) { 1169 1170 // Page exists where this archive should be 1171 $page = bbp_get_page_by_path( $bbp->root_slug ); 1172 if ( !empty( $page ) ) { 1173 1174 // Start output buffer 1112 1175 ob_start(); 1113 1176 1114 bbp_get_template_part( 'bbpress/content', 'single-user' ); 1177 // Restore previously unset filters 1178 bbp_restore_all_filters( 'the_content' ); 1179 1180 // Grab the content of this page 1181 $new_content = do_shortcode( apply_filters( 'the_content', get_post_field( 'post_content', $page->ID ) ) ); 1182 1183 // Clean up the buffer 1184 ob_end_clean(); 1185 1186 // No page so show the archive 1187 } else { 1188 $new_content = $bbp->shortcodes->display_forum_index(); 1189 } 1190 1191 /** Topics ************************************************************/ 1192 1193 // Topic archive 1194 } elseif ( bbp_is_topic_archive() ) { 1195 1196 // Page exists where this archive should be 1197 $page = bbp_get_page_by_path( $bbp->topic_archive_slug ); 1198 if ( !empty( $page ) ) { 1199 1200 // Start output buffer 1201 ob_start(); 1202 1203 // Restore previously unset filters 1204 bbp_restore_all_filters( 'the_content' ); 1205 1206 // Grab the content of this page 1207 $new_content = do_shortcode( apply_filters( 'the_content', get_post_field( 'post_content', $page->ID ) ) ); 1208 1209 // Clean up the buffer 1210 ob_end_clean(); 1211 1212 1213 // No page so show the archive 1214 } else { 1215 $new_content = $bbp->shortcodes->display_topic_index(); 1216 } 1217 1218 // Single topic 1219 } elseif ( bbp_is_topic_edit() ) { 1220 1221 // Split 1222 if ( bbp_is_topic_split() ) { 1223 ob_start(); 1224 1225 bbp_get_template_part( 'bbpress/form', 'topic-split' ); 1115 1226 1116 1227 $new_content = ob_get_contents(); … … 1118 1229 ob_end_clean(); 1119 1230 1120 // Profile Edit1121 } elseif ( bbp_is_ single_user_edit() ) {1231 // Merge 1232 } elseif ( bbp_is_topic_merge() ) { 1122 1233 ob_start(); 1123 1234 1124 bbp_get_template_part( 'bbpress/ content', 'single-user-edit' );1235 bbp_get_template_part( 'bbpress/form', 'topic-merge' ); 1125 1236 1126 1237 $new_content = ob_get_contents(); … … 1128 1239 ob_end_clean(); 1129 1240 1130 /** Forums ************************************************************/ 1131 1132 // Reply Edit 1133 } elseif ( bbp_is_forum_edit() ) { 1134 $new_content = $bbp->shortcodes->display_forum_form(); 1135 1136 // Forum archive 1137 } elseif ( bbp_is_forum_archive() ) { 1138 1139 // Page exists where this archive should be 1140 $page = bbp_get_page_by_path( $bbp->root_slug ); 1141 if ( !empty( $page ) ) { 1142 1143 // Start output buffer 1144 ob_start(); 1145 1146 // Restore previously unset filters 1147 bbp_restore_all_filters( 'the_content' ); 1148 1149 // Grab the content of this page 1150 $new_content = do_shortcode( apply_filters( 'the_content', get_post_field( 'post_content', $page->ID ) ) ); 1151 1152 // Clean up the buffer 1153 ob_end_clean(); 1154 1155 // No page so show the archive 1156 } else { 1157 $new_content = $bbp->shortcodes->display_forum_index(); 1158 } 1159 1160 /** Topics ************************************************************/ 1161 1162 // Topic archive 1163 } elseif ( bbp_is_topic_archive() ) { 1164 1165 // Page exists where this archive should be 1166 $page = bbp_get_page_by_path( $bbp->topic_archive_slug ); 1167 if ( !empty( $page ) ) { 1168 1169 // Start output buffer 1170 ob_start(); 1171 1172 // Restore previously unset filters 1173 bbp_restore_all_filters( 'the_content' ); 1174 1175 // Grab the content of this page 1176 $new_content = do_shortcode( apply_filters( 'the_content', get_post_field( 'post_content', $page->ID ) ) ); 1177 1178 // Clean up the buffer 1179 ob_end_clean(); 1180 1181 1182 // No page so show the archive 1183 } else { 1184 $new_content = $bbp->shortcodes->display_topic_index(); 1185 } 1186 1187 // Single topic 1188 } elseif ( bbp_is_topic_edit() ) { 1189 1190 // Split 1191 if ( bbp_is_topic_split() ) { 1192 ob_start(); 1193 1194 bbp_get_template_part( 'bbpress/form', 'topic-split' ); 1195 1196 $new_content = ob_get_contents(); 1197 1198 ob_end_clean(); 1199 1200 // Merge 1201 } elseif ( bbp_is_topic_merge() ) { 1202 ob_start(); 1203 1204 bbp_get_template_part( 'bbpress/form', 'topic-merge' ); 1205 1206 $new_content = ob_get_contents(); 1207 1208 ob_end_clean(); 1209 1210 // Edit 1211 } else { 1212 $new_content = $bbp->shortcodes->display_topic_form(); 1213 } 1214 1215 /** Replies ***********************************************************/ 1216 1217 // Reply archive 1218 } elseif ( is_post_type_archive( bbp_get_reply_post_type() ) ) { 1219 //$new_content = $bbp->shortcodes->display_reply_index(); 1220 1221 // Reply Edit 1222 } elseif ( bbp_is_reply_edit() ) { 1223 $new_content = $bbp->shortcodes->display_reply_form(); 1224 1225 /** Views *************************************************************/ 1226 1227 } elseif ( bbp_is_single_view() ) { 1228 $new_content = $bbp->shortcodes->display_view( array( 'id' => get_query_var( 'bbp_view' ) ) ); 1229 1230 /** Topic Tags ********************************************************/ 1231 1232 } elseif ( get_query_var( 'bbp_topic_tag' ) ) { 1233 1234 // Edit topic tag 1235 if ( bbp_is_topic_tag_edit() ) { 1236 $new_content = $bbp->shortcodes->display_topic_tag_form(); 1237 1238 // Show topics of tag 1239 } else { 1240 $new_content = $bbp->shortcodes->display_topics_of_tag( array( 'id' => bbp_get_topic_tag_id() ) ); 1241 } 1242 1243 /** Forums/Topics/Replies *********************************************/ 1244 1241 // Edit 1245 1242 } else { 1246 1247 // Check the post_type 1248 switch ( get_post_type() ) { 1249 1250 // Single Forum 1251 case bbp_get_forum_post_type() : 1252 $new_content = $bbp->shortcodes->display_forum( array( 'id' => get_the_ID() ) ); 1253 break; 1254 1255 // Single Topic 1256 case bbp_get_topic_post_type() : 1257 $new_content = $bbp->shortcodes->display_topic( array( 'id' => get_the_ID() ) ); 1258 break; 1259 1260 // Single Reply 1261 case bbp_get_reply_post_type() : 1262 1263 break; 1264 } 1265 } 1266 1267 // Juggle the content around and try to prevent unsightly comments 1268 if ( !empty( $new_content ) && ( $new_content != $content ) ) { 1269 1270 // Set the content to be the new content 1271 $content = apply_filters( 'bbp_replace_the_content', $new_content, $content ); 1272 1273 // Clean up after ourselves 1274 unset( $new_content ); 1275 1276 /** 1277 * Supplemental hack to prevent stubborn comments_template() output. 1278 * 1279 * By this time we can safely assume that everything we needed from 1280 * the {$post} global has been rendered into the buffer, so we're 1281 * going to empty it and {$withcomments} for good measure. This has 1282 * the added benefit of preventing an incorrect "Edit" link on the 1283 * bottom of most popular page templates, at the cost of rendering 1284 * these globals useless for the remaining page output without using 1285 * wp_reset_postdata() to get that data back. 1286 * 1287 * @see comments_template() For why we're doing this :) 1288 * @see wp_reset_postdata() If you need to get $post back 1289 * 1290 * Note: If a theme uses custom code to output comments, it's 1291 * possible all of this dancing around is for not. 1292 * 1293 * Note: If you need to keep these globals around for any special 1294 * reason, we've provided a failsafe hook to bypass this you 1295 * can put in your plugin or theme below ---v 1296 * 1297 * apply_filters( 'bbp_spill_the_beans', '__return_true' ); 1298 */ 1299 if ( !apply_filters( 'bbp_spill_the_beans', false ) ) { 1300 1301 // Setup the chopping block 1302 global $post, $withcomments; 1303 1304 // Empty out globals that aren't being used in this loop anymore 1305 $withcomments = $post = false; 1306 } 1243 $new_content = $bbp->shortcodes->display_topic_form(); 1244 } 1245 1246 /** Replies ***********************************************************/ 1247 1248 // Reply archive 1249 } elseif ( is_post_type_archive( bbp_get_reply_post_type() ) ) { 1250 //$new_content = $bbp->shortcodes->display_reply_index(); 1251 1252 // Reply Edit 1253 } elseif ( bbp_is_reply_edit() ) { 1254 $new_content = $bbp->shortcodes->display_reply_form(); 1255 1256 /** Views *************************************************************/ 1257 1258 } elseif ( bbp_is_single_view() ) { 1259 $new_content = $bbp->shortcodes->display_view( array( 'id' => get_query_var( 'bbp_view' ) ) ); 1260 1261 /** Topic Tags ********************************************************/ 1262 1263 } elseif ( get_query_var( 'bbp_topic_tag' ) ) { 1264 1265 // Edit topic tag 1266 if ( bbp_is_topic_tag_edit() ) { 1267 $new_content = $bbp->shortcodes->display_topic_tag_form(); 1268 1269 // Show topics of tag 1270 } else { 1271 $new_content = $bbp->shortcodes->display_topics_of_tag( array( 'id' => bbp_get_topic_tag_id() ) ); 1272 } 1273 1274 /** Forums/Topics/Replies *********************************************/ 1275 1276 } else { 1277 1278 // Check the post_type 1279 switch ( get_post_type() ) { 1280 1281 // Single Forum 1282 case bbp_get_forum_post_type() : 1283 $new_content = $bbp->shortcodes->display_forum( array( 'id' => get_the_ID() ) ); 1284 break; 1285 1286 // Single Topic 1287 case bbp_get_topic_post_type() : 1288 $new_content = $bbp->shortcodes->display_topic( array( 'id' => get_the_ID() ) ); 1289 break; 1290 1291 // Single Reply 1292 case bbp_get_reply_post_type() : 1293 1294 break; 1295 } 1296 } 1297 1298 // Juggle the content around and try to prevent unsightly comments 1299 if ( !empty( $new_content ) && ( $new_content != $content ) ) { 1300 1301 // Set the content to be the new content 1302 $content = apply_filters( 'bbp_replace_the_content', $new_content, $content ); 1303 1304 // Clean up after ourselves 1305 unset( $new_content ); 1306 1307 /** 1308 * Supplemental hack to prevent stubborn comments_template() output. 1309 * 1310 * By this time we can safely assume that everything we needed from 1311 * the {$post} global has been rendered into the buffer, so we're 1312 * going to empty it and {$withcomments} for good measure. This has 1313 * the added benefit of preventing an incorrect "Edit" link on the 1314 * bottom of most popular page templates, at the cost of rendering 1315 * these globals useless for the remaining page output without using 1316 * wp_reset_postdata() to get that data back. 1317 * 1318 * @see comments_template() For why we're doing this :) 1319 * @see wp_reset_postdata() If you need to get $post back 1320 * 1321 * Note: If a theme uses custom code to output comments, it's 1322 * possible all of this dancing around is for not. 1323 * 1324 * Note: If you need to keep these globals around for any special 1325 * reason, we've provided a failsafe hook to bypass this you 1326 * can put in your plugin or theme below ---v 1327 * 1328 * apply_filters( 'bbp_spill_the_beans', '__return_true' ); 1329 */ 1330 if ( !apply_filters( 'bbp_spill_the_beans', false ) ) { 1331 1332 // Setup the chopping block 1333 global $post, $withcomments; 1334 1335 // Empty out globals that aren't being used in this loop anymore 1336 $withcomments = $post = false; 1307 1337 } 1308 1338 } -
branches/plugin/bbp-includes/bbp-core-shortcodes.php
r3566 r3623 207 207 * @param string $content 208 208 * @uses bbp_has_forums() 209 * @uses current_theme_supports()210 209 * @uses get_template_part() 211 210 * @return string … … 249 248 * @param string $content 250 249 * @uses bbp_has_topics() 251 * @uses current_theme_supports()252 250 * @uses get_template_part() 253 251 * @uses bbp_single_forum_description() … … 358 356 * @since bbPress (r3566) 359 357 * 360 * @uses current_theme_supports()361 358 * @uses get_template_part() 362 359 */ … … 385 382 * @uses bbp_get_hidden_forum_ids() 386 383 * @uses bbp_has_topics() 387 * @uses current_theme_supports()388 384 * @uses get_template_part() 389 385 * @return string … … 438 434 * @param array $attr 439 435 * @param string $content 440 * @uses current_theme_supports()441 436 * @uses get_template_part() 442 437 * @return string … … 541 536 * @since bbPress (r3031) 542 537 * 543 * @uses current_theme_supports()544 538 * @uses get_template_part() 545 539 */ … … 564 558 * @since bbPress (r3031) 565 559 * 566 * @uses current_theme_supports()567 560 * @uses get_template_part() 568 561 */ … … 617 610 * @param array $attr 618 611 * @param string $content 619 * @uses current_theme_supports()620 612 * @uses get_template_part() 621 613 * @return string … … 678 670 * @param array $attr 679 671 * @param string $content 680 * @uses current_theme_supports()681 672 * @uses get_template_part() 682 673 * @return string … … 720 711 * @param string $content 721 712 * @uses bbp_has_topics() 722 * @uses current_theme_supports()723 713 * @uses get_template_part() 724 714 * @uses bbp_single_forum_description()
Note: See TracChangeset
for help on using the changeset viewer.