BP_Core
Creates the Core component.
Description
Source
File: bp-core/classes/class-bp-core.php
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 | class BP_Core extends BP_Component { /** * Start the members component creation process. * * @since BuddyPress 1.5.0 * */ public function __construct() { parent::start( 'core' , __( 'BuddyBoss Core' , 'buddyboss' ), buddypress()->plugin_dir ); $this ->bootstrap(); } /** * Populate the global data needed before BuddyPress can continue. * * This involves figuring out the currently required, activated, deactivated, * and optional components. * * @since BuddyPress 1.5.0 */ private function bootstrap() { /** * Fires before the loading of individual components and after BuddyBoss Core. * * Allows plugins to run code ahead of the other components. * * @since BuddyPress 1.2.0 */ do_action( 'bp_core_loaded' ); $this ->load_components(); $this ->load_integrations(); } /** * Load components files * * @since BuddyBoss 1.0.0 */ private function load_components() { $bp = buddypress(); /** * Filters the included and optional components. * * @since BuddyPress 1.5.0 * * @param array $value Array of included and optional components. */ $bp ->optional_components = apply_filters( 'bp_optional_components' , array_keys (bp_core_get_components( 'optional' ))); /** * Filters the required components. * * @since BuddyPress 1.5.0 * * @param array $value Array of required components. */ $bp ->required_components = apply_filters( 'bp_required_components' , array ( 'members' , 'xprofile' )); // Get a list of activated components. if ( $active_components = bp_get_option( 'bp-active-components' )) { /** This filter is documented in bp-core/admin/bp-core-admin-components.php */ $bp ->active_components = apply_filters( 'bp_active_components' , $active_components ); /** * Filters the deactivated components. * * @since BuddyPress 1.0.0 * * @param array $value Array of deactivated components. */ $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)))); // Pre 1.5 Backwards compatibility. } elseif ( $deactivated_components = bp_get_option( 'bp-deactivated-components' )) { // Trim off namespace and filename. foreach ( array_keys (( array ) $deactivated_components ) as $component ) { $trimmed [] = str_replace ( '.php' , '' , str_replace ( 'bp-' , '' , $component )); } /** This filter is documented in bp-core/bp-core-loader.php */ $bp ->deactivated_components = apply_filters( 'bp_deactivated_components' , $trimmed ); // Setup the active components. $active_components = array_fill_keys( array_diff ( array_values ( array_merge ( $bp ->optional_components, $bp ->required_components)), array_values ( $bp ->deactivated_components)), '1' ); /** This filter is documented in bp-core/admin/bp-core-admin-components.php */ $bp ->active_components = apply_filters( 'bp_active_components' , $bp ->active_components); // Default to all components active. } else { // Set globals. $bp ->deactivated_components = array (); // Setup the active components. $active_components = array_fill_keys( array_values ( array_merge ( $bp ->optional_components, $bp ->required_components)), '1' ); /** This filter is documented in bp-core/admin/bp-core-admin-components.php */ $bp ->active_components = apply_filters( 'bp_active_components' , $bp ->active_components); } // Loop through optional components. foreach ( $bp ->optional_components as $component ) { if (bp_is_active( $component ) && file_exists ( $bp ->plugin_dir . '/bp-' . $component . '/bp-' . $component . '-loader.php' )) { include $bp ->plugin_dir . '/bp-' . $component . '/bp-' . $component . '-loader.php' ; } } // Loop through required components. foreach ( $bp ->required_components as $component ) { if ( file_exists ( $bp ->plugin_dir . '/bp-' . $component . '/bp-' . $component . '-loader.php' )) { include $bp ->plugin_dir . '/bp-' . $component . '/bp-' . $component . '-loader.php' ; } } // Add Core to required components. $bp ->required_components[] = 'core' ; /** * Fires after the loading of individual components. * * @since BuddyPress 2.0.0 */ do_action( 'bp_core_components_included' ); } /** * Load integrations files * * @since BuddyBoss 1.0.0 */ private function load_integrations() { $bp = buddypress(); /** * Filters the included and optional integrations. * * @since BuddyBoss 1.0.0 * * @param array $value Array of included and optional integrations. */ $bp ->available_integrations = apply_filters( 'bp_integrations' , array ( 'appboss' , 'learndash' , )); $integration_dir = $bp ->plugin_dir . '/bp-integrations/' ; foreach ( $bp ->available_integrations as $integration ) { $file = "{$integration_dir}{$integration}/bp-{$integration}-loader.php" ; if ( file_exists ( $file )) { include $file ; } } /** * Fires after the loading of individual integrations. * * @since BuddyBoss 1.0.0 */ do_action( 'bp_core_inetegrations_included' ); } /** * Include bp-core files. * * @since BuddyPress 1.6.0 * * @see BP_Component::includes() for description of parameters. * * @param array $includes See {@link BP_Component::includes()}. */ public function includes( $includes = array ()) { if (!is_admin()) { return ; } $includes = array ( 'admin' , ); parent::includes( $includes ); } /** * Set up bp-core global settings. * * Sets up a majority of the BuddyPress globals that require a minimal * amount of processing, meaning they cannot be set in the BuddyPress class. * * @since BuddyPress 1.5.0 * * @see BP_Component::setup_globals() for description of parameters. * * @param array $args See {@link BP_Component::setup_globals()}. */ public function setup_globals( $args = array ()) { $bp = buddypress(); /** Database ********************************************************* */ // Get the base database prefix. if ( empty ( $bp ->table_prefix)) { $bp ->table_prefix = bp_core_get_table_prefix(); } // The domain for the root of the site where the main blog resides. if ( empty ( $bp ->root_domain)) { $bp ->root_domain = bp_core_get_root_domain(); } // Fetches all of the core BuddyPress settings in one fell swoop. if ( empty ( $bp ->site_options)) { $bp ->site_options = bp_core_get_root_options(); } // The names of the core WordPress pages used to display BuddyPress content. if ( empty ( $bp ->pages)) { $bp ->pages = bp_core_get_directory_pages(); } /** Basic current user data ****************************************** */ // Logged in user is the 'current_user'. $current_user = wp_get_current_user(); // The user ID of the user who is currently logged in. $bp ->loggedin_user = new stdClass; $bp ->loggedin_user->id = isset( $current_user ->ID) ? $current_user ->ID : 0; /** Avatars ********************************************************** */ // Fetches the default Gravatar image to use if the user/group/blog has no avatar or gravatar. $bp ->grav_default = new stdClass; /** * Filters the default user Gravatar. * * @since BuddyPress 1.1.0 * * @param string $value Default user Gravatar. */ $bp ->grav_default->user = apply_filters( 'bp_user_gravatar_default' , $bp ->site_options[ 'avatar_default' ]); /** * Filters the default group Gravatar. * * @since BuddyPress 1.1.0 * * @param string $value Default group Gravatar. */ $bp ->grav_default->group = apply_filters( 'bp_group_gravatar_default' , $bp ->grav_default->user); /** * Filters the default blog Gravatar. * * @since BuddyPress 1.1.0 * * @param string $value Default blog Gravatar. */ $bp ->grav_default->blog = apply_filters( 'bp_blog_gravatar_default' , $bp ->grav_default->user); // Notifications table. Included here for legacy purposes. Use // bp-notifications instead. $bp ->core->table_name_notifications = $bp ->table_prefix . 'bp_notifications' ; // Backward compatibility for plugins modifying the legacy bp_nav and bp_options_nav global properties. $bp ->bp_nav = new BP_Core_BP_Nav_BackCompat(); $bp ->bp_options_nav = new BP_Core_BP_Options_Nav_BackCompat(); /** * Used to determine if user has admin rights on current content. If the * logged in user is viewing their own profile and wants to delete * something, is_item_admin is used. This is a generic variable so it * can be used by other components. It can also be modified, so when * viewing a group 'is_item_admin' would be 'true' if they are a group * admin, and 'false' if they are not. */ bp_update_is_item_admin(bp_user_has_access(), 'core' ); // Is the logged in user is a mod for the current item? bp_update_is_item_mod(false, 'core' ); /** * Fires at the end of the setup of bp-core globals setting. * * @since BuddyPress 1.1.0 */ do_action( 'bp_core_setup_globals' ); } /** * Setup cache groups * * @since BuddyPress 2.2.0 */ public function setup_cache_groups() { // Global groups. wp_cache_add_global_groups( array ( 'bp' , )); parent::setup_cache_groups(); } /** * Set up post types. * * @since BuddyPress BuddyPress (2.4.0) */ public function register_post_types() { // Emails if (bp_is_root_blog() && !is_network_admin()) { register_post_type( bp_get_email_post_type(), apply_filters( 'bp_register_email_post_type' , array ( 'description' => __( 'BuddyBoss emails' , 'buddyboss' ), 'labels' => bp_get_email_post_type_labels(), 'menu_icon' => 'dashicons-email-alt' , 'public' => false, 'publicly_queryable' => bp_current_user_can( 'bp_moderate' ), 'query_var' => false, 'rewrite' => false, 'show_in_admin_bar' => false, 'show_in_menu' => false, 'show_ui' => bp_current_user_can( 'bp_moderate' ), 'supports' => bp_get_email_post_type_supports(), )) ); } if (bp_is_active( 'groups' ) && true === bp_disable_group_type_creation()) { // Register Group Types custom post type. register_post_type( bp_get_group_type_post_type(), apply_filters( 'bp_register_group_type_post_type' , array ( 'description' => __( 'BuddyBoss group type' , 'buddyboss' ), 'labels' => bp_get_group_type_post_type_labels(), 'public' => true, 'publicly_queryable' => bp_current_user_can( 'bp_moderate' ), 'query_var' => false, 'rewrite' => false, 'show_in_admin_bar' => false, 'show_in_menu' => '' , 'map_meta_cap' => true, 'show_in_rest' => true, 'show_ui' => bp_current_user_can( 'bp_moderate' ), 'supports' => bp_get_group_type_post_type_supports(), )) ); } parent::register_post_types(); } } |
Changelog
Version | Description |
---|---|
BuddyPress 1.5.0 | Introduced. |
Methods
- __construct — Start the members component creation process.
- bootstrap — Populate the global data needed before BuddyPress can continue.
- includes — Include bp-core files.
- load_components — Load components files
- load_integrations — Load integrations files
- register_post_types — Set up post types.
- setup_cache_groups — Setup cache groups
- setup_globals — Set up bp-core global settings.
Questions?
We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.