Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
02/05/2016 05:15:55 AM (9 years ago)
Author:
boonebgorges
Message:

Move bp-members classes to their own files.

See #6870.

File:
1 edited

Legend:

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

    r10506 r10521  
    1111defined( 'ABSPATH' ) || exit;
    1212
    13 /**
    14  * Defines the BuddyPress Members Component.
    15  */
    16 class BP_Members_Component extends BP_Component {
    17 
    18     /**
    19      * Member types.
    20      *
    21      * @see bp_register_member_type()
    22      *
    23      * @since 2.2.0
    24      * @var array
    25      */
    26     public $types = array();
    27 
    28     /**
    29      * Start the members component creation process.
    30      *
    31      * @since 1.5.0
    32      */
    33     public function __construct() {
    34         parent::start(
    35             'members',
    36             __( 'Members', 'buddypress' ),
    37             buddypress()->plugin_dir,
    38             array(
    39                 'adminbar_myaccount_order' => 20,
    40                 'search_query_arg' => 'members_search',
    41             )
    42         );
    43     }
    44 
    45     /**
    46      * Include bp-members files.
    47      *
    48      * @see BP_Component::includes() for description of parameters.
    49      *
    50      * @param array $includes See {@link BP_Component::includes()}.
    51      */
    52     public function includes( $includes = array() ) {
    53 
    54         // Always include these files.
    55         $includes = array(
    56             'actions',
    57             'classes',
    58             'filters',
    59             'screens',
    60             'template',
    61             'adminbar',
    62             'functions',
    63             'widgets',
    64             'cache',
    65         );
    66 
    67         if ( bp_is_active( 'activity' ) ) {
    68             $includes[] = 'activity';
    69         }
    70 
    71         // Include these only if in admin.
    72         if ( is_admin() ) {
    73             $includes[] = 'admin';
    74         }
    75 
    76         parent::includes( $includes );
    77     }
    78 
    79     /**
    80      * Set up bp-members global settings.
    81      *
    82      * The BP_MEMBERS_SLUG constant is deprecated, and only used here for
    83      * backwards compatibility.
    84      *
    85      * @since 1.5.0
    86      *
    87      * @see BP_Component::setup_globals() for description of parameters.
    88      *
    89      * @param array $args See {@link BP_Component::setup_globals()}.
    90      */
    91     public function setup_globals( $args = array() ) {
    92         global $wpdb;
    93 
    94         $bp = buddypress();
    95 
    96         /** Component Globals ************************************************
    97          */
    98 
    99         // Define a slug, as a fallback for backpat.
    100         if ( !defined( 'BP_MEMBERS_SLUG' ) ) {
    101             define( 'BP_MEMBERS_SLUG', $this->id );
    102         }
    103 
    104         // Override any passed args.
    105         $args = array(
    106             'slug'            => BP_MEMBERS_SLUG,
    107             'root_slug'       => isset( $bp->pages->members->slug ) ? $bp->pages->members->slug : BP_MEMBERS_SLUG,
    108             'has_directory'   => true,
    109             'directory_title' => _x( 'Members', 'component directory title', 'buddypress' ),
    110             'search_string'   => __( 'Search Members...', 'buddypress' ),
    111             'global_tables'   => array(
    112                 'table_name_last_activity' => bp_core_get_table_prefix() . 'bp_activity',
    113                 'table_name_signups'       => $wpdb->base_prefix . 'signups', // signups is a global WordPress table
    114             )
    115         );
    116 
    117         parent::setup_globals( $args );
    118 
    119         /** Logged in user ***************************************************
    120          */
    121 
    122         // The core userdata of the user who is currently logged in.
    123         $bp->loggedin_user->userdata       = bp_core_get_core_userdata( bp_loggedin_user_id() );
    124 
    125         // Fetch the full name for the logged in user.
    126         $bp->loggedin_user->fullname       = isset( $bp->loggedin_user->userdata->display_name ) ? $bp->loggedin_user->userdata->display_name : '';
    127 
    128         // Hits the DB on single WP installs so get this separately.
    129         $bp->loggedin_user->is_super_admin = $bp->loggedin_user->is_site_admin = is_super_admin( bp_loggedin_user_id() );
    130 
    131         // The domain for the user currently logged in. eg: http://example.com/members/andy.
    132         $bp->loggedin_user->domain         = bp_core_get_user_domain( bp_loggedin_user_id() );
    133 
    134         /** Displayed user ***************************************************
    135          */
    136 
    137         // The core userdata of the user who is currently being displayed.
    138         $bp->displayed_user->userdata = bp_core_get_core_userdata( bp_displayed_user_id() );
    139 
    140         // Fetch the full name displayed user.
    141         $bp->displayed_user->fullname = isset( $bp->displayed_user->userdata->display_name ) ? $bp->displayed_user->userdata->display_name : '';
    142 
    143         // The domain for the user currently being displayed.
    144         $bp->displayed_user->domain   = bp_core_get_user_domain( bp_displayed_user_id() );
    145 
    146         /** Signup ***********************************************************
    147          */
    148 
    149         $bp->signup = new stdClass;
    150 
    151         /** Profiles Fallback ************************************************
    152          */
    153 
    154         if ( ! bp_is_active( 'xprofile' ) ) {
    155             $bp->profile       = new stdClass;
    156             $bp->profile->slug = 'profile';
    157             $bp->profile->id   = 'profile';
    158         }
    159     }
    160 
    161     /**
    162      * Set up canonical stack for this component.
    163      *
    164      * @since 2.1.0
    165      */
    166     public function setup_canonical_stack() {
    167         $bp = buddypress();
    168 
    169         /** Default Profile Component ****************************************
    170          */
    171 
    172         if ( defined( 'BP_DEFAULT_COMPONENT' ) && BP_DEFAULT_COMPONENT ) {
    173             $bp->default_component = BP_DEFAULT_COMPONENT;
    174         } else {
    175             if ( bp_is_active( 'activity' ) && isset( $bp->pages->activity ) ) {
    176                 $bp->default_component = bp_get_activity_slug();
    177             } else {
    178                 $bp->default_component = ( 'xprofile' === $bp->profile->id ) ? 'profile' : $bp->profile->id;
    179             }
    180         }
    181 
    182         /** Canonical Component Stack ****************************************
    183          */
    184 
    185         if ( bp_displayed_user_id() ) {
    186             $bp->canonical_stack['base_url'] = bp_displayed_user_domain();
    187 
    188             if ( bp_current_component() ) {
    189                 $bp->canonical_stack['component'] = bp_current_component();
    190             }
    191 
    192             if ( bp_current_action() ) {
    193                 $bp->canonical_stack['action'] = bp_current_action();
    194             }
    195 
    196             if ( !empty( $bp->action_variables ) ) {
    197                 $bp->canonical_stack['action_variables'] = bp_action_variables();
    198             }
    199 
    200             // Looking at the single member root/home, so assume the default.
    201             if ( ! bp_current_component() ) {
    202                 $bp->current_component = $bp->default_component;
    203 
    204             // The canonical URL will not contain the default component.
    205             } elseif ( bp_is_current_component( $bp->default_component ) && ! bp_current_action() ) {
    206                 unset( $bp->canonical_stack['component'] );
    207             }
    208 
    209             // If we're on a spammer's profile page, only users with the 'bp_moderate' cap
    210             // can view subpages on the spammer's profile.
    211             //
    212             // users without the cap trying to access a spammer's subnav page will get
    213             // redirected to the root of the spammer's profile page.  this occurs by
    214             // by removing the component in the canonical stack.
    215             if ( bp_is_user_spammer( bp_displayed_user_id() ) && ! bp_current_user_can( 'bp_moderate' ) ) {
    216                 unset( $bp->canonical_stack['component'] );
    217             }
    218         }
    219     }
    220 
    221     /**
    222      * Set up fall-back component navigation if XProfile is inactive.
    223      *
    224      * @since 1.5.0
    225      *
    226      * @see BP_Component::setup_nav() for a description of arguments.
    227      *
    228      * @param array $main_nav Optional. See BP_Component::setup_nav() for
    229      *                        description.
    230      * @param array $sub_nav  Optional. See BP_Component::setup_nav() for
    231      *                        description.
    232      */
    233     public function setup_nav( $main_nav = array(), $sub_nav = array() ) {
    234 
    235         // Bail if XProfile component is active.
    236         if ( bp_is_active( 'xprofile' ) ) {
    237             return;
    238         }
    239 
    240         // Don't set up navigation if there's no member.
    241         if ( ! is_user_logged_in() && ! bp_is_user() ) {
    242             return;
    243         }
    244 
    245         // Determine user to use.
    246         if ( bp_displayed_user_domain() ) {
    247             $user_domain = bp_displayed_user_domain();
    248         } elseif ( bp_loggedin_user_domain() ) {
    249             $user_domain = bp_loggedin_user_domain();
    250         } else {
    251             return;
    252         }
    253 
    254         $slug         = bp_get_profile_slug();
    255         $profile_link = trailingslashit( $user_domain . $slug );
    256 
    257         // Setup the main navigation.
    258         $main_nav = array(
    259             'name'                => _x( 'Profile', 'Member profile main navigation', 'buddypress' ),
    260             'slug'                => $slug,
    261             'position'            => 20,
    262             'screen_function'     => 'bp_members_screen_display_profile',
    263             'default_subnav_slug' => 'public',
    264             'item_css_id'         => buddypress()->profile->id
    265         );
    266 
    267         // Setup the subnav items for the member profile.
    268         $sub_nav[] = array(
    269             'name'            => _x( 'View', 'Member profile view', 'buddypress' ),
    270             'slug'            => 'public',
    271             'parent_url'      => $profile_link,
    272             'parent_slug'     => $slug,
    273             'screen_function' => 'bp_members_screen_display_profile',
    274             'position'        => 10
    275         );
    276 
    277         parent::setup_nav( $main_nav, $sub_nav );
    278     }
    279 
    280     /**
    281      * Set up the title for pages and <title>.
    282      */
    283     public function setup_title() {
    284         $bp = buddypress();
    285 
    286         if ( bp_is_my_profile() ) {
    287             $bp->bp_options_title = __( 'You', 'buddypress' );
    288         } elseif ( bp_is_user() ) {
    289             $bp->bp_options_title  = bp_get_displayed_user_fullname();
    290             $bp->bp_options_avatar = bp_core_fetch_avatar( array(
    291                 'item_id' => bp_displayed_user_id(),
    292                 'type'    => 'thumb',
    293                 'alt'     => sprintf( __( 'Profile picture of %s', 'buddypress' ), $bp->bp_options_title )
    294             ) );
    295         }
    296 
    297         parent::setup_title();
    298     }
    299 
    300     /**
    301      * Setup cache groups.
    302      *
    303      * @since 2.2.0
    304      */
    305     public function setup_cache_groups() {
    306 
    307         // Global groups.
    308         wp_cache_add_global_groups( array(
    309             'bp_last_activity',
    310             'bp_member_type'
    311         ) );
    312 
    313         parent::setup_cache_groups();
    314     }
    315 }
     13require dirname( __FILE__ ) . '/classes/class-bp-members-component.php';
    31614
    31715/**
Note: See TracChangeset for help on using the changeset viewer.