BP_Members_Admin::user_admin_load()

Set up the user’s profile admin page.

Description

Loaded before the page is rendered, this function does all initial setup, including: processing form requests, registering contextual help, and setting up screen options.

Source

File: bp-members/classes/class-bp-members-admin.php

	public function user_admin_load() {

		// Get the user ID.
		$user_id = $this->get_user_id();

		// Can current user edit this profile?
		if ( ! $this->member_can_edit( $user_id ) ) {
			wp_die( __( 'You cannot edit the requested user.', 'buddyboss' ) );
		}

		// Build redirection URL.
		$redirect_to = remove_query_arg( array( 'action', 'error', 'updated', 'spam', 'ham', 'delete_avatar' ), $_SERVER['REQUEST_URI'] );
		$doaction    = ! empty( $_REQUEST['action'] ) ? $_REQUEST['action'] : false;

		if ( ! empty( $_REQUEST['user_status'] ) ) {
			$spam = (bool) ( 'spam' === $_REQUEST['user_status'] );

			if ( $spam !== bp_is_user_spammer( $user_id ) ) {
				$doaction = $_REQUEST['user_status'];
			}
		}

		/**
		 * Fires at the start of the signups admin load.
		 *
		 * @since BuddyPress 2.0.0
		 *
		 * @param string $doaction Current bulk action being processed.
		 * @param array  $_REQUEST Current $_REQUEST global.
		 */
		do_action_ref_array( 'bp_members_admin_load', array( $doaction, $_REQUEST ) );

		/**
		 * Filters the allowed actions for use in the user admin page.
		 *
		 * @since BuddyPress 2.0.0
		 *
		 * @param array $value Array of allowed actions to use.
		 */
		$allowed_actions = apply_filters( 'bp_members_admin_allowed_actions', array( 'update', 'delete_avatar', 'spam', 'ham' ) );

		// Prepare the display of the Community Profile screen.
		if ( ! in_array( $doaction, $allowed_actions ) ) {
			add_screen_option( 'layout_columns', array( 'default' => 2, 'max' => 2, ) );

			get_current_screen()->add_help_tab( array(
				'id'      => 'bp-profile-edit-overview',
				'title'   => __( 'Overview', 'buddyboss' ),
				'content' =>
				'<p>' . __( 'This is the admin view of a user\'s profile.', 'buddyboss' ) . '</p>' .
				'<p>' . __( 'In the main column, you can edit the fields of the user\'s extended profile.', 'buddyboss' ) . '</p>' .
				'<p>' . __( 'In the right-hand column, you can update the user\'s status, delete the user\'s avatar, and view recent statistics.', 'buddyboss' ) . '</p>'
			) );

			// Help panel - sidebar links.
			get_current_screen()->set_help_sidebar(
				'<p><strong>' . __( 'For more information:', 'buddyboss' ) . '</strong></p>' .
				'<p>' . __( '<a href="https://www.buddyboss.com/resources/">Documentation</a>', 'buddyboss' ) . '</p>'
			);

			// Register metaboxes for the edit screen.
			add_meta_box(
				'submitdiv',
				__( 'Status', 'buddyboss' ),
				array( $this, 'user_admin_status_metabox' ),
				get_current_screen()->id,
				'side',
				'core'
			);

			// In case xprofile is not active.
			$this->stats_metabox->context  = 'normal';
			$this->stats_metabox->priority = 'core';

			/**
			 * Fires before loading the profile fields if component is active.
			 *
			 * Plugins should not use this hook, please use 'bp_members_admin_user_metaboxes' instead.
			 *
			 * @since BuddyPress 2.0.0
			 *
			 * @param int    $user_id       Current user ID for the screen.
			 * @param string $id            Current screen ID.
			 * @param object $stats_metabox Object holding position data for use with the stats metabox.
			 */
			do_action_ref_array( 'bp_members_admin_xprofile_metabox', array( $user_id, get_current_screen()->id, $this->stats_metabox ) );

			// If xProfile is inactive, difficult to know what's profile we're on.
			if ( 'normal' === $this->stats_metabox->context ) {
				$display_name = bp_core_get_user_displayname( $user_id );
			} else {
				$display_name = __( 'Member', 'buddyboss' );
			}

			// User Stat metabox.
			add_meta_box(
				'bp_members_admin_user_stats',
				sprintf( __( "%s's Stats", 'buddyboss' ), $display_name ),
				array( $this, 'user_admin_stats_metabox' ),
				get_current_screen()->id,
				sanitize_key( $this->stats_metabox->context ),
				sanitize_key( $this->stats_metabox->priority )
			);

			// profile type metabox. Only added if profile types have been registered.
			$member_types = bp_get_member_types();
			if ( ! empty( $member_types ) ) {
				add_meta_box(
					'bp_members_admin_member_type',
					__( 'Profile Type', 'buddyboss' ),
					array( $this, 'user_admin_member_type_metabox' ),
					get_current_screen()->id,
					'side',
					'core'
				);
			}

			/**
			 * Fires at the end of the Community Profile screen.
			 *
			 * Plugins can restrict metabox to "bp_moderate" admins by checking if
			 * the first argument ($this->is_self_profile) is false in their callback.
			 * They can also restrict their metabox to self profile editing
			 * by setting it to true.
			 *
			 * @since BuddyPress 2.0.0
			 *
			 * @param bool $is_self_profile Whether or not it is the current user's profile.
			 * @param int  $user_id         Current user ID.
			 */
			do_action( 'bp_members_admin_user_metaboxes', $this->is_self_profile, $user_id );

			// Enqueue JavaScript files.
			wp_enqueue_script( 'postbox'   );
			wp_enqueue_script( 'dashboard' );

		// Spam or Ham user.
		} elseif ( in_array( $doaction, array( 'spam', 'ham' ) ) && empty( $this->is_self_profile ) ) {

			check_admin_referer( 'edit-bp-profile_' . $user_id );

			if ( bp_core_process_spammer_status( $user_id, $doaction ) ) {
				$redirect_to = add_query_arg( 'updated', $doaction, $redirect_to );
			} else {
				$redirect_to = add_query_arg( 'error', $doaction, $redirect_to );
			}

			bp_core_redirect( $redirect_to );

		// Update other stuff once above ones are done.
		} else {
			$this->redirect = $redirect_to;

			/**
			 * Fires at end of user profile admin load if doaction does not match any available actions.
			 *
			 * @since BuddyPress 2.0.0
			 *
			 * @param string $doaction Current bulk action being processed.
			 * @param int    $user_id  Current user ID.
			 * @param array  $_REQUEST Current $_REQUEST global.
			 * @param string $redirect Determined redirect url to send user to.
			 */
			do_action_ref_array( 'bp_members_admin_update_user', array( $doaction, $user_id, $_REQUEST, $this->redirect ) );

			bp_core_redirect( $this->redirect );
		}
	}

Changelog

Changelog
Version Description
BuddyPress 2.0.0 Introduced.

Questions?

We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.