bbp_request_feed_trap

This function is hooked into the WordPress 'request' action and is responsible for sniffing out the query vars and serving up RSS2 feeds if the stars align and the user has requested a feed of any bbPress type.

Description

(array) bbp_request_feed_trap( (array) $query_vars = array() ); 

Returns (array)

Parameters (1)

0. $query_vars — Optional. (array) => array()
The query vars.

Usage

  1. if ( !function_exists( 'bbp_request_feed_trap' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'bbpress/includes/common/functions.php'; 
  3.  
  4. // The query vars. 
  5. $query_vars = array(); 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = bbp_request_feed_trap($query_vars); 
  9.  

Defined (1)

The function is defined in the following location(s).

/includes/common/functions.php  
  1. function bbp_request_feed_trap( $query_vars = array() ) { 
  2.  
  3. // Looking at a feed 
  4. if ( isset( $query_vars['feed'] ) ) { 
  5.  
  6. // Forum/Topic/Reply Feed 
  7. if ( isset( $query_vars['post_type'] ) ) { 
  8.  
  9. // Matched post type 
  10. $post_type = false; 
  11.  
  12. // Post types to check 
  13. $post_types = array( 
  14. ); 
  15.  
  16. // Cast query vars as array outside of foreach loop 
  17. $qv_array = (array) $query_vars['post_type']; 
  18.  
  19. // Check if this query is for a bbPress post type 
  20. foreach ( $post_types as $bbp_pt ) { 
  21. if ( in_array( $bbp_pt, $qv_array, true ) ) { 
  22. $post_type = $bbp_pt; 
  23. break; 
  24.  
  25. // Looking at a bbPress post type 
  26. if ( ! empty( $post_type ) ) { 
  27.  
  28. // Supported select query vars 
  29. $select_query_vars = array( 
  30. 'p' => false,  
  31. 'name' => false,  
  32. $post_type => false,  
  33. ); 
  34.  
  35. // Setup matched variables to select 
  36. foreach ( $query_vars as $key => $value ) { 
  37. if ( isset( $select_query_vars[$key] ) ) { 
  38. $select_query_vars[$key] = $value; 
  39.  
  40. // Remove any empties 
  41. $select_query_vars = array_filter( $select_query_vars ); 
  42.  
  43. // What bbPress post type are we looking for feeds on? 
  44. switch ( $post_type ) { 
  45.  
  46. // Forum 
  47.  
  48. // Define local variable(s) 
  49. $meta_query = array(); 
  50.  
  51. // Single forum 
  52. if ( !empty( $select_query_vars ) ) { 
  53.  
  54. // Load up our own query 
  55. query_posts( array_merge( array( 
  56. 'post_type' => bbp_get_forum_post_type(),  
  57. 'feed' => true 
  58. ), $select_query_vars ) ); 
  59.  
  60. // Restrict to specific forum ID 
  61. $meta_query = array( array( 
  62. 'key' => '_bbp_forum_id',  
  63. 'value' => bbp_get_forum_id(),  
  64. 'type' => 'numeric',  
  65. 'compare' => '=' 
  66. ) ); 
  67.  
  68. // Only forum replies 
  69. if ( !empty( $_GET['type'] ) && ( bbp_get_reply_post_type() === $_GET['type'] ) ) { 
  70.  
  71. // The query 
  72. $the_query = array( 
  73. 'author' => 0,  
  74. 'feed' => true,  
  75. 'post_type' => bbp_get_reply_post_type(),  
  76. 'post_parent' => 'any',  
  77. 'post_status' => array( bbp_get_public_status_id(), bbp_get_closed_status_id() ),  
  78. 'posts_per_page' => bbp_get_replies_per_rss_page(),  
  79. 'order' => 'DESC',  
  80. 'meta_query' => $meta_query 
  81. ); 
  82.  
  83. // Output the feed 
  84.  
  85. // Only forum topics 
  86. } elseif ( !empty( $_GET['type'] ) && ( bbp_get_topic_post_type() === $_GET['type'] ) ) { 
  87.  
  88. // The query 
  89. $the_query = array( 
  90. 'author' => 0,  
  91. 'feed' => true,  
  92. 'post_type' => bbp_get_topic_post_type(),  
  93. 'post_parent' => bbp_get_forum_id(),  
  94. 'post_status' => array( bbp_get_public_status_id(), bbp_get_closed_status_id() ),  
  95. 'posts_per_page' => bbp_get_topics_per_rss_page(),  
  96. 'order' => 'DESC' 
  97. ); 
  98.  
  99. // Output the feed 
  100.  
  101. // All forum topics and replies 
  102. } else { 
  103.  
  104. // Exclude private/hidden forums if not looking at single 
  105. if ( empty( $select_query_vars ) ) 
  106. $meta_query = array( bbp_exclude_forum_ids( 'meta_query' ) ); 
  107.  
  108. // The query 
  109. $the_query = array( 
  110. 'author' => 0,  
  111. 'feed' => true,  
  112. 'post_type' => array( bbp_get_reply_post_type(), bbp_get_topic_post_type() ),  
  113. 'post_parent' => 'any',  
  114. 'post_status' => array( bbp_get_public_status_id(), bbp_get_closed_status_id() ),  
  115. 'posts_per_page' => bbp_get_replies_per_rss_page(),  
  116. 'order' => 'DESC',  
  117. 'meta_query' => $meta_query 
  118. ); 
  119.  
  120. // Output the feed 
  121.  
  122. break; 
  123.  
  124. // Topic feed - Show replies 
  125.  
  126. // Single topic 
  127. if ( !empty( $select_query_vars ) ) { 
  128.  
  129. // Load up our own query 
  130. query_posts( array_merge( array( 
  131. 'post_type' => bbp_get_topic_post_type(),  
  132. 'feed' => true 
  133. ), $select_query_vars ) ); 
  134.  
  135. // Output the feed 
  136. bbp_display_replies_feed_rss2( array( 'feed' => true ) ); 
  137.  
  138. // All topics 
  139. } else { 
  140.  
  141. // The query 
  142. $the_query = array( 
  143. 'author' => 0,  
  144. 'feed' => true,  
  145. 'post_parent' => 'any',  
  146. 'posts_per_page' => bbp_get_topics_per_rss_page(),  
  147. 'show_stickies' => false 
  148. ); 
  149.  
  150. // Output the feed 
  151.  
  152. break; 
  153.  
  154. // Replies 
  155.  
  156. // The query 
  157. $the_query = array( 
  158. 'posts_per_page' => bbp_get_replies_per_rss_page(),  
  159. 'meta_query' => array( array( ) ),  
  160. 'feed' => true 
  161. ); 
  162.  
  163. // All replies 
  164. if ( empty( $select_query_vars ) ) { 
  165.  
  166. break; 
  167.  
  168. // Single Topic Vview 
  169. } elseif ( isset( $query_vars[ bbp_get_view_rewrite_id() ] ) ) { 
  170.  
  171. // Get the view 
  172. $view = $query_vars[ bbp_get_view_rewrite_id() ]; 
  173.  
  174. // We have a view to display a feed 
  175. if ( !empty( $view ) ) { 
  176.  
  177. // Get the view query 
  178. $the_query = bbp_get_view_query_args( $view ); 
  179.  
  180. // Output the feed 
  181.  
  182. // @todo User profile feeds 
  183.  
  184. // No feed so continue on 
  185. return $query_vars;