BP_Blogs_Theme_Compat

The main theme compat class for BuddyPress Blogs.

Defined (1)

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

/bp-blogs/classes/class-bp-blogs-theme-compat.php  
  1. class BP_Blogs_Theme_Compat { 
  2.  
  3. /** 
  4. * Set up theme compatibility for the Blogs component. 
  5. * @since 1.7.0 
  6. */ 
  7. public function __construct() { 
  8. add_action( 'bp_setup_theme_compat', array( $this, 'is_blogs' ) ); 
  9.  
  10. /** 
  11. * Are we looking at something that needs Blogs theme compatibility? 
  12. * @since 1.7.0 
  13. */ 
  14. public function is_blogs() { 
  15.  
  16. // Bail if not looking at a group. 
  17. if ( ! bp_is_blogs_component() ) 
  18. return; 
  19.  
  20. // Bail if looking at a users sites. 
  21. if ( bp_is_user() ) 
  22. return; 
  23.  
  24. // Blog Directory. 
  25. if ( is_multisite() && ! bp_current_action() ) { 
  26. bp_update_is_directory( true, 'blogs' ); 
  27.  
  28. /** 
  29. * Fires if in the blog directory and BuddyPress needs Blog theme compatibility,  
  30. * before the actions and filters are added. 
  31. * @since 1.5.0 
  32. */ 
  33. do_action( 'bp_blogs_screen_index' ); 
  34.  
  35. add_filter( 'bp_get_buddypress_template', array( $this, 'directory_template_hierarchy' ) ); 
  36. add_action( 'bp_template_include_reset_dummy_post_data', array( $this, 'directory_dummy_post' ) ); 
  37. add_filter( 'bp_replace_the_content', array( $this, 'directory_content' ) ); 
  38.  
  39. // Create blog. 
  40. } elseif ( is_user_logged_in() && bp_blog_signup_enabled() ) { 
  41. add_filter( 'bp_get_buddypress_template', array( $this, 'create_template_hierarchy' ) ); 
  42. add_action( 'bp_template_include_reset_dummy_post_data', array( $this, 'create_dummy_post' ) ); 
  43. add_filter( 'bp_replace_the_content', array( $this, 'create_content' ) ); 
  44.  
  45. /** Directory *************************************************************/ 
  46.  
  47. /** 
  48. * Add template hierarchy to theme compat for the blog directory page. 
  49. * This is to mirror how WordPress has 
  50. * {@link https://codex.wordpress.org/Template_Hierarchy template hierarchy}. 
  51. * @since 1.8.0 
  52. * @param string $templates The templates from bp_get_theme_compat_templates(). 
  53. * @return array $templates Array of custom templates to look for. 
  54. */ 
  55. public function directory_template_hierarchy( $templates ) { 
  56.  
  57. /** 
  58. * Filters the custom templates used for theme compat with the blog directory page. 
  59. * @since 1.8.0 
  60. * @param array $value Array of template paths to add to template list to look for. 
  61. */ 
  62. $new_templates = apply_filters( 'bp_template_hierarchy_blogs_create', array( 
  63. 'blogs/index-directory.php' 
  64. ) ); 
  65.  
  66. // Merge new templates with existing stack 
  67. // @see bp_get_theme_compat_templates(). 
  68. $templates = array_merge( (array) $new_templates, $templates ); 
  69.  
  70. return $templates; 
  71.  
  72. /** 
  73. * Update the global $post with directory data. 
  74. * @since 1.7.0 
  75. */ 
  76. public function directory_dummy_post() { 
  77.  
  78. bp_theme_compat_reset_post( array( 
  79. 'ID' => 0,  
  80. 'post_title' => __( 'Sites', 'buddypress' ),  
  81. 'post_author' => 0,  
  82. 'post_date' => 0,  
  83. 'post_content' => '',  
  84. 'post_type' => 'page',  
  85. 'post_status' => 'publish',  
  86. 'is_page' => true,  
  87. 'comment_status' => 'closed' 
  88. ) ); 
  89.  
  90. /** 
  91. * Filter the_content with the groups index template part. 
  92. * @since 1.7.0 
  93. */ 
  94. public function directory_content() { 
  95. return bp_buffer_template_part( 'blogs/index', null, false ); 
  96.  
  97. /** Create ****************************************************************/ 
  98.  
  99. /** 
  100. * Add custom template hierarchy to theme compat for the blog create page. 
  101. * This is to mirror how WordPress has 
  102. * {@link https://codex.wordpress.org/Template_Hierarchy template hierarchy}. 
  103. * @since 1.8.0 
  104. * @param string $templates The templates from bp_get_theme_compat_templates(). 
  105. * @return array $templates Array of custom templates to look for. 
  106. */ 
  107. public function create_template_hierarchy( $templates ) { 
  108.  
  109. /** 
  110. * Filters the custom templates used for theme compat with the blog create page. 
  111. * @since 1.8.0 
  112. * @param array $value Array of template paths to add to template list to look for. 
  113. */ 
  114. $new_templates = apply_filters( 'bp_template_hierarchy_blogs_create', array( 
  115. 'blogs/index-create.php' 
  116. ) ); 
  117.  
  118. // Merge new templates with existing stack 
  119. // @see bp_get_theme_compat_templates(). 
  120. $templates = array_merge( (array) $new_templates, $templates ); 
  121.  
  122. return $templates; 
  123.  
  124. /** 
  125. * Update the global $post with create screen data. 
  126. * @since 1.7.0 
  127. */ 
  128. public function create_dummy_post() { 
  129.  
  130. // Title based on ability to create blogs. 
  131. if ( is_user_logged_in() && bp_blog_signup_enabled() ) { 
  132. $title = __( 'Create a Site', 'buddypress' ); 
  133. } else { 
  134. $title = __( 'Sites', '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( 'blogs/create', null, false );