Skip to:
Content

bbPress.org

Changeset 3971


Ignore:
Timestamp:
06/17/2012 02:25:31 PM (10 years ago)
Author:
johnjamesjacoby
Message:

Theme Compatibility:

  • Allow root level templates to bypass the_content overriding if child/parent templates are found.
  • Introduces two functions and new theme_compat functionality, that modifies bbp_get_query_template() to tell bbp_locate_template() to not override the_content.
  • Reverts r3969.
  • Fixes #1854 correctly.
Location:
branches/plugin/bbp-includes
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/plugin/bbp-includes/bbp-template-functions.php

    r3968 r3971  
    7777        if ( file_exists( trailingslashit( STYLESHEETPATH ) . $template_name ) ) {
    7878            $located = trailingslashit( STYLESHEETPATH ) . $template_name;
     79            bbp_set_the_content_override( false );
    7980            break;
    8081
     
    8283        } elseif ( file_exists( trailingslashit( TEMPLATEPATH ) . $template_name ) ) {
    8384            $located = trailingslashit( TEMPLATEPATH ) . $template_name;
     85            bbp_set_the_content_override( false );
    8486            break;
    8587
     
    8789        } elseif ( file_exists( trailingslashit( bbp_get_theme_compat_dir() ) . $template_name ) ) {
    8890            $located = trailingslashit( bbp_get_theme_compat_dir() ) . $template_name;
     91            bbp_set_the_content_override( true );
    8992            break;
    9093        }
     
    120123        $templates = array( "{$type}.php" );
    121124
     125    // Set query_template to true to tell bbp_locate_template() we are trying
     126    // to determine if 'the_content' should be overridden or not.
     127    bbpress()->theme_compat->query_template = true;
     128
     129    // Filter possible templates, try to match one, and set any bbPress theme
     130    // compat properties so they can be cross-checked later.
    122131    $templates = apply_filters( "bbp_get_{$type}_template", $templates );
    123132    $templates = bbp_set_theme_compat_templates( $templates );
    124133    $template  = bbp_locate_template( $templates );
    125134    $template  = bbp_set_theme_compat_template( $template );
     135
     136    // Set query_template back to false, since we are done querying for main
     137    // template files.
     138    bbpress()->theme_compat->query_template = false;
    126139
    127140    return apply_filters( "bbp_{$type}_template", $template );
  • branches/plugin/bbp-includes/bbp-theme-compatibility.php

    r3970 r3971  
    285285        $bbp->theme_compat->packages[$theme->id] = $theme;
    286286    }
     287}
     288
     289/**
     290 * This is called from inside bbp_locate_template(). It sets whether or not
     291 * bbPress should override 'the_content' or if a root-level template was found
     292 * in either the current child or parent themes.
     293 *
     294 * @since bbPress (r3970)
     295 *
     296 * @param boolean $override
     297 * @return boolean
     298 */
     299function bbp_set_the_content_override( $override = false ) {
     300    $bbp = bbpress();
     301
     302    if ( empty( $bbp->theme_compat->query_template ) )
     303        return false;
     304
     305    $bbp->theme_compat->replace_the_content = $override;
     306
     307    return (bool) $bbp->theme_compat->replace_the_content;
     308}
     309
     310/**
     311 * Should bbPress try to replace 'the_content' because a template file could
     312 * not be found in either the child or parent themes.
     313 *
     314 * @since bbPress (r3970)
     315 *
     316 * @return boolean
     317 */
     318function bbp_is_the_content_override() {
     319    $bbp = bbpress();
     320
     321    if ( empty( $bbp->theme_compat->replace_the_content ) )
     322        return false;
     323
     324    return (bool) $bbp->theme_compat->replace_the_content;
    287325}
    288326
     
    402440    // includes archive-* and single-* WordPress post_type matches, allowing
    403441    // themes to use the expected format.
    404     if ( ! bbp_is_theme_compat_original_template( $template ) )
     442    if ( bbp_is_theme_compat_original_template( $template ) )
     443        return $template;
     444
     445    // If we know we are not going to override the_content with a bbPress
     446    // template part, bail early so we don't reset queries and hook filters in.
     447    if ( ! bbp_is_the_content_override() )
    405448        return $template;
    406449
Note: See TracChangeset for help on using the changeset viewer.