his->path . 'bp-members/screens/activate.php'; } // Theme compatibility. new BP_Registration_Theme_Compat(); } // Invitations. if ( is_user_logged_in() && bp_is_user_members_invitations() ) { // Actions. if ( isset( $_POST['members_invitations'] ) ) { require_once $this->path . 'bp-members/actions/invitations-bulk-manage.php'; } // Screens. require_once $this->path . 'bp-members/screens/invitations.php'; } } /** * Set up the component actions. * * @since 12.0.0 */ public function setup_actions() { parent::setup_actions(); // Check the parsed query is consistent with the Members navigation. add_action( 'bp_parse_query', array( $this, 'check_parsed_query' ), 999, 0 ); } /** * Set up additional globals for the component. * * @since 10.0.0 */ public function setup_additional_globals() { $bp = buddypress(); // Set-up Extra permastructs for the register and activate pages. $this->register_permastruct = bp_get_signup_slug() . '/%' . $this->rewrite_ids['member_register'] . '%'; $this->activate_permastruct = bp_get_activate_slug() . '/%' . $this->rewrite_ids['member_activate'] . '%'; // Init the User's ID to use to build the Nav for. $user_id = bp_loggedin_user_id(); /** Logged in user *************************************************** */ // The core userdata of the user who is currently logged in. $bp->loggedin_user->userdata = bp_core_get_core_userdata( $user_id ); // Fetch the full name for the logged in user. $bp->loggedin_user->fullname = isset( $bp->loggedin_user->userdata->display_name ) ? $bp->loggedin_user->userdata->display_name : ''; // Hits the DB on single WP installs so get this separately. $bp->loggedin_user->is_super_admin = $bp->loggedin_user->is_site_admin = is_super_admin( $user_id ); // The domain for the user currently logged in. eg: http://example.com/members/andy. $bp->loggedin_user->domain = bp_members_get_user_url( $user_id ); /** * Set the Displayed user for the classic BuddyPress. This should only be the case when the * legacy parser is on. When BP Rewrites are on, the displayed user is set in * `BP_Members_Component::parse_query()`. */ if ( bp_displayed_user_id() ) { // We're viewing a speciific user, switch the ID to use for the Nav to this one. $user_id = bp_displayed_user_id(); // The core userdata of the user who is currently being displayed. $bp->displayed_user->userdata = bp_core_get_core_userdata( $user_id ); // Fetch the full name displayed user. $bp->displayed_user->fullname = isset( $bp->displayed_user->userdata->display_name ) ? $bp->displayed_user->userdata->display_name : ''; // The domain for the user currently being displayed. $bp->displayed_user->domain = bp_members_get_user_url( $user_id ); // If A user is displayed, check if there is a front template if ( bp_get_displayed_user() ) { $bp->displayed_user->front_template = bp_displayed_user_get_front_template(); } } /** Initialize the nav for the members component ********************* */ $this->nav = new BP_Core_Nav( $user_id ); /** Signup *********************************************************** */ $bp->signup = new stdClass; /** Profiles Fallback ************************************************ */ if ( ! bp_is_active( 'xprofile' ) ) { $bp->profile = new stdClass; $bp->profile->slug = 'profile'; $bp->profile->id = 'profile'; } /** Network Invitations ************************************************** */ $bp->members->invitations = new stdClass; } /** * Set up bp-members global settings. * * The BP_MEMBERS_SLUG constant is deprecated. * * @since 1.5.0 * * @see BP_Component::setup_globals() for description of parameters. * * @global wpdb $wpdb The WordPress database object. * * @param array $args See {@link BP_Component::setup_globals()}. */ public function setup_globals( $args = array() ) { global $wpdb; $bp = buddypress(); $default_slug = $this->id; /** Component Globals ************************************************ */ // @deprecated. if ( defined( 'BP_MEMBERS_SLUG' ) ) { _doing_it_wrong( 'BP_MEMBERS_SLUG', esc_html__( 'Slug constants are deprecated.', 'buddypress' ), 'BuddyPress 12.0.0' ); $default_slug = BP_MEMBERS_SLUG; } // Fetch the default directory title. $default_directory_titles = bp_core_get_directory_page_default_titles(); $default_directory_title = $default_directory_titles[$this->id]; // Override any passed args. $args = array( 'slug' => $default_slug, 'root_slug' => isset( $bp->pages->members->slug ) ? $bp->pages->members->slug : $default_slug, 'has_directory' => true, 'rewrite_ids' => array( 'directory' => 'members', 'directory_type' => 'members_type', 'single_item' => 'member', 'single_item_component' => 'member_component', 'single_item_action' => 'member_action', 'single_item_action_variables' => 'member_action_variables', 'member_register' => 'register', 'member_activate' => 'activate', 'member_activate_key' => 'activate_key', ), 'directory_title' => isset( $bp->pages->members->title ) ? $bp->pages->members->title : $default_directory_title, 'search_string' => __( 'Search Members...', 'buddypress' ), 'global_tables' => array( 'table_name_invitations' => bp_core_get_table_prefix() . 'bp_invitations', 'table_name_last_activity' => bp_core_get_table_prefix() . 'bp_activity', 'table_name_optouts' => bp_core_get_table_prefix() . 'bp_optouts', 'table_name_signups' => $wpdb->base_prefix . 'signups', // Signups is a global WordPress table. ), 'notification_callback' => 'members_format_notifications', 'block_globals' => array( 'bp/dynamic-members' => array( 'widget_classnames' => array( 'widget_bp_core_members_widget', 'buddypress' ), ), 'bp/online-members' => array( 'widget_classnames' => array( 'widget_bp_core_whos_online_widget', 'buddypress' ), ), 'bp/active-members' => array( 'widget_classnames' => array( 'widget_bp_core_recently_active_widget', 'buddypress' ), ), ), ); parent::setup_globals( $args ); // Additional globals. $this->setup_additional_globals(); } /** * Set up canonical stack for this component. * * @since 2.1.0 */ public function setup_canonical_stack() { $bp = buddypress(); /** Default Profile Component **************************************** */ if ( bp_displayed_user_has_front_template() ) { $bp->default_component = 'front'; } elseif ( bp_is_active( 'activity' ) && isset( $bp->pages->activity ) ) { $bp->default_component = bp_get_activity_slug(); } else { $bp->default_component = ( 'xprofile' === $bp->profile->id ) ? 'profile' : $bp->profile->id; } if ( defined( 'BP_DEFAULT_COMPONENT' ) && BP_DEFAULT_COMPONENT ) { $default_component = BP_DEFAULT_COMPONENT; if ( 'profile' === $default_component ) { $default_component = 'xprofile'; } if ( bp_is_active( $default_component ) ) { $bp->default_component = BP_DEFAULT_COMPONENT; } } /** Canonical Component Stack **************************************** */ if ( bp_displayed_user_id() ) { $bp->canonical_stack['base_url'] = bp_displayed_user_url(); $action_variables = (array) bp_action_variables(); $path_chunks = bp_members_get_path_chunks( array_merge( array( bp_current_component(), bp_current_action() ), array_filter( $action_variables ) ) ); if ( isset( $path_chunks['single_item_component'] ) ) { $bp->canonical_stack['component'] = $path_chunks['single_item_component']; // The canonical URL will not contain the default component. if ( bp_is_current_component( $bp->default_component ) && ! bp_current_action() ) { unset( $bp->canonical_stack['component'] ); } elseif ( isset( $path_chunks['single_item_action'] ) ) { $bp->canonical_stack['action'] = $path_chunks['single_item_action']; if ( isset( $path_chunks['single_item_action_variables'] ) ) { $bp->canonical_stack['action_variables'] = $path_chunks['single_item_action_variables']; } } // Looking at the single member root/home, so assume the default. } else { $bp->current_component = $bp->default_component; } /* * If we're on a spammer's profile page, only users with the 'bp_moderate' cap * can view subpages on the spammer's profile. * * users without the cap trying to access a spammer's subnav page will get * redirected to the root of the spammer's profile page. this occurs by * by removing the component in the canonical stack. */ if ( bp_is_user_spammer( bp_displayed_user_id() ) && ! bp_current_user_can( 'bp_moderate' ) ) { unset( $bp->canonical_stack['component'] ); } } } /** * Get the Avatar and Cover image subnavs. * * @since 6.0.0 * @deprecated 12.0.0 * * @return array The Avatar and Cover image subnavs. */ public function get_avatar_cover_image_subnavs() { _deprecated_function( __METHOD__, '12.0.0' ); } /** * Register component navigation. * * @since 12.0.0 * * @see `BP_Component::register_nav()` for a description of arguments. * * @param array $main_nav Optional. See `BP_Component::register_nav()` for * description. * @param array $sub_nav Optional. See `BP_Component::register_nav()` for * description. */ public function register_nav( $main_nav = array(), $sub_nav = array() ) { // Set slug to profile in case the xProfile component is not active $slug = bp_get_profile_slug(); $main_nav = array( 'name' => _x( 'Profile', 'Member profile main navigation', 'buddypress' ), 'slug' => $slug, 'position' => 20, 'screen_function' => 'bp_members_screen_display_profile', 'default_subnav_slug' => 'public', 'item_css_id' => buddypress()->profile->id, 'generate' => ! bp_is_active( 'xprofile' ), ); $sub_nav[] = array( 'name' => _x( 'View', 'Member profile view', 'buddypress' ), 'slug' => 'public', 'parent_slug' => $slug, 'screen_function' => 'bp_members_screen_display_profile', 'position' => 10, 'generate' => ! bp_is_active( 'xprofile' ), ); $sub_nav[] = array( 'name' => _x( 'Change Profile Photo', 'Profile header sub menu', 'buddypress' ), 'slug' => 'change-avatar', 'parent_slug' => $slug, 'screen_function' => 'bp_members_screen_change_avatar', 'position' => 30, 'user_has_access' => false, 'user_has_access_callback' => 'bp_core_can_edit_settings', 'generate' => buddypress()->avatar->show_avatars, ); $sub_nav[] = array( 'name' => _x( 'Change Cover Image', 'Profile header sub menu', 'buddypress' ), 'slug' => 'change-cover-image', 'parent_slug' => $slug, 'screen_function' => 'bp_members_screen_change_cover_image', 'position' => 40, 'user_has_access' => false, 'user_has_access_callback' => 'bp_core_can_edit_settings', 'generate' => bp_displayed_user_use_cover_image_header(), ); parent::register_nav( $main_nav, $sub_nav ); } /** * Set up a profile nav in case the xProfile * component is not active and a front template is * used. * * @since 2.6.0 * @deprecated 12.0.0 */ public function setup_profile_nav() { _deprecated_function( __METHOD__, '12.0.0' ); } /** * Set up the xProfile nav. * * @since 6.0.0 * @deprecated 12.0.0 */ public function setup_xprofile_nav() { _deprecated_function( __METHOD__, '12.0.0' ); } /** * Get the Avatar and Cover image admin navs. * * @since 6.0.0 * * @param string $admin_bar_menu_id The Admin bar menu ID to attach sub items to. * @return array The Avatar and Cover image admin navs. */ public function get_avatar_cover_image_admin_navs( $admin_bar_menu_id = '' ) { $wp_admin_nav = array(); $profile_slug = bp_get_profile_slug(); if ( ! $admin_bar_menu_id ) { $admin_bar_menu_id = $this->id; } // Edit Avatar. if ( buddypress()->avatar->show_avatars ) { $wp_admin_nav[] = array( 'parent' => 'my-account-' . $admin_bar_menu_id, 'id' => 'my-account-' . $admin_bar_menu_id . '-change-avatar', 'title' => _x( 'Change Profile Photo', 'My Account Profile sub nav', 'buddypress' ), 'href' => bp_loggedin_user_url( bp_members_get_path_chunks( array( $profile_slug, 'change-avatar' ) ) ), 'position' => 30, ); } // Edit Cover Image if ( bp_displayed_user_use_cover_image_header() ) { $wp_admin_nav[] = array( 'parent' => 'my-account-' . $admin_bar_menu_id, 'id' => 'my-account-' . $admin_bar_menu_id . '-change-cover-image', 'title' => _x( 'Change Cover Image', 'My Account Profile sub nav', 'buddypress' ), 'href' => bp_loggedin_user_url( bp_members_get_path_chunks( array( $profile_slug, 'change-cover-image' ) ) ), 'position' => 40, ); } return $wp_admin_nav; } /** * Set up the Admin Bar. * * @since 6.0.0 * * @param array $wp_admin_nav Admin Bar items. */ public function setup_admin_bar( $wp_admin_nav = array() ) { // Menus for logged in user. if ( is_user_logged_in() ) { $profile_slug = bp_get_profile_slug(); if ( ! bp_is_active( 'xprofile' ) ) { // Add the "Profile" sub menu. $wp_admin_nav[] = array( 'parent' => buddypress()->my_account_menu_id, 'id' => 'my-account-' . $this->id, 'title' => _x( 'Profile', 'My Account Profile', 'buddypress' ), 'href' => bp_loggedin_user_url( bp_members_get_path_chunks( array( $profile_slug ) ) ), ); // View Profile. $wp_admin_nav[] = array( 'parent' => 'my-account-' . $this->id, 'id' => 'my-account-' . $this->id . '-public', 'title' => _x( 'View', 'My Account Profile sub nav', 'buddypress' ), 'href' => bp_loggedin_user_url( bp_members_get_path_chunks( array( $profile_slug, 'public' ) ) ), 'position' => 10, ); $wp_admin_nav = array_merge( $wp_admin_nav, $this->get_avatar_cover_image_admin_navs() ); /** * The xProfile is active. * * Add the Change Avatar and Change Cover Image Admin Bar items * to the xProfile Admin Bar Menu. */ } else { add_filter( 'bp_xprofile_admin_nav', array( $this, 'setup_xprofile_admin_nav' ), 2 ); } } parent::setup_admin_bar( $wp_admin_nav ); } /** * Adds "Profile > Change Avatar" & "Profile > Change Cover Image" subnav item * under the "Profile" adminbar menu. * * @since 6.0.0 * * @param array $wp_admin_nav The Profile adminbar nav array. * @return array */ public function setup_xprofile_admin_nav( $wp_admin_nav ) { $items = $this->get_avatar_cover_image_admin_navs( buddypress()->profile->id ); if ( $items ) { $wp_admin_nav = array_merge( $wp_admin_nav, $items ); } return $wp_admin_nav; } /** * Set up the title for pages and