[ Index ] |
PHP Cross Reference of BuddyPress |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * BuddyPress Blogs Loader 4 * 5 * The blogs component tracks posts and comments to member activity streams, 6 * shows blogs the member can post to in their profiles, and caches useful 7 * information from those blogs to make querying blogs in bulk more performant. 8 * 9 * @package BuddyPress 10 * @subpackage BlogsCore 11 * @since 1.5.0 12 */ 13 14 // Exit if accessed directly. 15 defined( 'ABSPATH' ) || exit; 16 17 /** 18 * Creates our Blogs component. 19 */ 20 class BP_Blogs_Component extends BP_Component { 21 22 /** 23 * Start the blogs component creation process. 24 * 25 * @since 1.5.0 26 */ 27 public function __construct() { 28 parent::start( 29 'blogs', 30 __( 'Site Directory', 'buddypress' ), 31 buddypress()->plugin_dir, 32 array( 33 'adminbar_myaccount_order' => 30, 34 'search_query_arg' => 'sites_search', 35 'features' => array( 'site-icon' ) 36 ) 37 ); 38 } 39 40 /** 41 * Set up global settings for the blogs component. 42 * 43 * The BP_BLOGS_SLUG constant is deprecated, and only used here for 44 * backwards compatibility. 45 * 46 * @since 1.5.0 47 * 48 * @see BP_Component::setup_globals() for description of parameters. 49 * 50 * @param array $args See {@link BP_Component::setup_globals()}. 51 */ 52 public function setup_globals( $args = array() ) { 53 $bp = buddypress(); 54 55 if ( ! defined( 'BP_BLOGS_SLUG' ) ) { 56 define ( 'BP_BLOGS_SLUG', $this->id ); 57 } 58 59 // Global tables for messaging component. 60 $global_tables = array( 61 'table_name' => $bp->table_prefix . 'bp_user_blogs', 62 'table_name_blogmeta' => $bp->table_prefix . 'bp_user_blogs_blogmeta', 63 ); 64 65 $meta_tables = array( 66 'bp_blog' => $bp->table_prefix . 'bp_user_blogs_blogmeta', 67 ); 68 69 // Fetch the default directory title. 70 $default_directory_titles = bp_core_get_directory_page_default_titles(); 71 $default_directory_title = $default_directory_titles[$this->id]; 72 73 // All globals for blogs component. 74 $args = array( 75 'slug' => BP_BLOGS_SLUG, 76 'root_slug' => isset( $bp->pages->blogs->slug ) ? $bp->pages->blogs->slug : BP_BLOGS_SLUG, 77 'has_directory' => is_multisite(), // Non-multisite installs don't need a top-level Sites directory, since there's only one site. 78 'directory_title' => isset( $bp->pages->blogs->title ) ? $bp->pages->blogs->title : $default_directory_title, 79 'notification_callback' => 'bp_blogs_format_notifications', 80 'search_string' => __( 'Search sites...', 'buddypress' ), 81 'autocomplete_all' => defined( 'BP_MESSAGES_AUTOCOMPLETE_ALL' ), 82 'global_tables' => $global_tables, 83 'meta_tables' => $meta_tables, 84 ); 85 86 // Setup the globals. 87 parent::setup_globals( $args ); 88 89 /** 90 * Filters if a blog is public. 91 * 92 * In case the config is not multisite, the blog_public option is ignored. 93 * 94 * @since 2.3.0 95 * 96 * @param int $value Whether or not the blog is public. 97 */ 98 if ( 0 !== apply_filters( 'bp_is_blog_public', (int) get_option( 'blog_public' ) ) || ! is_multisite() ) { 99 100 /** 101 * Filters the post types to track for the Blogs component. 102 * 103 * @since 1.5.0 104 * @deprecated 2.3.0 105 * 106 * @param array $value Array of post types to track. 107 */ 108 $post_types = apply_filters( 'bp_blogs_record_post_post_types', array( 'post' ) ); 109 110 foreach ( $post_types as $post_type ) { 111 add_post_type_support( $post_type, 'buddypress-activity' ); 112 } 113 } 114 } 115 116 /** 117 * Include bp-blogs files. 118 * 119 * @see BP_Component::includes() for description of parameters. 120 * 121 * @param array $includes See {@link BP_Component::includes()}. 122 */ 123 public function includes( $includes = array() ) { 124 125 // Files to include. 126 $includes = array( 127 'cache', 128 'template', 129 'filters', 130 'functions', 131 ); 132 133 if ( bp_is_active( 'activity' ) ) { 134 $includes[] = 'activity'; 135 } 136 137 if ( is_multisite() ) { 138 $includes[] = 'widgets'; 139 } 140 141 // Include the files. 142 parent::includes( $includes ); 143 } 144 145 /** 146 * Late includes method. 147 * 148 * Only load up certain code when on specific pages. 149 * 150 * @since 3.0.0 151 */ 152 public function late_includes() { 153 // Bail if PHPUnit is running. 154 if ( defined( 'BP_TESTS_DIR' ) ) { 155 return; 156 } 157 158 // Bail if not on a blogs page or not multisite. 159 if ( ! bp_is_blogs_component() || ! is_multisite() ) { 160 return; 161 } 162 163 // Actions. 164 if ( isset( $_GET['random-blog'] ) ) { 165 require $this->path . 'bp-blogs/actions/random.php'; 166 } 167 168 // Screens. 169 if ( bp_is_user() ) { 170 require $this->path . 'bp-blogs/screens/my-blogs.php'; 171 } else { 172 if ( bp_is_blogs_directory() ) { 173 require $this->path . 'bp-blogs/screens/directory.php'; 174 } 175 176 if ( is_user_logged_in() && bp_is_current_action( 'create' ) ) { 177 require $this->path . 'bp-blogs/screens/create.php'; 178 } 179 180 // Theme compatibility. 181 new BP_Blogs_Theme_Compat(); 182 } 183 } 184 185 /** 186 * Set up component navigation for bp-blogs. 187 * 188 * @see BP_Component::setup_nav() for a description of arguments. 189 * 190 * @param array $main_nav Optional. See BP_Component::setup_nav() for 191 * description. 192 * @param array $sub_nav Optional. See BP_Component::setup_nav() for 193 * description. 194 */ 195 public function setup_nav( $main_nav = array(), $sub_nav = array() ) { 196 197 /** 198 * Blog/post/comment menus should not appear on single WordPress setups. 199 * Although comments and posts made by users will still show on their 200 * activity stream. 201 */ 202 if ( ! is_multisite() ) { 203 return false; 204 } 205 206 // Determine user to use. 207 if ( bp_displayed_user_domain() ) { 208 $user_domain = bp_displayed_user_domain(); 209 } elseif ( bp_loggedin_user_domain() ) { 210 $user_domain = bp_loggedin_user_domain(); 211 } else { 212 return; 213 } 214 215 $slug = bp_get_blogs_slug(); 216 $parent_url = trailingslashit( $user_domain . $slug ); 217 218 // Add 'Sites' to the main navigation. 219 $count = (int) bp_get_total_blog_count_for_user(); 220 $class = ( 0 === $count ) ? 'no-count' : 'count'; 221 $nav_text = sprintf( 222 /* translators: %s: Site count for the current user */ 223 __( 'Sites %s', 'buddypress' ), 224 sprintf( 225 '<span class="%s">%s</span>', 226 esc_attr( $class ), 227 esc_html( $count ) 228 ) 229 ); 230 $main_nav = array( 231 'name' => $nav_text, 232 'slug' => $slug, 233 'position' => 30, 234 'screen_function' => 'bp_blogs_screen_my_blogs', 235 'default_subnav_slug' => 'my-sites', 236 'item_css_id' => $this->id 237 ); 238 239 $sub_nav[] = array( 240 'name' => __( 'My Sites', 'buddypress' ), 241 'slug' => 'my-sites', 242 'parent_url' => $parent_url, 243 'parent_slug' => $slug, 244 'screen_function' => 'bp_blogs_screen_my_blogs', 245 'position' => 10 246 ); 247 248 // Setup navigation. 249 parent::setup_nav( $main_nav, $sub_nav ); 250 } 251 252 /** 253 * Set up bp-blogs integration with the WordPress admin bar. 254 * 255 * @since 1.5.0 256 * 257 * @see BP_Component::setup_admin_bar() for a description of arguments. 258 * 259 * @param array $wp_admin_nav See BP_Component::setup_admin_bar() 260 * for description. 261 * @return bool 262 */ 263 public function setup_admin_bar( $wp_admin_nav = array() ) { 264 265 /** 266 * Site/post/comment menus should not appear on single WordPress setups. 267 * 268 * Comments and posts made by users will still show in their activity. 269 */ 270 if ( ! is_multisite() ) { 271 return false; 272 } 273 274 // Menus for logged in user. 275 if ( is_user_logged_in() ) { 276 277 // Setup the logged in user variables. 278 $blogs_link = trailingslashit( bp_loggedin_user_domain() . bp_get_blogs_slug() ); 279 280 // Add the "Sites" sub menu. 281 $wp_admin_nav[] = array( 282 'parent' => buddypress()->my_account_menu_id, 283 'id' => 'my-account-' . $this->id, 284 'title' => __( 'Sites', 'buddypress' ), 285 'href' => $blogs_link 286 ); 287 288 // My Sites. 289 $wp_admin_nav[] = array( 290 'parent' => 'my-account-' . $this->id, 291 'id' => 'my-account-' . $this->id . '-my-sites', 292 'title' => __( 'My Sites', 'buddypress' ), 293 'href' => $blogs_link, 294 'position' => 10 295 ); 296 297 // Create a Site. 298 if ( bp_blog_signup_enabled() ) { 299 $wp_admin_nav[] = array( 300 'parent' => 'my-account-' . $this->id, 301 'id' => 'my-account-' . $this->id . '-create', 302 'title' => __( 'Create a Site', 'buddypress' ), 303 'href' => trailingslashit( bp_get_blogs_directory_permalink() . 'create' ), 304 'position' => 99 305 ); 306 } 307 } 308 309 parent::setup_admin_bar( $wp_admin_nav ); 310 } 311 312 /** 313 * Set up the title for pages and <title>. 314 */ 315 public function setup_title() { 316 317 // Set up the component options navigation for Site. 318 if ( bp_is_blogs_component() ) { 319 $bp = buddypress(); 320 321 if ( bp_is_my_profile() ) { 322 if ( bp_is_active( 'xprofile' ) ) { 323 $bp->bp_options_title = __( 'My Sites', 'buddypress' ); 324 } 325 326 // If we are not viewing the logged in user, set up the current 327 // users avatar and name. 328 } else { 329 $bp->bp_options_avatar = bp_core_fetch_avatar( array( 330 'item_id' => bp_displayed_user_id(), 331 'type' => 'thumb', 332 'alt' => sprintf( 333 /* translators: %s: member name */ 334 __( 'Profile picture of %s', 'buddypress' ), 335 bp_get_displayed_user_fullname() 336 ), 337 ) ); 338 $bp->bp_options_title = bp_get_displayed_user_fullname(); 339 } 340 } 341 342 parent::setup_title(); 343 } 344 345 /** 346 * Setup cache groups 347 * 348 * @since 2.2.0 349 */ 350 public function setup_cache_groups() { 351 352 // Global groups. 353 wp_cache_add_global_groups( array( 354 'bp_blog_meta' 355 ) ); 356 357 parent::setup_cache_groups(); 358 } 359 360 /** 361 * Init the BP REST API. 362 * 363 * @since 6.0.0 364 * 365 * @param array $controllers Optional. See BP_Component::rest_api_init() for 366 * description. 367 */ 368 public function rest_api_init( $controllers = array() ) { 369 if ( is_multisite() ) { 370 $controllers = array( 371 'BP_REST_Blogs_Endpoint', 372 ); 373 374 // Support to Blog Avatar. 375 if ( bp_is_active( 'blogs', 'site-icon' ) ) { 376 $controllers[] = 'BP_REST_Attachments_Blog_Avatar_Endpoint'; 377 } 378 } 379 380 parent::rest_api_init( $controllers ); 381 } 382 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Jan 17 01:01:36 2021 | Cross-referenced by PHPXref 0.7.1 |