/includes/core/template-functions.php

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