Skip to:
Content

bbPress.org

Changeset 3629


Ignore:
Timestamp:
11/24/2011 11:30:21 AM (10 years ago)
Author:
johnjamesjacoby
Message:

Introduce bbp_get_query_template() function to handle the template assignment for the extra bbPress root level template files.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/plugin/bbp-includes/bbp-core-compatibility.php

    r3623 r3629  
    9696function bbp_theme_compat_enqueue_css() {
    9797
     98    // Bail if current theme has this under control
     99    if ( current_theme_supports( 'bbpress' ) )
     100        return;
     101
    98102    // Version of CSS
    99103    $version = bbp_get_theme_compat_version();
     
    181185
    182186    return $located;
     187}
     188
     189/**
     190 * Retrieve path to a template
     191 *
     192 * Used to quickly retrieve the path of a template without including the file
     193 * extension. It will also check the parent theme and theme-compat theme with
     194 * the use of {@link bbp_locate_template()}. Allows for more generic template
     195 * locations without the use of the other get_*_template() functions.
     196 *
     197 * @since bbPress (r3629)
     198 *
     199 * @param string $type Filename without extension.
     200 * @param array $templates An optional list of template candidates
     201 * @uses bbp_set_theme_compat_templates()
     202 * @uses bbp_locate_template()
     203 * @uses bbp_set_theme_compat_template()
     204 * @return string Full path to file.
     205 */
     206function bbp_get_query_template( $type, $templates = array() ) {
     207    $type = preg_replace( '|[^a-z0-9-]+|', '', $type );
     208
     209    if ( empty( $templates ) )
     210        $templates = array( "{$type}.php" );
     211
     212    $templates = apply_filters( "bbp_get_{$type}_template", $templates );
     213    $templates = bbp_set_theme_compat_templates( $templates );
     214    $template  = bbp_locate_template( $templates );
     215    $template  = bbp_set_theme_compat_template( $template );
     216
     217    return apply_filters( "bbp_{$type}_template", $template );
    183218}
    184219
     
    410445    $wp_query->is_tax     = $dummy['is_tax'];
    411446   
    412 
    413447    // If we are resetting a post, we are in theme compat
    414448    bbp_set_theme_compat_active();
     
    423457 *
    424458 * @uses bbp_get_displayed_user_id()
    425  * @uses bbp_locate_template()
    426  * @uses apply_filters()
    427  *
    428  * @return array
     459 * @uses bbp_get_query_template()
     460 * @return string Path to template file
    429461 */
    430462function bbp_get_single_user_template() {
     
    455487    );
    456488
    457     $templates = apply_filters( 'bbp_get_profile_template', $templates );
    458     $templates = bbp_set_theme_compat_templates( $templates );
    459 
    460     $template  = bbp_locate_template( $templates, false, false );
    461     $template  = bbp_set_theme_compat_template( $template );
    462 
    463     return $template;
     489    return bbp_get_query_template( 'profile', $templates );
    464490}
    465491
     
    470496 *
    471497 * @uses bbp_get_displayed_user_id()
    472  * @uses bbp_locate_template()
    473  * @uses apply_filters()
    474  *
    475  * @return array
     498 * @uses bbp_get_query_template()
     499 * @return string Path to template file
    476500 */
    477501function bbp_get_single_user_edit_template() {
     
    507531    );
    508532
    509     $templates = apply_filters( 'bbp_get_profile_edit_template', $templates );
    510     $templates = bbp_set_theme_compat_templates( $templates );
    511 
    512     $template  = bbp_locate_template( $templates, false, false );
    513     $template  = bbp_set_theme_compat_template( $template );
    514 
    515     return $template;
     533    return bbp_get_query_template( 'profile_edit', $templates );
    516534}
    517535
     
    522540 *
    523541 * @uses bbp_get_view_id()
    524  * @uses bbp_locate_template()
    525  * @uses apply_filters()
    526  *
    527  * @return array
     542 * @uses bbp_get_query_template()
     543 * @return string Path to template file
    528544 */
    529545function bbp_get_single_view_template() {
     
    553569    );
    554570
    555     $templates = apply_filters( 'bbp_get_single_view_template', $templates );
    556     $templates = bbp_set_theme_compat_templates( $templates );
    557 
    558     $template  = bbp_locate_template( $templates, false, false );
    559     $template  = bbp_set_theme_compat_template( $template );
    560 
    561     return $template;
     571    return bbp_get_query_template( 'single_view', $templates );
    562572}
    563573
     
    568578 *
    569579 * @uses bbp_get_topic_post_type()
    570  * @uses bbp_locate_template()
    571  * @uses apply_filters()
    572  *
    573  * @return array
     580 * @uses bbp_get_query_template()
     581 * @return string Path to template file
    574582 */
    575583function bbp_get_forum_edit_template() {
     
    589597    );
    590598
    591     $templates = apply_filters( 'bbp_get_forum_edit_template', $templates );
    592     $templates = bbp_set_theme_compat_templates( $templates );
    593 
    594     $template  = bbp_locate_template( $templates, false, false );
    595     $template  = bbp_set_theme_compat_template( $template );
    596 
    597     return $template;
     599    return bbp_get_query_template( 'forum_edit', $templates );
    598600}
    599601
     
    604606 *
    605607 * @uses bbp_get_topic_post_type()
    606  * @uses bbp_locate_template()
    607  * @uses apply_filters()
    608  *
    609  * @return array
     608 * @uses bbp_get_query_template()
     609 * @return string Path to template file
    610610 */
    611611function bbp_get_topic_edit_template() {
     
    625625    );
    626626
    627     $templates = apply_filters( 'bbp_get_topic_edit_template', $templates );
    628     $templates = bbp_set_theme_compat_templates( $templates );
    629 
    630     $template  = bbp_locate_template( $templates, false, false );
    631     $template  = bbp_set_theme_compat_template( $template );
    632 
    633     return $template;
     627    return bbp_get_query_template( 'topic_edit', $templates );
    634628}
    635629
     
    640634 *
    641635 * @uses bbp_get_topic_post_type()
    642  * @uses bbp_locate_template()
    643  * @uses apply_filters()
    644  *
    645  * @return array
     636 * @uses bbp_get_query_template()
     637 * @return string Path to template file
    646638 */
    647639function bbp_get_topic_split_template() {
     
    656648    );
    657649
    658     $templates = apply_filters( 'bbp_get_topic_split_template', $templates );
    659     $templates = bbp_set_theme_compat_templates( $templates );
    660 
    661     $template  = bbp_locate_template( $templates, false, false );
    662     $template  = bbp_set_theme_compat_template( $template );
    663 
    664     return $template;
     650    return bbp_get_query_template( 'topic_split', $templates );
    665651}
    666652
     
    671657 *
    672658 * @uses bbp_get_topic_post_type()
    673  * @uses bbp_locate_template()
    674  * @uses apply_filters()
    675  *
    676  * @return array
     659 * @uses bbp_get_query_template()
     660 * @return string Path to template file
    677661 */
    678662function bbp_get_topic_merge_template() {
     
    687671    );
    688672
    689     $templates = apply_filters( 'bbp_get_topic_merge_template', $templates );
    690     $templates = bbp_set_theme_compat_templates( $templates );
    691 
    692     $template  = bbp_locate_template( $templates, false, false );
    693     $template  = bbp_set_theme_compat_template( $template );
    694 
    695     return $template;
     673    return bbp_get_query_template( 'topic_merge', $templates );
    696674}
    697675
     
    702680 *
    703681 * @uses bbp_get_reply_post_type()
    704  * @uses bbp_locate_template()
    705  * @uses apply_filters()
    706  *
    707  * @return array
     682 * @uses bbp_get_query_template()
     683* @return string Path to template file
    708684 */
    709685function bbp_get_reply_edit_template() {
     
    723699    );
    724700
    725     $templates = apply_filters( 'bbp_get_reply_edit_template', $templates );
    726     $templates = bbp_set_theme_compat_templates( $templates );
    727 
    728     $template  = bbp_locate_template( $templates, false, false );
    729     $template  = bbp_set_theme_compat_template( $template );
    730 
    731     return $template;
     701    return bbp_get_query_template( 'reply_edit', $templates );
    732702}
    733703
     
    738708 *
    739709 * @uses bbp_get_topic_tag_tax_id()
    740  * @uses bbp_locate_template()
    741  * @uses apply_filters()
    742  *
    743  * @return array
     710 * @uses bbp_get_query_template()
     711 * @return string Path to template file
    744712 */
    745713function bbp_get_topic_tag_template() {
     
    759727    );
    760728
    761     $templates = apply_filters( 'bbp_get_topic_tag_template', $templates );
    762     $templates = bbp_set_theme_compat_templates( $templates );
    763 
    764     $template  = bbp_locate_template( $templates, false, false );
    765     $template  = bbp_set_theme_compat_template( $template );
    766 
    767     return $template;
     729    return bbp_get_query_template( 'topic_tag', $templates );
    768730}
    769731
     
    774736 *
    775737 * @uses bbp_get_topic_tag_tax_id()
    776  * @uses bbp_locate_template()
    777  * @uses apply_filters()
    778  *
    779  * @return array
     738 * @uses bbp_get_query_template()
     739 * @return string Path to template file
    780740 */
    781741function bbp_get_topic_tag_edit_template() {
     
    804764    );
    805765
    806     $templates = apply_filters( 'bbp_get_topic_tag_edit_template', $templates );
    807     $templates = bbp_set_theme_compat_templates( $templates );
    808 
    809     $template  = bbp_locate_template( $templates, false, false );
    810     $template  = bbp_set_theme_compat_template( $template );
    811 
    812     return $template;
     766    return bbp_get_query_template( 'topic_tag_edit', $templates );
    813767}
    814768
     
    820774 * @uses apply_filters()
    821775 * @uses bbp_set_theme_compat_templates()
    822  * @uses bbp_locate_template()
    823  *
    824  * @return type
     776 * @uses bbp_get_query_template()
     777 * @return string Path to template file
    825778 */
    826779function bbp_get_theme_compat_templates() {
     
    834787    );
    835788
    836     $templates = apply_filters( 'bbp_get_theme_compat_templates', $templates );
    837     $templates = bbp_set_theme_compat_templates( $templates );
    838 
    839     $template  = bbp_locate_template( $templates, false, false );
    840     $template  = bbp_set_theme_compat_template( $template );
    841 
    842     return $template;
     789    return bbp_get_query_template( 'bbpress', $templates );
    843790}
    844791
     
    10871034     * correct results.
    10881035     *
    1089      * We default to using page.php, since it's most likely to exist and
     1036     * Use bbp_get_theme_compat_templates() to provide a fall-back that
    10901037     * should be coded to work without superfluous elements and logic, like
    10911038     * prev/next navigation, comments, date/time, etc... You can hook into
Note: See TracChangeset for help on using the changeset viewer.