[ Index ]

PHP Cross Reference of BBPress

title

Body

[close]

/src/includes/core/ -> template-loader.php (source)

   1  <?php
   2  
   3  /**
   4   * bbPress Template Loader
   5   *
   6   * @package bbPress
   7   * @subpackage TemplateLoader
   8   */
   9  
  10  // Exit if accessed directly
  11  defined( 'ABSPATH' ) || exit;
  12  
  13  /**
  14   * Possibly intercept the template being loaded
  15   *
  16   * Listens to the 'template_include' filter and waits for any bbPress specific
  17   * template condition to be met. If one is met and the template file exists,
  18   * it will be used; otherwise
  19   *
  20   * Note that the _edit() checks are ahead of their counterparts, to prevent them
  21   * from being stomped on accident.
  22   *
  23   * @since 2.0.0 bbPress (r3032)
  24   *
  25   * @param string $template
  26   *
  27   * @return string The path to the template file that is being used
  28   */
  29  function bbp_template_include_theme_supports( $template = '' ) {
  30  
  31      // Editing a user
  32      if     ( bbp_is_single_user_edit() && ( $new_template = bbp_get_single_user_edit_template() ) ) :
  33  
  34      // User favorites
  35      elseif ( bbp_is_favorites()        && ( $new_template = bbp_get_favorites_template()        ) ) :
  36  
  37      // User favorites
  38      elseif ( bbp_is_subscriptions()    && ( $new_template = bbp_get_subscriptions_template()    ) ) :
  39  
  40      // Viewing a user
  41      elseif ( bbp_is_single_user()      && ( $new_template = bbp_get_single_user_template()      ) ) :
  42  
  43      // Single View
  44      elseif ( bbp_is_single_view()      && ( $new_template = bbp_get_single_view_template()      ) ) :
  45  
  46      // Search
  47      elseif ( bbp_is_search()           && ( $new_template = bbp_get_search_template()           ) ) :
  48  
  49      // Forum edit
  50      elseif ( bbp_is_forum_edit()       && ( $new_template = bbp_get_forum_edit_template()       ) ) :
  51  
  52      // Single Forum
  53      elseif ( bbp_is_single_forum()     && ( $new_template = bbp_get_single_forum_template()     ) ) :
  54  
  55      // Forum Archive
  56      elseif ( bbp_is_forum_archive()    && ( $new_template = bbp_get_forum_archive_template()    ) ) :
  57  
  58      // Topic merge
  59      elseif ( bbp_is_topic_merge()      && ( $new_template = bbp_get_topic_merge_template()      ) ) :
  60  
  61      // Topic split
  62      elseif ( bbp_is_topic_split()      && ( $new_template = bbp_get_topic_split_template()      ) ) :
  63  
  64      // Topic edit
  65      elseif ( bbp_is_topic_edit()       && ( $new_template = bbp_get_topic_edit_template()       ) ) :
  66  
  67      // Single Topic
  68      elseif ( bbp_is_single_topic()     && ( $new_template = bbp_get_single_topic_template()     ) ) :
  69  
  70      // Topic Archive
  71      elseif ( bbp_is_topic_archive()    && ( $new_template = bbp_get_topic_archive_template()    ) ) :
  72  
  73      // Reply move
  74      elseif ( bbp_is_reply_move()       && ( $new_template = bbp_get_reply_move_template()       ) ) :
  75  
  76      // Editing a reply
  77      elseif ( bbp_is_reply_edit()       && ( $new_template = bbp_get_reply_edit_template()       ) ) :
  78  
  79      // Single Reply
  80      elseif ( bbp_is_single_reply()     && ( $new_template = bbp_get_single_reply_template()     ) ) :
  81  
  82      // Editing a topic tag
  83      elseif ( bbp_is_topic_tag_edit()   && ( $new_template = bbp_get_topic_tag_edit_template()   ) ) :
  84  
  85      // Viewing a topic tag
  86      elseif ( bbp_is_topic_tag()        && ( $new_template = bbp_get_topic_tag_template()        ) ) :
  87      endif;
  88  
  89      // A bbPress template file was located, so override the WordPress template
  90      // and use it to switch off theme compatibility.
  91      if ( ! empty( $new_template ) ) {
  92          $template = bbp_set_template_included( $new_template );
  93      }
  94  
  95      // Filter & return
  96      return apply_filters( 'bbp_template_include_theme_supports', $template );
  97  }
  98  
  99  /**
 100   * Set the included template
 101   *
 102   * @since 2.4.0 bbPress (r4975)
 103   *
 104   * @param mixed $template Default false
 105   * @return mixed False if empty. Template name if template included
 106   */
 107  function bbp_set_template_included( $template = false ) {
 108      bbpress()->theme_compat->bbpress_template = $template;
 109  
 110      return bbpress()->theme_compat->bbpress_template;
 111  }
 112  
 113  /**
 114   * Is a bbPress template being included?
 115   *
 116   * @since 2.4.0 bbPress (r4975)
 117   *
 118   * @return bool True if yes, false if no
 119   */
 120  function bbp_is_template_included() {
 121      return ! empty( bbpress()->theme_compat->bbpress_template );
 122  }
 123  
 124  /** Custom Functions **********************************************************/
 125  
 126  /**
 127   * Attempt to load a custom bbPress functions file, similar to each themes
 128   * functions.php file.
 129   *
 130   * @since 2.1.0 bbPress (r3732)
 131   *
 132   * @global string $pagenow
 133   */
 134  function bbp_load_theme_functions() {
 135      global $pagenow;
 136  
 137      // If bbPress is being deactivated, do not load any more files
 138      if ( bbp_is_deactivation() ) {
 139          return;
 140      }
 141  
 142      if ( ! defined( 'WP_INSTALLING' ) || ( ! empty( $pagenow ) && ( 'wp-activate.php' !== $pagenow ) ) ) {
 143          bbp_locate_template( 'bbpress-functions.php', true );
 144      }
 145  }
 146  
 147  /** Individual Templates ******************************************************/
 148  
 149  /**
 150   * Get the user profile template
 151   *
 152   * @since 2.0.0 bbPress (r3311)
 153   *
 154   * @return string Path to template file
 155   */
 156  function bbp_get_single_user_template() {
 157      $nicename  = bbp_get_displayed_user_field( 'user_nicename' );
 158      $user_id   = bbp_get_displayed_user_id();
 159      $templates = array(
 160          'single-user-' . $nicename . '.php', // Single User nicename
 161          'single-user-' . $user_id  . '.php', // Single User ID
 162          'single-user.php',                   // Single User
 163          'user.php',                          // User
 164      );
 165      return bbp_get_query_template( 'profile', $templates );
 166  }
 167  
 168  /**
 169   * Get the user profile edit template
 170   *
 171   * @since 2.0.0 bbPress (r3311)
 172   *
 173   * @return string Path to template file
 174   */
 175  function bbp_get_single_user_edit_template() {
 176      $nicename  = bbp_get_displayed_user_field( 'user_nicename' );
 177      $user_id   = bbp_get_displayed_user_id();
 178      $templates = array(
 179          'single-user-edit-' . $nicename . '.php', // Single User Edit nicename
 180          'single-user-edit-' . $user_id  . '.php', // Single User Edit ID
 181          'single-user-edit.php',                   // Single User Edit
 182          'user-edit.php',                          // User Edit
 183          'user.php',                               // User
 184      );
 185      return bbp_get_query_template( 'profile_edit', $templates );
 186  }
 187  
 188  /**
 189   * Get the user favorites template
 190   *
 191   * @since 2.2.0 bbPress (r4225)
 192   *
 193   * @return string Path to template file
 194   */
 195  function bbp_get_favorites_template() {
 196      $nicename  = bbp_get_displayed_user_field( 'user_nicename' );
 197      $user_id   = bbp_get_displayed_user_id();
 198      $templates = array(
 199          'single-user-favorites-' . $nicename . '.php', // Single User Favs nicename
 200          'single-user-favorites-' . $user_id  . '.php', // Single User Favs ID
 201          'favorites-' . $nicename  . '.php',            // Favorites nicename
 202          'favorites-' . $user_id   . '.php',            // Favorites ID
 203          'favorites.php',                               // Favorites
 204          'user.php',                                    // User
 205      );
 206      return bbp_get_query_template( 'favorites', $templates );
 207  }
 208  
 209  /**
 210   * Get the user subscriptions template
 211   *
 212   * @since 2.2.0 bbPress (r4225)
 213   *
 214   * @return string Path to template file
 215   */
 216  function bbp_get_subscriptions_template() {
 217      $nicename  = bbp_get_displayed_user_field( 'user_nicename' );
 218      $user_id   = bbp_get_displayed_user_id();
 219      $templates = array(
 220          'single-user-subscriptions-' . $nicename . '.php', // Single User Subs nicename
 221          'single-user-subscriptions-' . $user_id  . '.php', // Single User Subs ID
 222          'subscriptions-' . $nicename  . '.php',            // Subscriptions nicename
 223          'subscriptions-' . $user_id   . '.php',            // Subscriptions ID
 224          'subscriptions.php',                               // Subscriptions
 225          'user.php',                                        // User
 226      );
 227      return bbp_get_query_template( 'subscriptions', $templates );
 228  }
 229  
 230  /**
 231   * Get the view template
 232   *
 233   * @since 2.0.0 bbPress (r3311)
 234   *
 235   * @return string Path to template file
 236   */
 237  function bbp_get_single_view_template() {
 238      $view_id   = bbp_get_view_id();
 239      $templates = array(
 240          'single-view-' . $view_id . '.php', // Single View ID
 241          'view-'        . $view_id . '.php', // View ID
 242          'single-view.php',                  // Single View
 243          'view.php',                         // View
 244      );
 245      return bbp_get_query_template( 'single_view', $templates );
 246  }
 247  
 248  /**
 249   * Get the search template
 250   *
 251   * @since 2.3.0 bbPress (r4579)
 252   *
 253   * @return string Path to template file
 254   */
 255  function bbp_get_search_template() {
 256      $templates = array(
 257          'page-forum-search.php', // Single Search
 258          'forum-search.php',      // Search
 259      );
 260      return bbp_get_query_template( 'single_search', $templates );
 261  }
 262  
 263  /**
 264   * Get the single forum template
 265   *
 266   * @since 2.1.0 bbPress (r3922)
 267   *
 268   * @return string Path to template file
 269   */
 270  function bbp_get_single_forum_template() {
 271      $templates = array(
 272          'single-' . bbp_get_forum_post_type() . '.php' // Single Forum
 273      );
 274      return bbp_get_query_template( 'single_forum', $templates );
 275  }
 276  
 277  /**
 278   * Get the forum archive template
 279   *
 280   * @since 2.1.0 bbPress (r3922)
 281   *
 282   * @return string Path to template file
 283   */
 284  function bbp_get_forum_archive_template() {
 285      $templates = array(
 286          'archive-' . bbp_get_forum_post_type() . '.php' // Forum Archive
 287      );
 288      return bbp_get_query_template( 'forum_archive', $templates );
 289  }
 290  
 291  /**
 292   * Get the forum edit template
 293   *
 294   * @since 2.1.0 bbPress (r3566)
 295   *
 296   * @return string Path to template file
 297   */
 298  function bbp_get_forum_edit_template() {
 299      $templates = array(
 300          'single-' . bbp_get_forum_post_type() . '-edit.php' // Single Forum Edit
 301      );
 302      return bbp_get_query_template( 'forum_edit', $templates );
 303  }
 304  
 305  /**
 306   * Get the single topic template
 307   *
 308   * @since 2.1.0 bbPress (r3922)
 309   *
 310   * @return string Path to template file
 311   */
 312  function bbp_get_single_topic_template() {
 313      $templates = array(
 314          'single-' . bbp_get_topic_post_type() . '.php'
 315      );
 316      return bbp_get_query_template( 'single_topic', $templates );
 317  }
 318  
 319  /**
 320   * Get the topic archive template
 321   *
 322   * @since 2.1.0 bbPress (r3922)
 323   *
 324   * @return string Path to template file
 325   */
 326  function bbp_get_topic_archive_template() {
 327      $templates = array(
 328          'archive-' . bbp_get_topic_post_type() . '.php' // Topic Archive
 329      );
 330      return bbp_get_query_template( 'topic_archive', $templates );
 331  }
 332  
 333  /**
 334   * Get the topic edit template
 335   *
 336   * @since 2.0.0 bbPress (r3311)
 337   *
 338   * @return string Path to template file
 339   */
 340  function bbp_get_topic_edit_template() {
 341      $templates = array(
 342          'single-' . bbp_get_topic_post_type() . '-edit.php' // Single Topic Edit
 343      );
 344      return bbp_get_query_template( 'topic_edit', $templates );
 345  }
 346  
 347  /**
 348   * Get the topic split template
 349   *
 350   * @since 2.0.0 bbPress (r3311)
 351   *
 352   * @return string Path to template file
 353   */
 354  function bbp_get_topic_split_template() {
 355      $templates = array(
 356          'single-' . bbp_get_topic_post_type() . '-split.php', // Topic Split
 357      );
 358      return bbp_get_query_template( 'topic_split', $templates );
 359  }
 360  
 361  /**
 362   * Get the topic merge template
 363   *
 364   * @since 2.0.0 bbPress (r3311)
 365   *
 366   * @return string Path to template file
 367   */
 368  function bbp_get_topic_merge_template() {
 369      $templates = array(
 370          'single-' . bbp_get_topic_post_type() . '-merge.php', // Topic Merge
 371      );
 372      return bbp_get_query_template( 'topic_merge', $templates );
 373  }
 374  
 375  /**
 376   * Get the single reply template
 377   *
 378   * @since 2.1.0 bbPress (r3922)
 379   *
 380   * @return string Path to template file
 381   */
 382  function bbp_get_single_reply_template() {
 383      $templates = array(
 384          'single-' . bbp_get_reply_post_type() . '.php'
 385      );
 386      return bbp_get_query_template( 'single_reply', $templates );
 387  }
 388  
 389  /**
 390   * Get the reply edit template
 391   *
 392   * @since 2.0.0 bbPress (r3311)
 393   *
 394  * @return string Path to template file
 395   */
 396  function bbp_get_reply_edit_template() {
 397      $templates = array(
 398          'single-' . bbp_get_reply_post_type() . '-edit.php' // Single Reply Edit
 399      );
 400      return bbp_get_query_template( 'reply_edit', $templates );
 401  }
 402  
 403  /**
 404   * Get the reply move template
 405   *
 406   * @since 2.3.0 bbPress (r4521)
 407   *
 408   * @return string Path to template file
 409   */
 410  function bbp_get_reply_move_template() {
 411      $templates = array(
 412          'single-' . bbp_get_reply_post_type() . '-move.php', // Reply move
 413      );
 414      return bbp_get_query_template( 'reply_move', $templates );
 415  }
 416  
 417  /**
 418   * Get the topic template
 419   *
 420   * @since 2.0.0 bbPress (r3311)
 421   *
 422   * @return string Path to template file
 423   */
 424  function bbp_get_topic_tag_template() {
 425      $tt_slug   = bbp_get_topic_tag_slug();
 426      $tt_id     = bbp_get_topic_tag_tax_id();
 427      $templates = array(
 428          'taxonomy-' . $tt_slug . '.php', // Single Topic Tag slug
 429          'taxonomy-' . $tt_id   . '.php', // Single Topic Tag ID
 430      );
 431      return bbp_get_query_template( 'topic_tag', $templates );
 432  }
 433  
 434  /**
 435   * Get the topic edit template
 436   *
 437   * @since 2.0.0 bbPress (r3311)
 438   *
 439   * @return string Path to template file
 440   */
 441  function bbp_get_topic_tag_edit_template() {
 442      $tt_slug   = bbp_get_topic_tag_slug();
 443      $tt_id     = bbp_get_topic_tag_tax_id();
 444      $templates = array(
 445          'taxonomy-' . $tt_slug . '-edit.php', // Single Topic Tag Edit slug
 446          'taxonomy-' . $tt_id   . '-edit.php'  // Single Topic Tag Edit ID
 447      );
 448      return bbp_get_query_template( 'topic_tag_edit', $templates );
 449  }
 450  
 451  /**
 452   * Get the templates to use as the endpoint for bbPress template parts
 453   *
 454   * @since 2.0.0 bbPress (r3311)
 455   * @since 2.6.0 bbPress (r5950) Added `singular.php` to template stack
 456   *
 457   * @return string Path to template file
 458   */
 459  function bbp_get_theme_compat_templates() {
 460      $templates = array(
 461          'plugin-bbpress.php',
 462          'bbpress.php',
 463          'forums.php',
 464          'forum.php',
 465          'generic.php',
 466          'page.php',
 467          'single.php',
 468          'singular.php',
 469          'index.php'
 470      );
 471      return bbp_get_query_template( 'bbpress', $templates );
 472  }


Generated: Wed Oct 23 01:01:36 2019 Cross-referenced by PHPXref 0.7.1