[ Index ]

PHP Cross Reference of BBPress

title

Body

[close]

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

   1  <?php
   2  
   3  /**
   4   * bbPress Template Functions
   5   *
   6   * This file contains functions necessary to mirror the WordPress core template
   7   * loading process. Many of those functions are not filterable, and even then
   8   * would not be robust enough to predict where bbPress templates might exist.
   9   *
  10   * @package bbPress
  11   * @subpackage TemplateFunctions
  12   */
  13  
  14  // Exit if accessed directly
  15  defined( 'ABSPATH' ) || exit;
  16  
  17  /**
  18   * Adds bbPress theme support to any active WordPress theme
  19   *
  20   * @since 2.0.0 bbPress (r3032)
  21   *
  22   * @param string $slug
  23   * @param string $name Optional. Default null
  24   */
  25  function bbp_get_template_part( $slug, $name = null ) {
  26  
  27      // Execute code for this part
  28      do_action( 'get_template_part_' . $slug, $slug, $name );
  29  
  30      // Setup possible parts
  31      $templates = array();
  32      if ( isset( $name ) ) {
  33          $templates[] = $slug . '-' . $name . '.php';
  34      }
  35      $templates[] = $slug . '.php';
  36  
  37      // Allow template parst to be filtered
  38      $templates = apply_filters( 'bbp_get_template_part', $templates, $slug, $name );
  39  
  40      // Return the part that is found
  41      return bbp_locate_template( $templates, true, false );
  42  }
  43  
  44  /**
  45   * Retrieve the name of the highest priority template file that exists.
  46   *
  47   * Searches in the child theme before parent theme so that themes which
  48   * inherit from a parent theme can just overload one file. If the template is
  49   * not found in either of those, it looks in the theme-compat folder last.
  50   *
  51   * @since 2.1.0 bbPress (r3618)
  52   *
  53   * @param string|array $template_names Template file(s) to search for, in order.
  54   * @param bool $load If true the template file will be loaded if it is found.
  55   * @param bool $require_once Whether to require_once or require. Default true.
  56   *                            Has no effect if $load is false.
  57   * @return string The template filename if one is located.
  58   */
  59  function bbp_locate_template( $template_names, $load = false, $require_once = true ) {
  60  
  61      // No file found yet
  62      $located            = false;
  63      $template_locations = bbp_get_template_stack();
  64  
  65      // Try to find a template file
  66      foreach ( (array) $template_names as $template_name ) {
  67  
  68          // Continue if template is empty
  69          if ( empty( $template_name ) ) {
  70              continue;
  71          }
  72  
  73          // Trim off any slashes from the template name
  74          $template_name  = ltrim( $template_name, '/' );
  75  
  76          // Loop through template stack
  77          foreach ( (array) $template_locations as $template_location ) {
  78  
  79              // Continue if $template_location is empty
  80              if ( empty( $template_location ) ) {
  81                  continue;
  82              }
  83  
  84              // Check child theme first
  85              if ( file_exists( trailingslashit( $template_location ) . $template_name ) ) {
  86                  $located = trailingslashit( $template_location ) . $template_name;
  87                  break 2;
  88              }
  89          }
  90      }
  91  
  92      /**
  93       * This action exists only to follow the standard bbPress coding convention,
  94       * and should not be used to short-circuit any part of the template locator.
  95       *
  96       * If you want to override a specific template part, please either filter
  97       * 'bbp_get_template_part' or add a new location to the template stack.
  98       */
  99      do_action( 'bbp_locate_template', $located, $template_name, $template_names, $template_locations, $load, $require_once );
 100  
 101      // Maybe load the template if one was located
 102      if ( ( defined( 'WP_USE_THEMES' ) && WP_USE_THEMES ) && ( true === $load ) && ! empty( $located ) ) {
 103          load_template( $located, $require_once );
 104      }
 105  
 106      return $located;
 107  }
 108  
 109  /**
 110   * Locate an enqueueable file on the server. Used before being enqueued.
 111   *
 112   * If SCRIPT_DEBUG is set and the file includes a .min suffix, this function
 113   * will automatically attempt to locate a non-minified version of that file.
 114   *
 115   * If SCRIPT_DEBUG is not set and the file exclude a .min suffix, this function
 116   * will automatically attempt to locate a minified version of that file.
 117   *
 118   * See: https://bbpress.trac.wordpress.org/ticket/3218
 119   *
 120   * @since 2.6.0
 121   *
 122   * @param string $file
 123   *
 124   * @return boolean
 125   */
 126  function bbp_locate_enqueueable( $file = '' ) {
 127  
 128      // Bail if no file to locate
 129      if ( empty( $file ) ) {
 130          return false;
 131      }
 132  
 133      // Add file to files array
 134      $files = array( $file );
 135  
 136      // Get the file variant (minified or not, but opposite of $file)
 137      $file_is_min  = ( false !== strpos( $file, '.min' ) );
 138      $file_variant = ( false === $file_is_min )
 139          ? str_replace( array( '.css', '.js' ), array( '.min.css', '.min.js' ), $file )
 140          : str_replace( '.min', '', $file );
 141  
 142      // Are we debugging?
 143      $script_debug = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG;
 144  
 145      // Debugging, so prefer unminified files
 146      if ( true === $script_debug ) {
 147          if ( true === $file_is_min ) {
 148              array_unshift( $files, $file_variant );
 149          } else {
 150              array_push( $files, $file_variant );
 151          }
 152  
 153      // Not debugging, so prefer minified files
 154      } elseif ( false === $script_debug ) {
 155          if ( true === $file_is_min ) {
 156              array_push( $files, $file_variant );
 157          } else {
 158              array_unshift( $files, $file_variant );
 159          }
 160      }
 161  
 162      // Return first found file location in the stack
 163      return bbp_locate_template( $files, false, false );
 164  }
 165  
 166  /**
 167   * Convert an enqueueable file path to a URL
 168   *
 169   * @since 2.6.0
 170   * @param string $file
 171   *
 172   * @return string
 173   */
 174  function bbp_urlize_enqueueable( $file = '' ) {
 175  
 176      // Get DIR and URL
 177      $content_dir = constant( 'WP_CONTENT_DIR' );
 178      $content_url = content_url();
 179  
 180      // IIS (Windows) here
 181      // Replace back slashes with forward slash
 182      if ( false !== strpos( $file, '\\' ) ) {
 183          $file        = str_replace( '\\', '/', $file        );
 184          $content_dir = str_replace( '\\', '/', $content_dir );
 185      }
 186  
 187      // Return path to file relative to site URL
 188      return str_replace( $content_dir, $content_url, $file );
 189  }
 190  
 191  /**
 192   * Enqueue a script from the highest priority location in the template stack.
 193   *
 194   * Registers the style if file provided (does NOT overwrite) and enqueues.
 195   *
 196   * @since 2.5.0 bbPress (r5180)
 197   *
 198   * @param string      $handle Name of the stylesheet.
 199   * @param string|bool $file   Relative path to stylesheet. Example: '/css/mystyle.css'.
 200   * @param array       $deps   An array of registered style handles this stylesheet depends on. Default empty array.
 201   * @param string|bool $ver    String specifying the stylesheet version number, if it has one. This parameter is used
 202   *                            to ensure that the correct version is sent to the client regardless of caching, and so
 203   *                            should be included if a version number is available and makes sense for the stylesheet.
 204   * @param string      $media  Optional. The media for which this stylesheet has been defined.
 205   *                            Default 'all'. Accepts 'all', 'aural', 'braille', 'handheld', 'projection', 'print',
 206   *                            'screen', 'tty', or 'tv'.
 207   *
 208   * @return mixed The style filename if one is located. False if not.
 209   */
 210  function bbp_enqueue_style( $handle = '', $file = '', $deps = array(), $ver = false, $media = 'all' ) {
 211  
 212      // Attempt to locate an enqueueable
 213      $located = bbp_locate_enqueueable( $file );
 214  
 215      // Enqueue if located
 216      if ( ! empty( $located ) ) {
 217  
 218          // Make sure there is always a version
 219          if ( empty( $ver ) ) {
 220              $ver = bbp_get_version();
 221          }
 222  
 223          // Make path to file relative to site URL
 224          $located = bbp_urlize_enqueueable( $located );
 225  
 226          // Register the style
 227          wp_register_style( $handle, $located, $deps, $ver, $media );
 228  
 229          // Enqueue the style
 230          wp_enqueue_style( $handle );
 231      }
 232  
 233      return $located;
 234  }
 235  
 236  /**
 237   * Enqueue a script from the highest priority location in the template stack.
 238   *
 239   * Registers the style if file provided (does NOT overwrite) and enqueues.
 240   *
 241   * @since 2.5.0 bbPress (r5180)
 242   *
 243   * @param string      $handle    Name of the script.
 244   * @param string|bool $file      Relative path to the script. Example: '/js/myscript.js'.
 245   * @param array       $deps      An array of registered handles this script depends on. Default empty array.
 246   * @param string|bool $ver       Optional. String specifying the script version number, if it has one. This parameter
 247   *                               is used to ensure that the correct version is sent to the client regardless of caching,
 248   *                               and so should be included if a version number is available and makes sense for the script.
 249   * @param bool        $in_footer Optional. Whether to enqueue the script before </head> or before </body>.
 250   *                               Default 'false'. Accepts 'false' or 'true'.
 251   *
 252   * @return mixed The script filename if one is located. False if not.
 253   */
 254  function bbp_enqueue_script( $handle = '', $file = '', $deps = array(), $ver = false, $in_footer = false ) {
 255  
 256      // Attempt to locate an enqueueable
 257      $located = bbp_locate_enqueueable( $file );
 258  
 259      // Enqueue if located
 260      if ( ! empty( $located ) ) {
 261  
 262          // Make sure there is always a version
 263          if ( empty( $ver ) ) {
 264              $ver = bbp_get_version();
 265          }
 266  
 267          // Make path to file relative to site URL
 268          $located = bbp_urlize_enqueueable( $located );
 269  
 270          // Register the style
 271          wp_register_script( $handle, $located, $deps, $ver, $in_footer );
 272  
 273          // Enqueue the style
 274          wp_enqueue_script( $handle );
 275      }
 276  
 277      return $located;
 278  }
 279  
 280  /**
 281   * This is really cool. This function registers a new template stack location,
 282   * using WordPress's built in filters API.
 283   *
 284   * This allows for templates to live in places beyond just the parent/child
 285   * relationship, to allow for custom template locations. Used in conjunction
 286   * with bbp_locate_template(), this allows for easy template overrides.
 287   *
 288   * @since 2.2.0 bbPress (r4323)
 289   *
 290   * @param string $location_callback Callback function that returns the
 291   * @param int $priority
 292   */
 293  function bbp_register_template_stack( $location_callback = '', $priority = 10 ) {
 294  
 295      // Bail if no location, or function/method is not callable
 296      if ( empty( $location_callback ) || ! is_callable( $location_callback ) ) {
 297          return false;
 298      }
 299  
 300      // Add location callback to template stack
 301      return add_filter( 'bbp_template_stack', $location_callback, (int) $priority );
 302  }
 303  
 304  /**
 305   * Deregisters a previously registered template stack location.
 306   *
 307   * @since 2.3.0 bbPress (r4652)
 308   *
 309   * @param string $location_callback Callback function that returns the
 310   * @param int $priority
 311   * @return bool Whether stack was removed
 312   */
 313  function bbp_deregister_template_stack( $location_callback = '', $priority = 10 ) {
 314  
 315      // Bail if no location, or function/method is not callable
 316      if ( empty( $location_callback ) || ! is_callable( $location_callback ) ) {
 317          return false;
 318      }
 319  
 320      // Remove location callback to template stack
 321      return remove_filter( 'bbp_template_stack', $location_callback, (int) $priority );
 322  }
 323  
 324  /**
 325   * Call the functions added to the 'bbp_template_stack' filter hook, and return
 326   * an array of the template locations.
 327   *
 328   * @since 2.2.0 bbPress (r4323)
 329   * @since 2.6.0 bbPress (r5944) Added support for `WP_Hook`
 330   *
 331   * @global array $wp_filter Stores all of the filters
 332   * @global array $merged_filters Merges the filter hooks using this function.
 333   * @global array $wp_current_filter stores the list of current filters with the current one last
 334   *
 335   * @return array The filtered value after all hooked functions are applied to it.
 336   */
 337  function bbp_get_template_stack() {
 338      global $wp_filter, $merged_filters, $wp_current_filter;
 339  
 340      // Setup some default variables
 341      $tag  = 'bbp_template_stack';
 342      $args = $stack = array();
 343  
 344      // Add 'bbp_template_stack' to the current filter array
 345      $wp_current_filter[] = $tag;
 346  
 347      // Bail if no stack setup
 348      if ( empty( $wp_filter[ $tag ] ) ) {
 349          return array();
 350      }
 351  
 352      // Check if WP_Hook class exists, see #WP17817
 353      if ( class_exists( 'WP_Hook' ) ) {
 354          $filter = $wp_filter[ $tag ]->callbacks;
 355      } else {
 356          $filter = &$wp_filter[ $tag ];
 357  
 358          // Sort
 359          if ( ! isset( $merged_filters[ $tag ] ) ) {
 360              ksort( $filter );
 361              $merged_filters[ $tag ] = true;
 362          }
 363      }
 364  
 365      // Ensure we're always at the beginning of the filter array
 366      reset( $filter );
 367  
 368      // Loop through 'bbp_template_stack' filters, and call callback functions
 369      do {
 370          foreach ( (array) current( $filter ) as $the_ ) {
 371              if ( ! is_null( $the_['function'] ) ) {
 372                  $args[1] = $stack;
 373                  $stack[] = call_user_func_array( $the_['function'], array_slice( $args, 1, (int) $the_['accepted_args'] ) );
 374              }
 375          }
 376      } while ( next( $filter ) !== false );
 377  
 378      // Remove 'bbp_template_stack' from the current filter array
 379      array_pop( $wp_current_filter );
 380  
 381      // Remove empties and duplicates
 382      $stack = array_unique( array_filter( $stack ) );
 383  
 384      // Filter & return
 385      return (array) apply_filters( 'bbp_get_template_stack', $stack ) ;
 386  }
 387  
 388  /**
 389   * Get a template part in an output buffer, and return it
 390   *
 391   * @since 2.4.0 bbPress (r5043)
 392   *
 393   * @param string $slug
 394   * @param string $name
 395   * @return string
 396   */
 397  function bbp_buffer_template_part( $slug, $name = null, $echo = true ) {
 398      ob_start();
 399  
 400      bbp_get_template_part( $slug, $name );
 401  
 402      // Get the output buffer contents
 403      $output = ob_get_clean();
 404  
 405      // Echo or return the output buffer contents
 406      if ( true === $echo ) {
 407          echo $output;
 408      } else {
 409          return $output;
 410      }
 411  }
 412  
 413  /**
 414   * Retrieve path to a template
 415   *
 416   * Used to quickly retrieve the path of a template without including the file
 417   * extension. It will also check the parent theme and theme-compat theme with
 418   * the use of {@link bbp_locate_template()}. Allows for more generic template
 419   * locations without the use of the other get_*_template() functions.
 420   *
 421   * @since 2.1.0 bbPress (r3629)
 422   *
 423   * @param string $type Filename without extension.
 424   * @param array $templates An optional list of template candidates
 425   * @return string Full path to file.
 426   */
 427  function bbp_get_query_template( $type, $templates = array() ) {
 428      $type = preg_replace( '|[^a-z0-9-]+|', '', $type );
 429  
 430      // Fallback template
 431      if ( empty( $templates ) ) {
 432          $templates = array( "{$type}.php" );
 433      }
 434  
 435      // Filter possible templates
 436      $templates = apply_filters( "bbp_get_{$type}_template", $templates );
 437  
 438      // Stash the possible templates for this query, for later use
 439      bbp_set_theme_compat_templates( $templates );
 440  
 441      // Try to locate a template in the stack
 442      $template = bbp_locate_template( $templates );
 443  
 444      // Stash the located template for this query, for later use
 445      bbp_set_theme_compat_template( $template );
 446  
 447      // Filter & return
 448      return apply_filters( "bbp_{$type}_template", $template, $templates );
 449  }
 450  
 451  /**
 452   * Get the possible subdirectories to check for templates in
 453   *
 454   * @since 2.1.0 bbPress (r3738)
 455   *
 456   * @param array $templates Templates we are looking for
 457   * @return array Possible subdirectories to look in
 458   */
 459  function bbp_get_template_locations( $templates = array() ) {
 460      $locations = array(
 461          'bbpress',
 462          'forums',
 463          ''
 464      );
 465  
 466      // Filter & return
 467      return apply_filters( 'bbp_get_template_locations', $locations, $templates );
 468  }
 469  
 470  /**
 471   * Add template locations to template files being searched for
 472   *
 473   * @since 2.1.0 bbPress (r3738)
 474   *
 475   * @param array $stacks
 476   * @return array()
 477   */
 478  function bbp_add_template_stack_locations( $stacks = array() ) {
 479      $retval = array();
 480  
 481      // Get alternate locations
 482      $locations = bbp_get_template_locations();
 483  
 484      // Loop through locations and stacks and combine
 485      foreach ( (array) $stacks as $stack ) {
 486          foreach ( (array) $locations as $custom_location ) {
 487              $retval[] = untrailingslashit( trailingslashit( $stack ) . $custom_location );
 488          }
 489      }
 490  
 491      // Filter & return
 492      return (array) apply_filters( 'bbp_add_template_stack_locations', array_unique( $retval ), $stacks );
 493  }
 494  
 495  /**
 496   * Add checks for bbPress conditions to parse_query action
 497   *
 498   * If it's a user page, WP_Query::bbp_is_single_user is set to true.
 499   *
 500   * If it's a user edit page, WP_Query::bbp_is_single_user_edit is set to true
 501   * and the the 'wp-admin/includes/user.php' file is included.
 502   *
 503   * In addition, on user/user edit pages, WP_Query::home is set to false & query
 504   * vars 'bbp_user_id' with the displayed user id is added.
 505   *
 506   * In 2.6.0, the 'author_name' variable is no longer set when viewing a single
 507   * user, because of is_author() weirdness. If this removal causes problems, it
 508   * may come back in a future release.
 509   *
 510   * If it's a forum edit, WP_Query::bbp_is_forum_edit is set to true
 511   * If it's a topic edit, WP_Query::bbp_is_topic_edit is set to true
 512   * If it's a reply edit, WP_Query::bbp_is_reply_edit is set to true.
 513   *
 514   * If it's a view page, WP_Query::bbp_is_view is set to true
 515   * If it's a search page, WP_Query::bbp_is_search is set to true
 516   *
 517   * @since 2.0.0 bbPress (r2688)
 518   *
 519   * @param WP_Query $posts_query
 520   */
 521  function bbp_parse_query( $posts_query ) {
 522  
 523      // Bail if $posts_query is not the main loop
 524      if ( ! $posts_query->is_main_query() ) {
 525          return;
 526      }
 527  
 528      // Bail if filters are suppressed on this query
 529      if ( true === $posts_query->get( 'suppress_filters' ) ) {
 530          return;
 531      }
 532  
 533      // Bail if in admin
 534      if ( is_admin() ) {
 535          return;
 536      }
 537  
 538      // Get query variables
 539      $bbp_view = $posts_query->get( bbp_get_view_rewrite_id() );
 540      $bbp_user = $posts_query->get( bbp_get_user_rewrite_id() );
 541      $is_edit  = $posts_query->get( bbp_get_edit_rewrite_id() );
 542  
 543      // It is a user page - We'll also check if it is user edit
 544      if ( ! empty( $bbp_user ) ) {
 545  
 546          /** Find User *********************************************************/
 547  
 548          // Setup the default user variable
 549          $the_user = false;
 550  
 551          // If using pretty permalinks, always use slug
 552          if ( get_option( 'permalink_structure' ) ) {
 553              $the_user = get_user_by( 'slug', $bbp_user );
 554  
 555          // If not using pretty permalinks, always use numeric ID
 556          } elseif ( is_numeric( $bbp_user ) ) {
 557              $the_user = get_user_by( 'id', $bbp_user );
 558          }
 559  
 560          // 404 and bail if user does not have a profile
 561          if ( empty( $the_user->ID ) || ! bbp_user_has_profile( $the_user->ID ) ) {
 562              $posts_query->bbp_is_404 = true;
 563              return;
 564          }
 565  
 566          /** User Exists *******************************************************/
 567  
 568          $is_favs        = $posts_query->get( bbp_get_user_favorites_rewrite_id()     );
 569          $is_subs        = $posts_query->get( bbp_get_user_subscriptions_rewrite_id() );
 570          $is_topics      = $posts_query->get( bbp_get_user_topics_rewrite_id()        );
 571          $is_replies     = $posts_query->get( bbp_get_user_replies_rewrite_id()       );
 572          $is_engagements = $posts_query->get( bbp_get_user_engagements_rewrite_id()   );
 573  
 574          // View or edit?
 575          if ( ! empty( $is_edit ) ) {
 576  
 577              // We are editing a profile
 578              $posts_query->bbp_is_single_user_edit = true;
 579  
 580              // Load the core WordPress contact methods
 581              if ( ! function_exists( '_wp_get_user_contactmethods' ) ) {
 582                  require_once ABSPATH . 'wp-includes/registration.php';
 583              }
 584  
 585              // Load the edit_user functions
 586              if ( ! function_exists( 'edit_user' ) ) {
 587                  require_once ABSPATH . 'wp-admin/includes/user.php';
 588              }
 589  
 590              // Load the grant/revoke super admin functions
 591              if ( is_multisite() && ! function_exists( 'revoke_super_admin' ) ) {
 592                  require_once ABSPATH . 'wp-admin/includes/ms.php';
 593              }
 594  
 595              // Editing a user
 596              $posts_query->bbp_is_edit = true;
 597  
 598          // User favorites
 599          } elseif ( ! empty( $is_favs ) ) {
 600              $posts_query->bbp_is_single_user_favs = true;
 601  
 602          // User subscriptions
 603          } elseif ( ! empty( $is_subs ) ) {
 604              $posts_query->bbp_is_single_user_subs = true;
 605  
 606          // User topics
 607          } elseif ( ! empty( $is_topics ) ) {
 608              $posts_query->bbp_is_single_user_topics = true;
 609  
 610          // User topics
 611          } elseif ( ! empty( $is_replies ) ) {
 612              $posts_query->bbp_is_single_user_replies = true;
 613  
 614          // User engagements
 615          } elseif ( ! empty( $is_engagements ) ) {
 616              $posts_query->bbp_is_single_user_engagements = true;
 617  
 618          // User profile
 619          } else {
 620              $posts_query->bbp_is_single_user_profile = true;
 621          }
 622  
 623          // Make sure 404 is not set
 624          $posts_query->is_404  = false;
 625  
 626          // Correct is_home variable
 627          $posts_query->is_home = false;
 628  
 629          // Looking at a single user
 630          $posts_query->bbp_is_single_user = true;
 631  
 632          // User found so don't 404 yet
 633          $posts_query->bbp_is_404 = false;
 634  
 635          // User is looking at their own profile
 636          if ( bbp_get_current_user_id() === $the_user->ID ) {
 637              $posts_query->bbp_is_single_user_home = true;
 638          }
 639  
 640          // Set bbp_user_id for future reference
 641          $posts_query->set( 'bbp_user_id', $the_user->ID );
 642  
 643          // Set the displayed user global to this user
 644          bbpress()->displayed_user = $the_user;
 645  
 646      // View Page
 647      } elseif ( ! empty( $bbp_view ) ) {
 648  
 649          // Check if the view exists by checking if there are query args are set
 650          $view_args = bbp_get_view_query_args( $bbp_view );
 651  
 652          // Bail if view args is false (view isn't registered)
 653          if ( false === $view_args ) {
 654              $posts_query->bbp_is_404 = true;
 655              return;
 656          }
 657  
 658          // Correct is_home variable
 659          $posts_query->is_home     = false;
 660  
 661          // We are in a custom topic view
 662          $posts_query->bbp_is_view = true;
 663  
 664          // No 404 because views are all (currently) public
 665          $posts_query->bbp_is_404 = false;
 666  
 667      // Search Page
 668      } elseif ( isset( $posts_query->query_vars[ bbp_get_search_rewrite_id() ] ) ) {
 669  
 670          // Check if there are search query args set
 671          $search_terms = bbp_get_search_terms();
 672          if ( ! empty( $search_terms ) ) {
 673              $posts_query->bbp_search_terms = $search_terms;
 674          }
 675  
 676          // Correct is_home variable
 677          $posts_query->is_home = false;
 678  
 679          // We are in a search query
 680          $posts_query->bbp_is_search = true;
 681  
 682          // No 404 because search is always public
 683          $posts_query->bbp_is_404 = false;
 684  
 685      // Forum/Topic/Reply Edit Page
 686      } elseif ( ! empty( $is_edit ) ) {
 687  
 688          // Get the post type from the main query loop
 689          $post_type = $posts_query->get( 'post_type' );
 690  
 691          // Check which post_type we are editing, if any
 692          if ( ! empty( $post_type ) ) {
 693              switch ( $post_type ) {
 694  
 695                  // We are editing a forum
 696                  case bbp_get_forum_post_type() :
 697                      $posts_query->bbp_is_forum_edit  = true;
 698                      $posts_query->bbp_is_edit        = true;
 699                      $posts_query->bbp_is_404         = false;
 700                      break;
 701  
 702                  // We are editing a topic
 703                  case bbp_get_topic_post_type() :
 704                      $posts_query->bbp_is_topic_edit  = true;
 705                      $posts_query->bbp_is_edit        = true;
 706                      $posts_query->bbp_is_404         = false;
 707                      break;
 708  
 709                  // We are editing a reply
 710                  case bbp_get_reply_post_type() :
 711                      $posts_query->bbp_is_reply_edit  = true;
 712                      $posts_query->bbp_is_edit        = true;
 713                      $posts_query->bbp_is_404         = false;
 714                      break;
 715              }
 716  
 717          // We are editing a topic tag
 718          } elseif ( bbp_is_topic_tag() ) {
 719              $posts_query->bbp_is_topic_tag_edit = true;
 720              $posts_query->bbp_is_edit           = true;
 721              $posts_query->bbp_is_404            = false;
 722          }
 723  
 724          // We save post revisions on our own
 725          remove_action( 'pre_post_update', 'wp_save_post_revision' );
 726  
 727      // Topic tag page
 728      } elseif ( bbp_is_topic_tag() ) {
 729          $posts_query->set( 'bbp_topic_tag',  get_query_var( 'term' )   );
 730          $posts_query->set( 'post_type',      bbp_get_topic_post_type() );
 731          $posts_query->set( 'posts_per_page', bbp_get_topics_per_page() );
 732  
 733      // Do topics on forums root
 734      } elseif ( is_post_type_archive( bbp_get_post_types( array( 'has_archive' => true ) ) ) && ( 'topics' === bbp_show_on_root() ) ) {
 735          $posts_query->bbp_show_topics_on_root = true;
 736      }
 737  }


Generated: Tue Jul 16 01:01:32 2019 Cross-referenced by PHPXref 0.7.1