Skip to:
Content

bbPress.org


Ignore:
Timestamp:
06/15/2017 04:31:59 AM (9 years ago)
Author:
johnjamesjacoby
Message:

Theme Compat: Improve loading & support for external template packs.

  • Better error handling if tempate pack is broken, unloaded, or missing
  • Consolidate favs & subs code to use the same central handlers, by passing an object_id and object_type around (for future support of term subscriptions)
  • Rename data addtributes from previous BuddyPress favs & subs fixes
  • Adjust load order of template pack setup so that it's as late as possible, allowing template pack authors more time to get registered
  • Automatically add the current template pack to the template stack (multiple packs can still be layered, and this improves support for that)
  • Merge topic.js and forum.js in "bbPress Default" template pack to use the same engagements.js script, which simplifies localization & uses 1 less script between pages

This change puts the finishing touches on favs & subs consolidation for 2.6, and updates several related & surrounding functions to better support the necessary mark-up changes.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/includes/core/theme-compat.php

    r6501 r6551  
    2929 *
    3030 * This is only intended to be extended, and is included here as a basic guide
    31  * for future Theme Packs to use. @link BBP_Twenty_Ten is a good example of
    32  * extending this class, as is @link bbp_setup_theme_compat()
     31 * for future Template Packs to use. @link bbp_setup_theme_compat()
    3332 *
    3433 * @since 2.0.0 bbPress (r3506)
     
    8887                        : '';
    8988        }
     89
     90        /**
     91         * Return the template directory.
     92         *
     93         * @since 2.6.0 bbPress (r6548)
     94         *
     95         * @return string
     96         */
     97        public function get_dir() {
     98                return $this->dir;
     99        }
    90100}
    91101
     
    93103
    94104/**
    95  * Setup the default theme compat theme
     105 * Setup the active template pack and register it's directory in the stack.
    96106 *
    97107 * @since 2.0.0 bbPress (r3311)
     
    99109 * @param BBP_Theme_Compat $theme
    100110 */
    101 function bbp_setup_theme_compat( $theme = '' ) {
     111function bbp_setup_theme_compat( $theme = 'default' ) {
    102112        $bbp = bbpress();
    103113
    104         // Make sure theme package is available, set to default if not
    105         if ( ! isset( $bbp->theme_compat->packages[ $theme ] ) || ! is_a( $bbp->theme_compat->packages[ $theme ], 'BBP_Theme_Compat' ) ) {
     114        // Bail if something already has this under control
     115        if ( ! empty( $bbp->theme_compat->theme ) ) {
     116                return;
     117        }
     118
     119        // Fallback for empty theme
     120        if ( empty( $theme ) ) {
    106121                $theme = 'default';
    107122        }
    108123
    109         // Try to set the active theme compat theme. If it's not in the registered
    110         // packages array, it doesn't exist, so do nothing with it.
     124        // If the theme is registered, use it and add it to the stack
    111125        if ( isset( $bbp->theme_compat->packages[ $theme ] ) ) {
    112126                $bbp->theme_compat->theme = $bbp->theme_compat->packages[ $theme ];
    113         }
     127
     128                // Setup the template stack for the active template pack
     129                bbp_register_template_stack( array( $bbp->theme_compat->theme, 'get_dir' ) );
     130        }
     131}
     132
     133/**
     134 * Get the current template pack package.
     135 *
     136 * @since 2.6.0 bbPress (r6548)
     137 *
     138 * @return BBP_Theme_Compat
     139 */
     140function bbp_get_current_template_pack() {
     141        $bbp = bbpress();
     142
     143        // Theme was not setup, so fallback to an empty object
     144        if ( empty( $bbp->theme_compat->theme ) ) {
     145                $bbp->theme_compat->theme = new BBP_Theme_Compat();
     146        }
     147
     148        // Filter & return
     149        return apply_filters( 'bbp_get_current_template_pack', $bbp->theme_compat->theme );
     150}
     151
     152/**
     153 * Gets the id of the bbPress compatible theme used, in the event the
     154 * currently active WordPress theme does not explicitly support bbPress.
     155 * This can be filtered or set manually. Tricky theme authors can override the
     156 * default and include their own bbPress compatibility layers for their themes.
     157 *
     158 * @since 2.0.0 bbPress (r3506)
     159 *
     160 * @uses apply_filters()
     161 * @return string
     162 */
     163function bbp_get_theme_compat_id() {
     164
     165        // Filter & return
     166        return apply_filters( 'bbp_get_theme_compat_id', bbp_get_current_template_pack()->id );
    114167}
    115168
     
    125178 * @return string
    126179 */
    127 function bbp_get_theme_compat_id() {
     180function bbp_get_theme_compat_name() {
    128181
    129182        // Filter & return
    130         return apply_filters( 'bbp_get_theme_compat_id', bbpress()->theme_compat->theme->id );
    131 }
    132 
    133 /**
    134  * Gets the name of the bbPress compatible theme used, in the event the
    135  * currently active WordPress theme does not explicitly support bbPress.
    136  * This can be filtered or set manually. Tricky theme authors can override the
    137  * default and include their own bbPress compatibility layers for their themes.
    138  *
    139  * @since 2.0.0 bbPress (r3506)
    140  *
    141  * @uses apply_filters()
    142  * @return string
    143  */
    144 function bbp_get_theme_compat_name() {
    145 
    146         // Filter & return
    147         return apply_filters( 'bbp_get_theme_compat_name', bbpress()->theme_compat->theme->name );
     183        return apply_filters( 'bbp_get_theme_compat_name', bbp_get_current_template_pack()->name );
    148184}
    149185
     
    162198
    163199        // Filter & return
    164         return apply_filters( 'bbp_get_theme_compat_version', bbpress()->theme_compat->theme->version );
     200        return apply_filters( 'bbp_get_theme_compat_version', bbp_get_current_template_pack()->version );
    165201}
    166202
     
    179215
    180216        // Filter & return
    181         return apply_filters( 'bbp_get_theme_compat_dir', bbpress()->theme_compat->theme->dir );
     217        return apply_filters( 'bbp_get_theme_compat_dir', bbp_get_current_template_pack()->dir );
    182218}
    183219
     
    196232
    197233        // Filter & return
    198         return apply_filters( 'bbp_get_theme_compat_url', bbpress()->theme_compat->theme->url );
     234        return apply_filters( 'bbp_get_theme_compat_url', bbp_get_current_template_pack()->url );
    199235}
    200236
     
    273309
    274310/**
    275  * Set the theme compat original_template global
     311 * Is a template the original_template global
    276312 *
    277313 * Stash the original template file for the current query. Useful for checking
     
    283319        $bbp = bbpress();
    284320
     321        // Bail if no original template
    285322        if ( empty( $bbp->theme_compat->original_template ) ) {
    286323                return false;
     
    317354        }
    318355}
     356
    319357/**
    320358 * This fun little function fills up some WordPress globals with dummy data to
Note: See TracChangeset for help on using the changeset viewer.