Skip to:
Content

bbPress.org

Changeset 3623


Ignore:
Timestamp:
11/20/2011 12:57:43 AM (14 years ago)
Author:
johnjamesjacoby
Message:

First pass at v2 theme compatibility:

  • Remove references to current_theme_supports()
  • Introduce bbp_locate_template() to include theme compat path
  • Use bbp_locate_template() through-out project
  • See #1691
Location:
branches/plugin
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/plugin/bbp-admin/bbp-admin.php

    r3586 r3623  
    389389     *
    390390     * @uses current_user_can() To check notice should be displayed.
    391      * @uses current_theme_supports() To check theme for bbPress support
    392391     */
    393392    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
    412394    }
    413395
  • branches/plugin/bbp-admin/bbp-metaboxes.php

    r3563 r3623  
    209209    <div class="versions">
    210210
    211         <p>
    212             <?php
    213                 if ( current_theme_supports( 'bbpress' ) )
    214                     _e( 'Theme is using <strong>custom bbPress</strong> styling.', 'bbpress' );
    215                 else
    216                     _e( 'Theme is using <strong>default bbPress</strong> styling.', 'bbpress' );
    217             ?>
    218         </p>
    219 
    220211        <span id="wp-version-message">
    221212            <?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  
    6666 * @global bbPress $bbp
    6767 * @param BBP_Theme_Compat $theme
    68  * @uses current_theme_supports()
    6968 */
    7069function bbp_setup_theme_compat( $theme = '' ) {
     
    7271
    7372    // Check if current theme supports bbPress
    74     if ( empty( $bbp->theme_compat->theme ) && !current_theme_supports( 'bbpress' ) ) {
     73    if ( empty( $bbp->theme_compat->theme ) ) {
    7574        if ( empty( $theme ) ) {
    7675            $theme          = new BBP_Theme_Compat();           
     
    9291 *
    9392 * @uses bbp_set_compat_theme_dir() Set the compatable theme to bbp-twentyten
    94  * @uses current_theme_supports() Check bbPress theme support
    9593 * @uses wp_enqueue_style() Enqueue the bbp-twentyten default CSS
    9694 * @uses wp_enqueue_script() Enqueue the bbp-twentyten default topic JS
     
    9896function bbp_theme_compat_enqueue_css() {
    9997
    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' );
    114108    }
    115109}
     
    117111/**
    118112 * Adds bbPress theme support to any active WordPress theme
    119  *
    120  * This function is really cool because it's responsible for managing the
    121  * 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 template
    124  * part using load_template(). If so, it proceeds with using get_template_part()
    125  * as per normal, and no one is the wiser.
    126113 *
    127114 * @since bbPress (r3032)
     
    129116 * @param string $slug
    130117 * @param string $name Optional. Default null
    131  * @uses current_theme_supports()
     118 * @uses bbp_locate_template()
    132119 * @uses load_template()
    133120 * @uses get_template_part()
     
    135122function bbp_get_template_part( $slug, $name = null ) {
    136123
    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 */
     150function 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;
    146183}
    147184
     
    303340function bbp_theme_compat_reset_post( $args = array() ) {
    304341    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' ) );
    309342
    310343    // Default arguments
     
    390423 *
    391424 * @uses bbp_get_displayed_user_id()
     425 * @uses bbp_locate_template()
    392426 * @uses apply_filters()
    393427 *
     
    424458    $templates = bbp_set_theme_compat_templates( $templates );
    425459
    426     $template  = locate_template( $templates, false, false );
     460    $template  = bbp_locate_template( $templates, false, false );
    427461    $template  = bbp_set_theme_compat_template( $template );
    428462
     
    435469 * @since bbPress (r3311)
    436470 *
    437  * @uses $displayed
     471 * @uses bbp_get_displayed_user_id()
     472 * @uses bbp_locate_template()
    438473 * @uses apply_filters()
    439474 *
     
    475510    $templates = bbp_set_theme_compat_templates( $templates );
    476511
    477     $template  = locate_template( $templates, false, false );
     512    $template  = bbp_locate_template( $templates, false, false );
    478513    $template  = bbp_set_theme_compat_template( $template );
    479514
     
    487522 *
    488523 * @uses bbp_get_view_id()
     524 * @uses bbp_locate_template()
    489525 * @uses apply_filters()
    490526 *
     
    520556    $templates = bbp_set_theme_compat_templates( $templates );
    521557
    522     $template  = locate_template( $templates, false, false );
     558    $template  = bbp_locate_template( $templates, false, false );
    523559    $template  = bbp_set_theme_compat_template( $template );
    524560
     
    532568 *
    533569 * @uses bbp_get_topic_post_type()
     570 * @uses bbp_locate_template()
    534571 * @uses apply_filters()
    535572 *
     
    555592    $templates = bbp_set_theme_compat_templates( $templates );
    556593
    557     $template  = locate_template( $templates, false, false );
     594    $template  = bbp_locate_template( $templates, false, false );
    558595    $template  = bbp_set_theme_compat_template( $template );
    559596
     
    567604 *
    568605 * @uses bbp_get_topic_post_type()
     606 * @uses bbp_locate_template()
    569607 * @uses apply_filters()
    570608 *
     
    590628    $templates = bbp_set_theme_compat_templates( $templates );
    591629
    592     $template  = locate_template( $templates, false, false );
     630    $template  = bbp_locate_template( $templates, false, false );
    593631    $template  = bbp_set_theme_compat_template( $template );
    594632
     
    602640 *
    603641 * @uses bbp_get_topic_post_type()
     642 * @uses bbp_locate_template()
    604643 * @uses apply_filters()
    605644 *
     
    620659    $templates = bbp_set_theme_compat_templates( $templates );
    621660
    622     $template  = locate_template( $templates, false, false );
     661    $template  = bbp_locate_template( $templates, false, false );
    623662    $template  = bbp_set_theme_compat_template( $template );
    624663
     
    632671 *
    633672 * @uses bbp_get_topic_post_type()
     673 * @uses bbp_locate_template()
    634674 * @uses apply_filters()
    635675 *
     
    650690    $templates = bbp_set_theme_compat_templates( $templates );
    651691
    652     $template  = locate_template( $templates, false, false );
     692    $template  = bbp_locate_template( $templates, false, false );
    653693    $template  = bbp_set_theme_compat_template( $template );
    654694
     
    662702 *
    663703 * @uses bbp_get_reply_post_type()
     704 * @uses bbp_locate_template()
    664705 * @uses apply_filters()
    665706 *
     
    685726    $templates = bbp_set_theme_compat_templates( $templates );
    686727
    687     $template  = locate_template( $templates, false, false );
     728    $template  = bbp_locate_template( $templates, false, false );
    688729    $template  = bbp_set_theme_compat_template( $template );
    689730
     
    697738 *
    698739 * @uses bbp_get_topic_tag_tax_id()
     740 * @uses bbp_locate_template()
    699741 * @uses apply_filters()
    700742 *
     
    720762    $templates = bbp_set_theme_compat_templates( $templates );
    721763
    722     $template  = locate_template( $templates, false, false );
     764    $template  = bbp_locate_template( $templates, false, false );
    723765    $template  = bbp_set_theme_compat_template( $template );
    724766
     
    732774 *
    733775 * @uses bbp_get_topic_tag_tax_id()
     776 * @uses bbp_locate_template()
    734777 * @uses apply_filters()
    735778 *
     
    764807    $templates = bbp_set_theme_compat_templates( $templates );
    765808
    766     $template  = locate_template( $templates, false, false );
     809    $template  = bbp_locate_template( $templates, false, false );
    767810    $template  = bbp_set_theme_compat_template( $template );
    768811
     
    776819 *
    777820 * @uses apply_filters()
    778  * @uses bbp_set_theme_compat_templates();
     821 * @uses bbp_set_theme_compat_templates()
     822 * @uses bbp_locate_template()
    779823 *
    780824 * @return type
     
    793837    $templates = bbp_set_theme_compat_templates( $templates );
    794838
    795     $template  = locate_template( $templates, false, false );
     839    $template  = bbp_locate_template( $templates, false, false );
    796840    $template  = bbp_set_theme_compat_template( $template );
    797841
     
    812856 * @param string $template
    813857 *
    814  * @uses current_theme_supports() To check if theme supports bbPress
    815858 * @uses bbp_is_single_user() To check if page is single user
    816859 * @uses bbp_get_single_user_template() To get user template
     
    835878function bbp_template_include_theme_supports( $template = '' ) {
    836879
    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;
    874913
    875914    return apply_filters( 'bbp_template_include_theme_supports', $template );
     
    882921 */
    883922function 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();
    10691104    }
    10701105
     
    10861121function bbp_replace_the_content( $content = '' ) {
    10871122
    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
    11121175            ob_start();
    11131176
    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' );
    11151226
    11161227            $new_content = ob_get_contents();
     
    11181229            ob_end_clean();
    11191230
    1120         // Profile Edit
    1121         } elseif ( bbp_is_single_user_edit() ) {
     1231        // Merge
     1232        } elseif ( bbp_is_topic_merge() ) {
    11221233            ob_start();
    11231234
    1124             bbp_get_template_part( 'bbpress/content', 'single-user-edit' );
     1235            bbp_get_template_part( 'bbpress/form', 'topic-merge' );
    11251236
    11261237            $new_content = ob_get_contents();
     
    11281239            ob_end_clean();
    11291240
    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
    12451242        } 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;
    13071337        }
    13081338    }
  • branches/plugin/bbp-includes/bbp-core-shortcodes.php

    r3566 r3623  
    207207     * @param string $content
    208208     * @uses bbp_has_forums()
    209      * @uses current_theme_supports()
    210209     * @uses get_template_part()
    211210     * @return string
     
    249248     * @param string $content
    250249     * @uses bbp_has_topics()
    251      * @uses current_theme_supports()
    252250     * @uses get_template_part()
    253251     * @uses bbp_single_forum_description()
     
    358356     * @since bbPress (r3566)
    359357     *
    360      * @uses current_theme_supports()
    361358     * @uses get_template_part()
    362359     */
     
    385382     * @uses bbp_get_hidden_forum_ids()
    386383     * @uses bbp_has_topics()
    387      * @uses current_theme_supports()
    388384     * @uses get_template_part()
    389385     * @return string
     
    438434     * @param array $attr
    439435     * @param string $content
    440      * @uses current_theme_supports()
    441436     * @uses get_template_part()
    442437     * @return string
     
    541536     * @since bbPress (r3031)
    542537     *
    543      * @uses current_theme_supports()
    544538     * @uses get_template_part()
    545539     */
     
    564558     * @since bbPress (r3031)
    565559     *
    566      * @uses current_theme_supports()
    567560     * @uses get_template_part()
    568561     */
     
    617610     * @param array $attr
    618611     * @param string $content
    619      * @uses current_theme_supports()
    620612     * @uses get_template_part()
    621613     * @return string
     
    678670     * @param array $attr
    679671     * @param string $content
    680      * @uses current_theme_supports()
    681672     * @uses get_template_part()
    682673     * @return string
     
    720711     * @param string $content
    721712     * @uses bbp_has_topics()
    722      * @uses current_theme_supports()
    723713     * @uses get_template_part()
    724714     * @uses bbp_single_forum_description()
Note: See TracChangeset for help on using the changeset viewer.