Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
02/05/2016 04:26:30 AM (9 years ago)
Author:
boonebgorges
Message:

Move bp-core classes to their own files.

See #6870.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-core/bp-core-loader.php

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