BP_Groups_Theme_Compat

The main theme compat class for BuddyPress Groups.

Defined (1)

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

/bp-groups/classes/class-bp-groups-theme-compat.php  
  1. class BP_Groups_Theme_Compat { 
  2.  
  3. /** 
  4. * Set up theme compatibility for the Groups component. 
  5. * @since 1.7.0 
  6. */ 
  7. public function __construct() { 
  8. add_action( 'bp_setup_theme_compat', array( $this, 'is_group' ) ); 
  9.  
  10. /** 
  11. * Are we looking at something that needs group theme compatibility? 
  12. * @since 1.7.0 
  13. */ 
  14. public function is_group() { 
  15.  
  16. // Bail if not looking at a group. 
  17. if ( ! bp_is_groups_component() ) 
  18. return; 
  19.  
  20. // Group Directory. 
  21. if ( bp_is_groups_directory() ) { 
  22. bp_update_is_directory( true, 'groups' ); 
  23.  
  24. /** 
  25. * Fires at the start of the group theme compatibility setup. 
  26. * @since 1.1.0 
  27. */ 
  28. do_action( 'groups_directory_groups_setup' ); 
  29.  
  30. add_filter( 'bp_get_buddypress_template', array( $this, 'directory_template_hierarchy' ) ); 
  31. add_action( 'bp_template_include_reset_dummy_post_data', array( $this, 'directory_dummy_post' ) ); 
  32. add_filter( 'bp_replace_the_content', array( $this, 'directory_content' ) ); 
  33.  
  34. // Creating a group. 
  35. } elseif ( bp_is_groups_component() && bp_is_current_action( 'create' ) ) { 
  36. add_filter( 'bp_get_buddypress_template', array( $this, 'create_template_hierarchy' ) ); 
  37. add_action( 'bp_template_include_reset_dummy_post_data', array( $this, 'create_dummy_post' ) ); 
  38. add_filter( 'bp_replace_the_content', array( $this, 'create_content' ) ); 
  39.  
  40. // Group page. 
  41. } elseif ( bp_is_single_item() ) { 
  42. add_filter( 'bp_get_buddypress_template', array( $this, 'single_template_hierarchy' ) ); 
  43. add_action( 'bp_template_include_reset_dummy_post_data', array( $this, 'single_dummy_post' ) ); 
  44. add_filter( 'bp_replace_the_content', array( $this, 'single_content' ) ); 
  45.  
  46.  
  47. /** Directory *********************************************************/ 
  48.  
  49. /** 
  50. * Add template hierarchy to theme compat for the group directory page. 
  51. * This is to mirror how WordPress has 
  52. * {@link https://codex.wordpress.org/Template_Hierarchy template hierarchy}. 
  53. * @since 1.8.0 
  54. * @param string $templates The templates from bp_get_theme_compat_templates(). 
  55. * @return array $templates Array of custom templates to look for. 
  56. */ 
  57. public function directory_template_hierarchy( $templates ) { 
  58. // Set up the template hierarchy. 
  59. $new_templates = array(); 
  60. if ( '' !== bp_get_current_group_directory_type() ) { 
  61. $new_templates[] = 'groups/index-directory-type-' . sanitize_file_name( bp_get_current_group_directory_type() ) . '.php'; 
  62. $new_templates[] = 'groups/index-directory.php'; 
  63.  
  64. /** 
  65. * Filters the Groups directory page template hierarchy based on priority. 
  66. * @since 1.8.0 
  67. * @param array $value Array of default template files to use. 
  68. */ 
  69. $new_templates = apply_filters( 'bp_template_hierarchy_groups_directory', $new_templates ); 
  70.  
  71. // Merge new templates with existing stack. 
  72. // @see bp_get_theme_compat_templates(). 
  73. $templates = array_merge( (array) $new_templates, $templates ); 
  74.  
  75. return $templates; 
  76.  
  77. /** 
  78. * Update the global $post with directory data. 
  79. * @since 1.7.0 
  80. */ 
  81. public function directory_dummy_post() { 
  82. bp_theme_compat_reset_post( array( 
  83. 'ID' => 0,  
  84. 'post_title' => bp_get_directory_title( 'groups' ),  
  85. 'post_author' => 0,  
  86. 'post_date' => 0,  
  87. 'post_content' => '',  
  88. 'post_type' => 'page',  
  89. 'post_status' => 'publish',  
  90. 'is_page' => true,  
  91. 'comment_status' => 'closed' 
  92. ) ); 
  93.  
  94. /** 
  95. * Filter the_content with the groups index template part. 
  96. * @since 1.7.0 
  97. */ 
  98. public function directory_content() { 
  99. return bp_buffer_template_part( 'groups/index', null, false ); 
  100.  
  101. /** Create ************************************************************/ 
  102.  
  103. /** 
  104. * Add custom template hierarchy to theme compat for the group create page. 
  105. * This is to mirror how WordPress has 
  106. * {@link https://codex.wordpress.org/Template_Hierarchy template hierarchy}. 
  107. * @since 1.8.0 
  108. * @param string $templates The templates from bp_get_theme_compat_templates(). 
  109. * @return array $templates Array of custom templates to look for. 
  110. */ 
  111. public function create_template_hierarchy( $templates ) { 
  112.  
  113. /** 
  114. * Filters the Groups create page template hierarchy based on priority. 
  115. * @since 1.8.0 
  116. * @param array $value Array of default template files to use. 
  117. */ 
  118. $new_templates = apply_filters( 'bp_template_hierarchy_groups_create', array( 
  119. 'groups/index-create.php' 
  120. ) ); 
  121.  
  122. // Merge new templates with existing stack. 
  123. // @see bp_get_theme_compat_templates(). 
  124. $templates = array_merge( $new_templates, $templates ); 
  125.  
  126. return $templates; 
  127.  
  128. /** 
  129. * Update the global $post with create screen data. 
  130. * @since 1.7.0 
  131. */ 
  132. public function create_dummy_post() { 
  133.  
  134. $title = _x( 'Groups', 'Group creation page', 'buddypress' ); 
  135.  
  136. bp_theme_compat_reset_post( array( 
  137. 'ID' => 0,  
  138. 'post_title' => $title,  
  139. 'post_author' => 0,  
  140. 'post_date' => 0,  
  141. 'post_content' => '',  
  142. 'post_type' => 'page',  
  143. 'post_status' => 'publish',  
  144. 'is_page' => true,  
  145. 'comment_status' => 'closed' 
  146. ) ); 
  147.  
  148. /** 
  149. * Filter the_content with the create screen template part. 
  150. * @since 1.7.0 
  151. */ 
  152. public function create_content() { 
  153. return bp_buffer_template_part( 'groups/create', null, false ); 
  154.  
  155. /** Single ************************************************************/ 
  156.  
  157. /** 
  158. * Add custom template hierarchy to theme compat for group pages. 
  159. * This is to mirror how WordPress has 
  160. * {@link https://codex.wordpress.org/Template_Hierarchy template hierarchy}. 
  161. * @since 1.8.0 
  162. * @param string $templates The templates from bp_get_theme_compat_templates(). 
  163. * @return array $templates Array of custom templates to look for. 
  164. */ 
  165. public function single_template_hierarchy( $templates ) { 
  166. // Setup some variables we're going to reference in our custom templates. 
  167. $group = groups_get_current_group(); 
  168.  
  169. /** 
  170. * Filters the Groups single pages template hierarchy based on priority. 
  171. * @since 1.8.0 
  172. * @param array $value Array of default template files to use. 
  173. */ 
  174. $new_templates = apply_filters( 'bp_template_hierarchy_groups_single_item', array( 
  175. 'groups/single/index-id-' . sanitize_file_name( bp_get_current_group_id() ) . '.php',  
  176. 'groups/single/index-slug-' . sanitize_file_name( bp_get_current_group_slug() ) . '.php',  
  177. 'groups/single/index-action-' . sanitize_file_name( bp_current_action() ) . '.php',  
  178. 'groups/single/index-status-' . sanitize_file_name( $group->status ) . '.php',  
  179. 'groups/single/index.php' 
  180. ) ); 
  181.  
  182. // Merge new templates with existing stack. 
  183. // @see bp_get_theme_compat_templates(). 
  184. $templates = array_merge( (array) $new_templates, $templates ); 
  185.  
  186. return $templates; 
  187.  
  188. /** 
  189. * Update the global $post with single group data. 
  190. * @since 1.7.0 
  191. */ 
  192. public function single_dummy_post() { 
  193. bp_theme_compat_reset_post( array( 
  194. 'ID' => 0,  
  195. 'post_title' => bp_get_current_group_name(),  
  196. 'post_author' => 0,  
  197. 'post_date' => 0,  
  198. 'post_content' => '',  
  199. 'post_type' => 'page',  
  200. 'post_status' => 'publish',  
  201. 'is_page' => true,  
  202. 'comment_status' => 'closed' 
  203. ) ); 
  204.  
  205. /** 
  206. * Filter the_content with the single group template part. 
  207. * @since 1.7.0 
  208. */ 
  209. public function single_content() { 
  210. return bp_buffer_template_part( 'groups/single/home', null, false );