[ Index ] |
PHP Cross Reference of BuddyPress |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * BuddyPress Core Loader. 4 * 5 * Core contains the commonly used functions, classes, and APIs. 6 * 7 * @package BuddyPress 8 * @subpackage Core 9 * @since 1.5.0 10 */ 11 12 // Exit if accessed directly. 13 defined( 'ABSPATH' ) || exit; 14 15 /** 16 * Creates the Core component. 17 * 18 * @since 1.5.0 19 */ 20 class BP_Core extends BP_Component { 21 22 /** 23 * Start the members component creation process. 24 * 25 * @since 1.5.0 26 * 27 */ 28 public function __construct() { 29 parent::start( 30 'core', 31 __( 'BuddyPress Core', 'buddypress' ), 32 buddypress()->plugin_dir 33 ); 34 35 $this->bootstrap(); 36 } 37 38 /** 39 * Magic getter. 40 * 41 * This exists specifically for supporting deprecated object vars. 42 * 43 * @since 7.0.0 44 * 45 * @param string $key 46 * @return mixed 47 */ 48 public function __get( $key = '' ) { 49 50 // Backwards compatibility for the original Notifications table var 51 if ( 'table_name_notifications' === $key ) { 52 return bp_is_active( 'notifications' ) 53 ? buddypress()->notifications->table_name 54 : buddypress()->table_prefix . 'bp_notifications'; 55 } 56 57 // Return object var if set, else null 58 return isset( $this->{$key} ) 59 ? $this->{$key} 60 : null; 61 } 62 63 /** 64 * Populate the global data needed before BuddyPress can continue. 65 * 66 * This involves figuring out the currently required, activated, deactivated, 67 * and optional components. 68 * 69 * @since 1.5.0 70 */ 71 private function bootstrap() { 72 $bp = buddypress(); 73 74 /** 75 * Fires before the loading of individual components and after BuddyPress Core. 76 * 77 * Allows plugins to run code ahead of the other components. 78 * 79 * @since 1.2.0 80 */ 81 do_action( 'bp_core_loaded' ); 82 83 /** Components ******************************************************* 84 */ 85 86 /** 87 * Filters the included and optional components. 88 * 89 * @since 1.5.0 90 * 91 * @param array $value Array of included and optional components. 92 */ 93 $bp->optional_components = apply_filters( 'bp_optional_components', array( 'activity', 'blogs', 'friends', 'groups', 'messages', 'notifications', 'settings', 'xprofile' ) ); 94 95 /** 96 * Filters the required components. 97 * 98 * @since 1.5.0 99 * 100 * @param array $value Array of required components. 101 */ 102 $bp->required_components = apply_filters( 'bp_required_components', array( 'members' ) ); 103 104 // Get a list of activated components. 105 if ( $active_components = bp_get_option( 'bp-active-components' ) ) { 106 107 /** This filter is documented in bp-core/admin/bp-core-admin-components.php */ 108 $bp->active_components = apply_filters( 'bp_active_components', $active_components ); 109 110 /** 111 * Filters the deactivated components. 112 * 113 * @since 1.0.0 114 * 115 * @param array $value Array of deactivated components. 116 */ 117 $bp->deactivated_components = apply_filters( 'bp_deactivated_components', array_values( array_diff( array_values( array_merge( $bp->optional_components, $bp->required_components ) ), array_keys( $bp->active_components ) ) ) ); 118 119 // Pre 1.5 Backwards compatibility. 120 } elseif ( $deactivated_components = bp_get_option( 'bp-deactivated-components' ) ) { 121 122 // Trim off namespace and filename. 123 foreach ( array_keys( (array) $deactivated_components ) as $component ) { 124 $trimmed[] = str_replace( '.php', '', str_replace( 'bp-', '', $component ) ); 125 } 126 127 /** This filter is documented in bp-core/bp-core-loader.php */ 128 $bp->deactivated_components = apply_filters( 'bp_deactivated_components', $trimmed ); 129 130 // Setup the active components. 131 $active_components = array_fill_keys( array_diff( array_values( array_merge( $bp->optional_components, $bp->required_components ) ), array_values( $bp->deactivated_components ) ), '1' ); 132 133 /** This filter is documented in bp-core/admin/bp-core-admin-components.php */ 134 $bp->active_components = apply_filters( 'bp_active_components', $bp->active_components ); 135 136 // Default to all components active. 137 } else { 138 139 // Set globals. 140 $bp->deactivated_components = array(); 141 142 // Setup the active components. 143 $active_components = array_fill_keys( array_values( array_merge( $bp->optional_components, $bp->required_components ) ), '1' ); 144 145 /** This filter is documented in bp-core/admin/bp-core-admin-components.php */ 146 $bp->active_components = apply_filters( 'bp_active_components', $bp->active_components ); 147 } 148 149 // Loop through optional components. 150 foreach( $bp->optional_components as $component ) { 151 if ( bp_is_active( $component ) && file_exists( $bp->plugin_dir . '/bp-' . $component . '/bp-' . $component . '-loader.php' ) ) { 152 include( $bp->plugin_dir . '/bp-' . $component . '/bp-' . $component . '-loader.php' ); 153 } 154 } 155 156 // Loop through required components. 157 foreach( $bp->required_components as $component ) { 158 if ( file_exists( $bp->plugin_dir . '/bp-' . $component . '/bp-' . $component . '-loader.php' ) ) { 159 include( $bp->plugin_dir . '/bp-' . $component . '/bp-' . $component . '-loader.php' ); 160 } 161 } 162 163 // Add Core to required components. 164 $bp->required_components[] = 'core'; 165 166 /** 167 * Fires after the loading of individual components. 168 * 169 * @since 2.0.0 170 */ 171 do_action( 'bp_core_components_included' ); 172 } 173 174 /** 175 * Include bp-core files. 176 * 177 * @since 1.6.0 178 * 179 * @see BP_Component::includes() for description of parameters. 180 * 181 * @param array $includes See {@link BP_Component::includes()}. 182 */ 183 public function includes( $includes = array() ) { 184 185 if ( ! is_admin() ) { 186 return; 187 } 188 189 $includes = array( 190 'admin' 191 ); 192 193 parent::includes( $includes ); 194 } 195 196 /** 197 * Set up bp-core global settings. 198 * 199 * Sets up a majority of the BuddyPress globals that require a minimal 200 * amount of processing, meaning they cannot be set in the BuddyPress class. 201 * 202 * @since 1.5.0 203 * 204 * @see BP_Component::setup_globals() for description of parameters. 205 * 206 * @param array $args See {@link BP_Component::setup_globals()}. 207 */ 208 public function setup_globals( $args = array() ) { 209 $bp = buddypress(); 210 211 /** Database ********************************************************* 212 */ 213 214 // Get the base database prefix. 215 if ( empty( $bp->table_prefix ) ) { 216 $bp->table_prefix = bp_core_get_table_prefix(); 217 } 218 219 // The domain for the root of the site where the main blog resides. 220 if ( empty( $bp->root_domain ) ) { 221 $bp->root_domain = bp_core_get_root_domain(); 222 } 223 224 // Fetches all of the core BuddyPress settings in one fell swoop. 225 if ( empty( $bp->site_options ) ) { 226 $bp->site_options = bp_core_get_root_options(); 227 } 228 229 // The names of the core WordPress pages used to display BuddyPress content. 230 if ( empty( $bp->pages ) ) { 231 $bp->pages = bp_core_get_directory_pages(); 232 } 233 234 /** Basic current user data ****************************************** 235 */ 236 237 // Logged in user is the 'current_user'. 238 $current_user = wp_get_current_user(); 239 240 // The user ID of the user who is currently logged in. 241 $bp->loggedin_user = new stdClass; 242 $bp->loggedin_user->id = isset( $current_user->ID ) ? $current_user->ID : 0; 243 244 /** Avatars ********************************************************** 245 */ 246 247 // Fetches the default Gravatar image to use if the user/group/blog has no avatar or gravatar. 248 $bp->grav_default = new stdClass; 249 250 /** 251 * Filters the default user Gravatar. 252 * 253 * @since 1.1.0 254 * 255 * @param string $value Default user Gravatar. 256 */ 257 $bp->grav_default->user = apply_filters( 'bp_user_gravatar_default', $bp->site_options['avatar_default'] ); 258 259 /** 260 * Filters the default group Gravatar. 261 * 262 * @since 1.1.0 263 * 264 * @param string $value Default group Gravatar. 265 */ 266 $bp->grav_default->group = apply_filters( 'bp_group_gravatar_default', $bp->grav_default->user ); 267 268 /** 269 * Filters the default blog Gravatar. 270 * 271 * @since 1.1.0 272 * 273 * @param string $value Default blog Gravatar. 274 */ 275 $bp->grav_default->blog = apply_filters( 'bp_blog_gravatar_default', $bp->grav_default->user ); 276 277 // Backward compatibility for plugins modifying the legacy bp_nav and bp_options_nav global properties. 278 $bp->bp_nav = new BP_Core_BP_Nav_BackCompat(); 279 $bp->bp_options_nav = new BP_Core_BP_Options_Nav_BackCompat(); 280 281 /** 282 * Used to determine if user has admin rights on current content. If the 283 * logged in user is viewing their own profile and wants to delete 284 * something, is_item_admin is used. This is a generic variable so it 285 * can be used by other components. It can also be modified, so when 286 * viewing a group 'is_item_admin' would be 'true' if they are a group 287 * admin, and 'false' if they are not. 288 */ 289 bp_update_is_item_admin( bp_user_has_access(), 'core' ); 290 291 // Is the logged in user is a mod for the current item? 292 bp_update_is_item_mod( false, 'core' ); 293 294 parent::setup_globals( 295 array( 296 'block_globals' => array( 297 'bp/login-form' => array( 298 'widget_classnames' => array( 'widget_bp_core_login_widget', 'buddypress' ), 299 ), 300 ), 301 ) 302 ); 303 } 304 305 /** 306 * Setup cache groups 307 * 308 * @since 2.2.0 309 */ 310 public function setup_cache_groups() { 311 312 // Global groups. 313 wp_cache_add_global_groups( array( 314 'bp' 315 ) ); 316 317 parent::setup_cache_groups(); 318 } 319 320 /** 321 * Set up post types. 322 * 323 * @since BuddyPress (2.4.0) 324 */ 325 public function register_post_types() { 326 327 // Emails 328 if ( bp_is_root_blog() && ! is_network_admin() ) { 329 register_post_type( 330 bp_get_email_post_type(), 331 apply_filters( 'bp_register_email_post_type', array( 332 'description' => _x( 'BuddyPress emails', 'email post type description', 'buddypress' ), 333 'capabilities' => array( 334 'edit_posts' => 'bp_moderate', 335 'edit_others_posts' => 'bp_moderate', 336 'publish_posts' => 'bp_moderate', 337 'read_private_posts' => 'bp_moderate', 338 'delete_posts' => 'bp_moderate', 339 'delete_others_posts' => 'bp_moderate', 340 ), 341 'map_meta_cap' => true, 342 'labels' => bp_get_email_post_type_labels(), 343 'menu_icon' => 'dashicons-email', 344 'public' => false, 345 'publicly_queryable' => bp_current_user_can( 'bp_moderate' ), 346 'query_var' => false, 347 'rewrite' => false, 348 'show_in_admin_bar' => false, 349 'show_ui' => bp_current_user_can( 'bp_moderate' ), 350 'supports' => bp_get_email_post_type_supports(), 351 ) ) 352 ); 353 } 354 355 parent::register_post_types(); 356 } 357 358 /** 359 * Init the Core controllers of the BP REST API. 360 * 361 * @since 9.0.0 362 * 363 * @param array $controllers Optional. See BP_Component::rest_api_init() for 364 * description. 365 */ 366 public function rest_api_init( $controllers = array() ) { 367 $controllers = array( 368 'BP_REST_Components_Endpoint', 369 ); 370 371 parent::rest_api_init( $controllers ); 372 } 373 374 /** 375 * Register the BP Core Blocks. 376 * 377 * @since 9.0.0 378 * 379 * @param array $blocks Optional. See BP_Component::blocks_init() for 380 * description. 381 */ 382 public function blocks_init( $blocks = array() ) { 383 parent::blocks_init( 384 array( 385 'bp/login-form' => array( 386 'name' => 'bp/login-form', 387 'editor_script' => 'bp-login-form-block', 388 'editor_script_url' => plugins_url( 'js/blocks/login-form.js', dirname( __FILE__ ) ), 389 'editor_script_deps' => array( 390 'wp-blocks', 391 'wp-element', 392 'wp-components', 393 'wp-i18n', 394 'wp-block-editor', 395 'wp-server-side-render', 396 ), 397 'style' => 'bp-login-form-block', 398 'style_url' => plugins_url( 'css/blocks/login-form.css', dirname( __FILE__ ) ), 399 'attributes' => array( 400 'title' => array( 401 'type' => 'string', 402 'default' => '', 403 ), 404 'forgotPwdLink' => array( 405 'type' => 'boolean', 406 'default' => false, 407 ), 408 ), 409 'render_callback' => 'bp_block_render_login_form_block', 410 ), 411 ) 412 ); 413 } 414 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Nov 21 01:00:57 2024 | Cross-referenced by PHPXref 0.7.1 |