( $this->rewrite_ids['directory_type'] ); if ( $member_slug ) { /** * Filter the portion of the URI that is the displayed user's slug. * * Eg. example.com/ADMIN (when root profiles is enabled) * example.com/members/ADMIN (when root profiles isn't enabled) * * ADMIN would be the displayed user's slug. * * @since 2.6.0 * * @param string $member_slug */ $member_slug = apply_filters( 'bp_core_set_uri_globals_member_slug', $member_slug ); $bp->current_component = ''; // Unless root profiles are on, the member shouldn't be set yet. if ( ! $member ) { $member = get_user_by( $member_data['field'], $member_slug ); if ( ! $member ) { bp_do_404(); return; } } // If the member is marked as a spammer, 404 (unless logged-in user is a super admin). if ( bp_is_user_spammer( $member->ID ) ) { if ( bp_current_user_can( 'bp_moderate' ) ) { bp_core_add_message( __( 'This user has been marked as a spammer. Only site admins can view this profile.', 'buddypress' ), 'warning' ); } else { bp_do_404(); return; } } // Set the displayed user and the current item. $bp->displayed_user->id = $member->ID; $bp->current_item = $member_slug; // The core userdata of the user who is currently being displayed. if ( ! isset( $bp->displayed_user->userdata ) || ! $bp->displayed_user->userdata ) { $bp->displayed_user->userdata = bp_core_get_core_userdata( bp_displayed_user_id() ); } // Fetch the full name displayed user. if ( ! isset( $bp->displayed_user->fullname ) || ! $bp->displayed_user->fullname ) { $bp->displayed_user->fullname = ''; if ( isset( $bp->displayed_user->userdata->display_name ) ) { $bp->displayed_user->fullname = $bp->displayed_user->userdata->display_name; } } // The domain for the user currently being displayed. if ( ! isset( $bp->displayed_user->domain ) || ! $bp->displayed_user->domain ) { $bp->displayed_user->domain = bp_members_get_user_url( bp_displayed_user_id() ); } // If a user is displayed, check if there is a front template and reset navigation. if ( bp_get_displayed_user() ) { $bp->displayed_user->front_template = bp_displayed_user_get_front_template(); // Reset the nav for the members component. $this->nav = new BP_Core_Nav(); } $member_component = $query->get( $this->rewrite_ids['single_item_component'] ); if ( $member_component ) { // Check if the member's component slug has been customized. $item_component_rewrite_id = bp_rewrites_get_custom_slug_rewrite_id( 'members', $member_component ); if ( $item_component_rewrite_id ) { $member_component = str_replace( 'bp_member_', '', $item_component_rewrite_id ); } $bp->current_component = $member_component; } $current_action = $query->get( $this->rewrite_ids['single_item_action'] ); if ( $current_action ) { $context = sprintf( 'bp_member_%s_', $bp->current_component ); // Check if the member's component action slug has been customized. $item_component_action_rewrite_id = bp_rewrites_get_custom_slug_rewrite_id( 'members', $current_action, $context ); if ( $item_component_action_rewrite_id ) { $custom_action_slug = str_replace( $context, '', $item_component_action_rewrite_id ); // Make sure the action is stored as a slug: underscores need to be replaced by dashes. $current_action = str_replace( '_', '-', $custom_action_slug ); } $bp->current_action = $current_action; } $action_variables = $query->get( $this->rewrite_ids['single_item_action_variables'] ); if ( $action_variables ) { $context = sprintf( 'bp_member_%1$s_%2$s_', $bp->current_component, $bp->current_action ); if ( ! is_array( $action_variables ) ) { $action_variables = explode( '/', ltrim( $action_variables, '/' ) ); } foreach ( $action_variables as $key_variable => $action_variable ) { $item_component_action_variable_rewrite_id = bp_rewrites_get_custom_slug_rewrite_id( 'members', $action_variable, $context ); if ( $item_component_action_variable_rewrite_id ) { $action_variables[ $key_variable ] = str_replace( $context, '', $item_component_action_variable_rewrite_id ); } } $bp->action_variables = $action_variables; } // Is this a member type query? } elseif ( $member_type_slug ) { $member_type = bp_get_member_types( array( 'has_directory' => true, 'directory_slug' => $member_type_slug, ) ); if ( $member_type ) { $member_type = reset( $member_type ); $bp->current_member_type = $member_type; } else { $bp->current_component = ''; bp_do_404(); return; } } // Set the BuddyPress queried object. if ( isset( $bp->pages->members->id ) ) { $query->queried_object = get_post( $bp->pages->members->id ); $query->queried_object_id = $query->queried_object->ID; if ( $member ) { $query->queried_object->single_item_name = $member->display_name; } elseif ( $member_type ) { $query->queried_object->directory_type_name = $member_type; } } // Handle the custom registration page. } elseif ( $is_register_component ) { $bp->current_component = 'register'; // Handle the custom activation page. } elseif ( $is_activate_component ) { $bp->current_component = 'activate'; $current_action = $query->get( $this->rewrite_ids['member_activate_key'] ); if ( $current_action ) { $bp->current_action = $current_action; } } parent::parse_query( $query ); } /** * Check the parsed query is consistent with Members navigation. * * As the members’ component pages need a valid screen function to load the right BP Template, * we need to make sure the current single item action exists inside the Members navigation and * that the corresponding screen function is a valid callback. * * @since 12.0.0 */ public function check_parsed_query() { if ( bp_is_user() ) { $single_item_component = bp_current_component(); $single_item_action = ''; if ( $single_item_component ) { $single_item_action = bp_current_action(); } // Viewing a single activity. if ( 'activity' === $single_item_component && is_numeric( $single_item_action ) ) { return; } $bp = buddypress(); if ( ! bp_is_active( $single_item_component ) && ! $bp->members->nav->get_primary( array( 'slug' => $single_item_component ), false ) ) { bp_do_404(); return; } // Navigation is generated by a component. if ( isset( $bp->{$single_item_component} ) ) { $screen_function = ''; if ( isset( $bp->{$single_item_component}->sub_nav ) ) { $screen_functions = wp_list_pluck( $bp->{$single_item_component}->sub_nav, 'screen_function', 'slug' ); if ( isset( $screen_functions[ $single_item_action ] ) ) { $screen_function = $screen_functions[ $single_item_action ]; } } // Check if this nav item has been added from outside the Component's class. if ( ! $screen_function ) { $sub_nav = $this->nav->get( $single_item_component . '/' . $single_item_action ); if ( isset( $sub_nav->screen_function ) && $sub_nav->screen_function ) { $screen_function = $sub_nav->screen_function; } } if ( ! $single_item_action || ! $screen_function || ! is_callable( $screen_function ) ) { bp_do_404(); return; } // Navigation is not generated by a component. } else { $sub_nav = $bp->members->nav->get_secondary( array( 'parent_slug' => $single_item_component, 'slug' => $single_item_action, ), false ); if ( ! $sub_nav ) { bp_do_404(); return; } } } } /** * Init the BP REST API. * * @since 5.0.0 * @since 6.0.0 Adds the Member Cover and Signup REST endpoints. * @since 9.0.0 Moves the `BP_REST_Components_Endpoint` controller in `BP_Core` component. * * @param array $controllers Optional. See BP_Component::rest_api_init() for * description. */ public function rest_api_init( $controllers = array() ) { $controllers = array( 'BP_REST_Members_Endpoint', 'BP_REST_Attachments_Member_Avatar_Endpoint', ); if ( bp_is_active( 'members', 'cover_image' ) ) { $controllers[] = 'BP_REST_Attachments_Member_Cover_Endpoint'; } if ( bp_get_signup_allowed() ) { $controllers[] = 'BP_REST_Signup_Endpoint'; } parent::rest_api_init( $controllers ); } /** * Register the BP Members Blocks. * * @since 6.0.0 * @since 12.0.0 Use the WP Blocks API v2. * * @param array $blocks Optional. See BP_Component::blocks_init() for * description. */ public function blocks_init( $blocks = array() ) { parent::blocks_init( array( 'bp/member' => array( 'metadata' => trailingslashit( buddypress()->plugin_dir ) . 'bp-members/blocks/member', 'render_callback' => 'bp_members_render_member_block', ), 'bp/members' => array( 'metadata' => trailingslashit( buddypress()->plugin_dir ) . 'bp-members/blocks/members', 'render_callback' => 'bp_members_render_members_block', ), 'bp/dynamic-members' => array( 'metadata' => trailingslashit( buddypress()->plugin_dir ) . 'bp-members/blocks/dynamic-members', 'render_callback' => 'bp_members_render_dynamic_members_block', ), 'bp/online-members' => array( 'metadata' => trailingslashit( buddypress()->plugin_dir ) . 'bp-members/blocks/online-members', 'render_callback' => 'bp_members_render_online_members_block', ), 'bp/active-members' => array( 'metadata' => trailingslashit( buddypress()->plugin_dir ) . 'bp-members/blocks/active-members', 'render_callback' => 'bp_members_render_active_members_block', ), ) ); } }