[ Index ] |
PHP Cross Reference of BuddyPress |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * BuddyPress Blogs Theme Compatibility. 4 * 5 * @package BuddyPress 6 * @subpackage BlogsScreens 7 * @since 1.5.0 8 */ 9 10 // Exit if accessed directly. 11 defined( 'ABSPATH' ) || exit; 12 13 /** 14 * The main theme compat class for BuddyPress Blogs. 15 * 16 * This class sets up the necessary theme compatibility actions to safely output 17 * group template parts to the_title and the_content areas of a theme. 18 * 19 * @since 1.7.0 20 */ 21 class BP_Blogs_Theme_Compat { 22 23 /** 24 * Set up theme compatibility for the Blogs component. 25 * 26 * @since 1.7.0 27 */ 28 public function __construct() { 29 add_action( 'bp_setup_theme_compat', array( $this, 'is_blogs' ) ); 30 } 31 32 /** 33 * Are we looking at something that needs Blogs theme compatibility? 34 * 35 * @since 1.7.0 36 */ 37 public function is_blogs() { 38 39 // Bail if not looking at a group. 40 if ( ! bp_is_blogs_component() ) 41 return; 42 43 // Bail if looking at a users sites. 44 if ( bp_is_user() ) 45 return; 46 47 // Blog Directory. 48 if ( is_multisite() && ! bp_current_action() ) { 49 bp_update_is_directory( true, 'blogs' ); 50 51 /** 52 * Fires if in the blog directory and BuddyPress needs Blog theme compatibility, 53 * before the actions and filters are added. 54 * 55 * @since 1.5.0 56 */ 57 do_action( 'bp_blogs_screen_index' ); 58 59 add_filter( 'bp_get_buddypress_template', array( $this, 'directory_template_hierarchy' ) ); 60 add_action( 'bp_template_include_reset_dummy_post_data', array( $this, 'directory_dummy_post' ) ); 61 add_filter( 'bp_replace_the_content', array( $this, 'directory_content' ) ); 62 63 // Create blog. 64 } elseif ( is_user_logged_in() && bp_blog_signup_enabled() ) { 65 add_filter( 'bp_get_buddypress_template', array( $this, 'create_template_hierarchy' ) ); 66 add_action( 'bp_template_include_reset_dummy_post_data', array( $this, 'create_dummy_post' ) ); 67 add_filter( 'bp_replace_the_content', array( $this, 'create_content' ) ); 68 } 69 } 70 71 /** Directory *************************************************************/ 72 73 /** 74 * Add template hierarchy to theme compat for the blog directory page. 75 * 76 * This is to mirror how WordPress has 77 * {@link https://codex.wordpress.org/Template_Hierarchy template hierarchy}. 78 * 79 * @since 1.8.0 80 * 81 * @param string $templates The templates from bp_get_theme_compat_templates(). 82 * @return array $templates Array of custom templates to look for. 83 */ 84 public function directory_template_hierarchy( $templates ) { 85 86 /** 87 * Filters the custom templates used for theme compat with the blog directory page. 88 * 89 * @since 1.8.0 90 * 91 * @param array $value Array of template paths to add to template list to look for. 92 */ 93 $new_templates = apply_filters( 'bp_template_hierarchy_blogs_create', array( 94 'blogs/index-directory.php' 95 ) ); 96 97 // Merge new templates with existing stack 98 // @see bp_get_theme_compat_templates(). 99 $templates = array_merge( (array) $new_templates, $templates ); 100 101 return $templates; 102 } 103 104 /** 105 * Update the global $post with directory data. 106 * 107 * @since 1.7.0 108 */ 109 public function directory_dummy_post() { 110 111 bp_theme_compat_reset_post( array( 112 'ID' => 0, 113 'post_title' => __( 'Sites', 'buddypress' ), 114 'post_author' => 0, 115 'post_date' => 0, 116 'post_content' => '', 117 'post_type' => 'page', 118 'post_status' => 'publish', 119 'is_page' => true, 120 'comment_status' => 'closed' 121 ) ); 122 } 123 124 /** 125 * Filter the_content with the groups index template part. 126 * 127 * @since 1.7.0 128 */ 129 public function directory_content() { 130 return bp_buffer_template_part( 'blogs/index', null, false ); 131 } 132 133 /** Create ****************************************************************/ 134 135 /** 136 * Add custom template hierarchy to theme compat for the blog create page. 137 * 138 * This is to mirror how WordPress has 139 * {@link https://codex.wordpress.org/Template_Hierarchy template hierarchy}. 140 * 141 * @since 1.8.0 142 * 143 * @param string $templates The templates from bp_get_theme_compat_templates(). 144 * @return array $templates Array of custom templates to look for. 145 */ 146 public function create_template_hierarchy( $templates ) { 147 148 /** 149 * Filters the custom templates used for theme compat with the blog create page. 150 * 151 * @since 1.8.0 152 * 153 * @param array $value Array of template paths to add to template list to look for. 154 */ 155 $new_templates = apply_filters( 'bp_template_hierarchy_blogs_create', array( 156 'blogs/index-create.php' 157 ) ); 158 159 // Merge new templates with existing stack 160 // @see bp_get_theme_compat_templates(). 161 $templates = array_merge( (array) $new_templates, $templates ); 162 163 return $templates; 164 } 165 166 /** 167 * Update the global $post with create screen data. 168 * 169 * @since 1.7.0 170 */ 171 public function create_dummy_post() { 172 173 // Title based on ability to create blogs. 174 if ( is_user_logged_in() && bp_blog_signup_enabled() ) { 175 $title = __( 'Create a Site', 'buddypress' ); 176 } else { 177 $title = __( 'Sites', 'buddypress' ); 178 } 179 180 bp_theme_compat_reset_post( array( 181 'ID' => 0, 182 'post_title' => $title, 183 'post_author' => 0, 184 'post_date' => 0, 185 'post_content' => '', 186 'post_type' => 'page', 187 'post_status' => 'publish', 188 'is_page' => true, 189 'comment_status' => 'closed' 190 ) ); 191 } 192 193 /** 194 * Filter the_content with the create screen template part. 195 * 196 * @since 1.7.0 197 */ 198 public function create_content() { 199 return bp_buffer_template_part( 'blogs/create', null, false ); 200 } 201 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sat Dec 14 01:00:55 2024 | Cross-referenced by PHPXref 0.7.1 |