bp_members_admin_bar_user_admin_menu()

Add the User Admin top-level menu to user pages.

Description

Source

File: bp-members/bp-members-adminbar.php

function bp_members_admin_bar_user_admin_menu() {
	global $wp_admin_bar;

	// Only show if viewing a user.
	if ( !bp_is_user() )
		return false;

	// Don't show this menu to non site admins or if you're viewing your own profile.
	if ( !current_user_can( 'edit_users' ) || bp_is_my_profile() )
		return false;

	$bp = buddypress();

	// Unique ID for the 'My Account' menu.
	$bp->user_admin_menu_id = 'user-admin';

	$user = get_userdata( bp_displayed_user_id() );
	$link = BP_Core_Members_Switching::maybe_switch_url( $user );

	// Add the top-level User Admin button.
	$wp_admin_bar->add_menu( array(
		'id'    => $bp->user_admin_menu_id,
		'title' => __( 'Edit Member', 'buddyboss' ),
		'href'  => add_query_arg( [
			'redirect_to' => urlencode( bp_get_members_component_link( 'profile', 'edit' ) ),
		], $link )
	) );

	if ( bp_is_active( 'xprofile' ) ) {
		// User Admin > Edit this user's profile.
		$wp_admin_bar->add_menu( array(
			'parent' => $bp->user_admin_menu_id,
			'id'     => $bp->user_admin_menu_id . '-edit-profile',
			'title'  => __( 'Edit Profile', 'buddyboss' ),
			'href'   => add_query_arg( [
				'redirect_to' => urlencode( bp_get_members_component_link( 'profile', 'edit' ) ),
			], $link )
		) );

		// User Admin > Edit this user's avatar.
		if ( buddypress()->avatar->show_avatars ) {
			$wp_admin_bar->add_menu( array(
				'parent' => $bp->user_admin_menu_id,
				'id'     => $bp->user_admin_menu_id . '-change-avatar',
				'title'  => __( 'Edit Profile Photo', 'buddyboss' ),
				'href'   => add_query_arg( [
					'redirect_to' => urlencode( bp_get_members_component_link( 'profile', 'change-avatar' ) ),
				], $link )
			) );
		}

		// User Admin > Edit this user's cover photo.
		if ( bp_displayed_user_use_cover_image_header() ) {
			$wp_admin_bar->add_menu( array(
				'parent' => $bp->user_admin_menu_id,
				'id'     => $bp->user_admin_menu_id . '-change-cover-image',
				'title'  => __( 'Edit Cover Photo', 'buddyboss' ),
				'href'   => add_query_arg( [
					'redirect_to' => urlencode( bp_get_members_component_link( 'profile', 'change-cover-image' ) ),
				], $link )
			) );
		}

	}

	if ( bp_is_active( 'settings' ) ) {
		// User Admin > Spam/unspam.
//		$wp_admin_bar->add_menu( array(
//			'parent' => $bp->user_admin_menu_id,
//			'id'     => $bp->user_admin_menu_id . '-user-capabilities',
//			'title'  => __( 'User Capabilities', 'buddyboss' ),
//			'href'   => add_query_arg( [
//				'redirect_to' => urlencode( bp_displayed_user_domain() . 'settings/capabilities/' ),
//			], $link )
//		) );

		// User Admin > Delete Account.
		$wp_admin_bar->add_menu( array(
			'parent' => $bp->user_admin_menu_id,
			'id'     => $bp->user_admin_menu_id . '-delete-user',
			'title'  => __( 'Delete Account', 'buddyboss' ),
			'href'   => add_query_arg( [
				'redirect_to' => urlencode( bp_displayed_user_domain() . 'settings/delete-account/' ),
			], $link )
		) );

	}

}

Changelog

Changelog
Version Description
BuddyPress 1.5.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.