[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

/src/bp-core/classes/ -> class-bp-core.php (source)

   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       * Populate the global data needed before BuddyPress can continue.
  40       *
  41       * This involves figuring out the currently required, activated, deactivated,
  42       * and optional components.
  43       *
  44       * @since 1.5.0
  45       */
  46  	private function bootstrap() {
  47          $bp = buddypress();
  48  
  49          /**
  50           * Fires before the loading of individual components and after BuddyPress Core.
  51           *
  52           * Allows plugins to run code ahead of the other components.
  53           *
  54           * @since 1.2.0
  55           */
  56          do_action( 'bp_core_loaded' );
  57  
  58          /** Components *******************************************************
  59           */
  60  
  61          /**
  62           * Filters the included and optional components.
  63           *
  64           * @since 1.5.0
  65           *
  66           * @param array $value Array of included and optional components.
  67           */
  68          $bp->optional_components = apply_filters( 'bp_optional_components', array( 'activity', 'blogs', 'friends', 'groups', 'messages', 'notifications', 'settings', 'xprofile' ) );
  69  
  70          /**
  71           * Filters the required components.
  72           *
  73           * @since 1.5.0
  74           *
  75           * @param array $value Array of required components.
  76           */
  77          $bp->required_components = apply_filters( 'bp_required_components', array( 'members' ) );
  78  
  79          // Get a list of activated components.
  80          if ( $active_components = bp_get_option( 'bp-active-components' ) ) {
  81  
  82              /** This filter is documented in bp-core/admin/bp-core-admin-components.php */
  83              $bp->active_components      = apply_filters( 'bp_active_components', $active_components );
  84  
  85              /**
  86               * Filters the deactivated components.
  87               *
  88               * @since 1.0.0
  89               *
  90               * @param array $value Array of deactivated components.
  91               */
  92              $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 ) ) ) );
  93  
  94          // Pre 1.5 Backwards compatibility.
  95          } elseif ( $deactivated_components = bp_get_option( 'bp-deactivated-components' ) ) {
  96  
  97              // Trim off namespace and filename.
  98              foreach ( array_keys( (array) $deactivated_components ) as $component ) {
  99                  $trimmed[] = str_replace( '.php', '', str_replace( 'bp-', '', $component ) );
 100              }
 101  
 102              /** This filter is documented in bp-core/bp-core-loader.php */
 103              $bp->deactivated_components = apply_filters( 'bp_deactivated_components', $trimmed );
 104  
 105              // Setup the active components.
 106              $active_components     = array_fill_keys( array_diff( array_values( array_merge( $bp->optional_components, $bp->required_components ) ), array_values( $bp->deactivated_components ) ), '1' );
 107  
 108              /** This filter is documented in bp-core/admin/bp-core-admin-components.php */
 109              $bp->active_components = apply_filters( 'bp_active_components', $bp->active_components );
 110  
 111          // Default to all components active.
 112          } else {
 113  
 114              // Set globals.
 115              $bp->deactivated_components = array();
 116  
 117              // Setup the active components.
 118              $active_components     = array_fill_keys( array_values( array_merge( $bp->optional_components, $bp->required_components ) ), '1' );
 119  
 120              /** This filter is documented in bp-core/admin/bp-core-admin-components.php */
 121              $bp->active_components = apply_filters( 'bp_active_components', $bp->active_components );
 122          }
 123  
 124          // Loop through optional components.
 125          foreach( $bp->optional_components as $component ) {
 126              if ( bp_is_active( $component ) && file_exists( $bp->plugin_dir . '/bp-' . $component . '/bp-' . $component . '-loader.php' ) ) {
 127                  include( $bp->plugin_dir . '/bp-' . $component . '/bp-' . $component . '-loader.php' );
 128              }
 129          }
 130  
 131          // Loop through required components.
 132          foreach( $bp->required_components as $component ) {
 133              if ( file_exists( $bp->plugin_dir . '/bp-' . $component . '/bp-' . $component . '-loader.php' ) ) {
 134                  include( $bp->plugin_dir . '/bp-' . $component . '/bp-' . $component . '-loader.php' );
 135              }
 136          }
 137  
 138          // Add Core to required components.
 139          $bp->required_components[] = 'core';
 140  
 141          /**
 142           * Fires after the loading of individual components.
 143           *
 144           * @since 2.0.0
 145           */
 146          do_action( 'bp_core_components_included' );
 147      }
 148  
 149      /**
 150       * Include bp-core files.
 151       *
 152       * @since 1.6.0
 153       *
 154       * @see BP_Component::includes() for description of parameters.
 155       *
 156       * @param array $includes See {@link BP_Component::includes()}.
 157       */
 158  	public function includes( $includes = array() ) {
 159  
 160          if ( ! is_admin() ) {
 161              return;
 162          }
 163  
 164          $includes = array(
 165              'admin'
 166          );
 167  
 168          parent::includes( $includes );
 169      }
 170  
 171      /**
 172       * Set up bp-core global settings.
 173       *
 174       * Sets up a majority of the BuddyPress globals that require a minimal
 175       * amount of processing, meaning they cannot be set in the BuddyPress class.
 176       *
 177       * @since 1.5.0
 178       *
 179       * @see BP_Component::setup_globals() for description of parameters.
 180       *
 181       * @param array $args See {@link BP_Component::setup_globals()}.
 182       */
 183  	public function setup_globals( $args = array() ) {
 184          $bp = buddypress();
 185  
 186          /** Database *********************************************************
 187           */
 188  
 189          // Get the base database prefix.
 190          if ( empty( $bp->table_prefix ) ) {
 191              $bp->table_prefix = bp_core_get_table_prefix();
 192          }
 193  
 194          // The domain for the root of the site where the main blog resides.
 195          if ( empty( $bp->root_domain ) ) {
 196              $bp->root_domain = bp_core_get_root_domain();
 197          }
 198  
 199          // Fetches all of the core BuddyPress settings in one fell swoop.
 200          if ( empty( $bp->site_options ) ) {
 201              $bp->site_options = bp_core_get_root_options();
 202          }
 203  
 204          // The names of the core WordPress pages used to display BuddyPress content.
 205          if ( empty( $bp->pages ) ) {
 206              $bp->pages = bp_core_get_directory_pages();
 207          }
 208  
 209          /** Basic current user data ******************************************
 210           */
 211  
 212          // Logged in user is the 'current_user'.
 213          $current_user            = wp_get_current_user();
 214  
 215          // The user ID of the user who is currently logged in.
 216          $bp->loggedin_user       = new stdClass;
 217          $bp->loggedin_user->id   = isset( $current_user->ID ) ? $current_user->ID : 0;
 218  
 219          /** Avatars **********************************************************
 220           */
 221  
 222          // Fetches the default Gravatar image to use if the user/group/blog has no avatar or gravatar.
 223          $bp->grav_default        = new stdClass;
 224  
 225          /**
 226           * Filters the default user Gravatar.
 227           *
 228           * @since 1.1.0
 229           *
 230           * @param string $value Default user Gravatar.
 231           */
 232          $bp->grav_default->user  = apply_filters( 'bp_user_gravatar_default',  $bp->site_options['avatar_default'] );
 233  
 234          /**
 235           * Filters the default group Gravatar.
 236           *
 237           * @since 1.1.0
 238           *
 239           * @param string $value Default group Gravatar.
 240           */
 241          $bp->grav_default->group = apply_filters( 'bp_group_gravatar_default', $bp->grav_default->user );
 242  
 243          /**
 244           * Filters the default blog Gravatar.
 245           *
 246           * @since 1.1.0
 247           *
 248           * @param string $value Default blog Gravatar.
 249           */
 250          $bp->grav_default->blog  = apply_filters( 'bp_blog_gravatar_default',  $bp->grav_default->user );
 251  
 252          // Notifications table. Included here for legacy purposes. Use
 253          // bp-notifications instead.
 254          $bp->core->table_name_notifications = $bp->table_prefix . 'bp_notifications';
 255  
 256          // Backward compatibility for plugins modifying the legacy bp_nav and bp_options_nav global properties.
 257          $bp->bp_nav         = new BP_Core_BP_Nav_BackCompat();
 258          $bp->bp_options_nav = new BP_Core_BP_Options_Nav_BackCompat();
 259  
 260          /**
 261           * Used to determine if user has admin rights on current content. If the
 262           * logged in user is viewing their own profile and wants to delete
 263           * something, is_item_admin is used. This is a generic variable so it
 264           * can be used by other components. It can also be modified, so when
 265           * viewing a group 'is_item_admin' would be 'true' if they are a group
 266           * admin, and 'false' if they are not.
 267           */
 268          bp_update_is_item_admin( bp_user_has_access(), 'core' );
 269  
 270          // Is the logged in user is a mod for the current item?
 271          bp_update_is_item_mod( false,                  'core' );
 272  
 273          /**
 274           * Fires at the end of the setup of bp-core globals setting.
 275           *
 276           * @since 1.1.0
 277           */
 278          do_action( 'bp_core_setup_globals' );
 279      }
 280  
 281      /**
 282       * Setup cache groups
 283       *
 284       * @since 2.2.0
 285       */
 286  	public function setup_cache_groups() {
 287  
 288          // Global groups.
 289          wp_cache_add_global_groups( array(
 290              'bp'
 291          ) );
 292  
 293          parent::setup_cache_groups();
 294      }
 295  
 296      /**
 297       * Set up post types.
 298       *
 299       * @since BuddyPress (2.4.0)
 300       */
 301  	public function register_post_types() {
 302  
 303          // Emails
 304          if ( bp_is_root_blog() && ! is_network_admin() ) {
 305              register_post_type(
 306                  bp_get_email_post_type(),
 307                  apply_filters( 'bp_register_email_post_type', array(
 308                      'description'       => _x( 'BuddyPress emails', 'email post type description', 'buddypress' ),
 309                      'labels'            => bp_get_email_post_type_labels(),
 310                      'menu_icon'         => 'dashicons-email',
 311                      'public'            => false,
 312                      'publicly_queryable' => bp_current_user_can( 'bp_moderate' ),
 313                      'query_var'         => false,
 314                      'rewrite'           => false,
 315                      'show_in_admin_bar' => false,
 316                      'show_ui'           => bp_current_user_can( 'bp_moderate' ),
 317                      'supports'          => bp_get_email_post_type_supports(),
 318                  ) )
 319              );
 320          }
 321  
 322          parent::register_post_types();
 323      }
 324  }


Generated: Sat Jul 20 01:01:39 2019 Cross-referenced by PHPXref 0.7.1