BP_Members_Theme_Compat

The main theme compat class for BuddyPress Members.

Defined (1)

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

/bp-members/classes/class-bp-members-theme-compat.php  
  1. class BP_Members_Theme_Compat { 
  2.  
  3. /** 
  4. * Set up the members component theme compatibility. 
  5. * @since 1.7.0 
  6. */ 
  7. public function __construct() { 
  8. add_action( 'bp_setup_theme_compat', array( $this, 'is_members' ) ); 
  9.  
  10. /** 
  11. * Are we looking at something that needs members theme compatibility? 
  12. * @since 1.7.0 
  13. */ 
  14. public function is_members() { 
  15.  
  16. // Bail if not looking at the members component or a user's page. 
  17. if ( ! bp_is_members_component() && ! bp_is_user() ) { 
  18. return; 
  19.  
  20. // Members Directory. 
  21. if ( ! bp_current_action() && ! bp_current_item() ) { 
  22. bp_update_is_directory( true, 'members' ); 
  23.  
  24. /** 
  25. * Fires if looking at Members directory when needing theme compat. 
  26. * @since 1.5.0 
  27. */ 
  28. do_action( 'bp_members_screen_index' ); 
  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. // User page. 
  35. } elseif ( bp_is_user() ) { 
  36.  
  37. // If we're on a single activity permalink page, we shouldn't use the members 
  38. // template, so stop here! 
  39. if ( bp_is_active( 'activity' ) && bp_is_single_activity() ) { 
  40. return; 
  41.  
  42. /** 
  43. * Fires if looking at Members user page when needing theme compat. 
  44. * @since 1.5.0 
  45. */ 
  46. do_action( 'bp_members_screen_display_profile' ); 
  47.  
  48. add_filter( 'bp_get_buddypress_template', array( $this, 'single_template_hierarchy' ) ); 
  49. add_action( 'bp_template_include_reset_dummy_post_data', array( $this, 'single_dummy_post' ) ); 
  50. add_filter( 'bp_replace_the_content', array( $this, 'single_dummy_content' ) ); 
  51.  
  52.  
  53. /** Directory *************************************************************/ 
  54.  
  55. /** 
  56. * Add template hierarchy to theme compat for the members directory page. 
  57. * This is to mirror how WordPress has 
  58. * {@link https://codex.wordpress.org/Template_Hierarchy template hierarchy}. 
  59. * @since 1.8.0 
  60. * @param array $templates The templates from bp_get_theme_compat_templates(). 
  61. * @return array $templates Array of custom templates to look for. 
  62. */ 
  63. public function directory_template_hierarchy( $templates = array() ) { 
  64.  
  65. // Set up the template hierarchy. 
  66. $new_templates = array(); 
  67. if ( '' !== bp_get_current_member_type() ) { 
  68. $new_templates[] = 'members/index-directory-type-' . sanitize_file_name( bp_get_current_member_type() ) . '.php'; 
  69. $new_templates[] = 'members/index-directory.php'; 
  70.  
  71. /** 
  72. * Filters the template hierarchy for theme compat and members directory page. 
  73. * @since 1.8.0 
  74. * @param array $value Array of template paths to add to hierarchy. 
  75. */ 
  76. $new_templates = apply_filters( 'bp_template_hierarchy_members_directory', $new_templates ); 
  77.  
  78. // Merge new templates with existing stack 
  79. // @see bp_get_theme_compat_templates(). 
  80. $templates = array_merge( (array) $new_templates, $templates ); 
  81.  
  82. return $templates; 
  83.  
  84. /** 
  85. * Update the global $post with directory data. 
  86. * @since 1.7.0 
  87. */ 
  88. public function directory_dummy_post() { 
  89. bp_theme_compat_reset_post( array( 
  90. 'ID' => 0,  
  91. 'post_title' => bp_get_directory_title( 'members' ),  
  92. 'post_author' => 0,  
  93. 'post_date' => 0,  
  94. 'post_content' => '',  
  95. 'post_type' => 'page',  
  96. 'post_status' => 'publish',  
  97. 'is_page' => true,  
  98. 'comment_status' => 'closed' 
  99. ) ); 
  100.  
  101. /** 
  102. * Filter the_content with the members index template part. 
  103. * @since 1.7.0 
  104. */ 
  105. public function directory_content() { 
  106. return bp_buffer_template_part( 'members/index', null, false ); 
  107.  
  108. /** Single ****************************************************************/ 
  109.  
  110. /** 
  111. * Add custom template hierarchy to theme compat for member pages. 
  112. * This is to mirror how WordPress has 
  113. * {@link https://codex.wordpress.org/Template_Hierarchy template hierarchy}. 
  114. * @since 1.8.0 
  115. * @param string $templates The templates from 
  116. * bp_get_theme_compat_templates(). 
  117. * @return array $templates Array of custom templates to look for. 
  118. */ 
  119. public function single_template_hierarchy( $templates ) { 
  120. // Setup some variables we're going to reference in our custom templates. 
  121. $user_nicename = buddypress()->displayed_user->userdata->user_nicename; 
  122.  
  123. /** 
  124. * Filters the template hierarchy for theme compat and member pages. 
  125. * @since 1.8.0 
  126. * @param array $value Array of template paths to add to hierarchy. 
  127. */ 
  128. $new_templates = apply_filters( 'bp_template_hierarchy_members_single_item', array( 
  129. 'members/single/index-id-' . sanitize_file_name( bp_displayed_user_id() ) . '.php',  
  130. 'members/single/index-nicename-' . sanitize_file_name( $user_nicename ) . '.php',  
  131. 'members/single/index-action-' . sanitize_file_name( bp_current_action() ) . '.php',  
  132. 'members/single/index-component-' . sanitize_file_name( bp_current_component() ) . '.php',  
  133. 'members/single/index.php' 
  134. ) ); 
  135.  
  136. // Merge new templates with existing stack 
  137. // @see bp_get_theme_compat_templates(). 
  138. $templates = array_merge( (array) $new_templates, $templates ); 
  139.  
  140. return $templates; 
  141.  
  142. /** 
  143. * Update the global $post with the displayed user's data. 
  144. * @since 1.7.0 
  145. */ 
  146. public function single_dummy_post() { 
  147. bp_theme_compat_reset_post( array( 
  148. 'ID' => 0,  
  149. 'post_title' => bp_get_displayed_user_fullname(),  
  150. 'post_author' => 0,  
  151. 'post_date' => 0,  
  152. 'post_content' => '',  
  153. 'post_type' => 'page',  
  154. 'post_status' => 'publish',  
  155. 'is_page' => true,  
  156. 'comment_status' => 'closed' 
  157. ) ); 
  158.  
  159. /** 
  160. * Filter the_content with the members' single home template part. 
  161. * @since 1.7.0 
  162. */ 
  163. public function single_dummy_content() { 
  164. return bp_buffer_template_part( 'members/single/home', null, false );