WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

On the user-profile page of my site I want to allow admin role users to be able to edit specific user-meta fields of subscriber role users.

How can I distinguish between the two user IDs.

The current logged in user is the admin user

get_current_user(); // returns the admin role user id

but I need to be able to access the subscriber ID to set the meta-data


How can i populate the $subscriber_user_id value correctly?

share|improve this question
up vote 3 down vote accepted

On the "profile page", i.e. user-edit.php in the admin back-end, the user ID of the profile currently being edited lives in the $user_id global.


global $user_id;
update_user_meta( $user_id, 'key', 'value' );

is the essence of what you are looking for.

Whether the current user is an admin needs to be checked only if you have the edit_users capability assigned to roles other than admins, which by default is not the case.

If you want the admins to only be able to save the metadata for subscribers, while having users of other roles, then you will have to check the edited users role before saving, obviously.

So, for the sake of completeness, the same with both checks in place:

global $current_user, $user_id;

/* user object of user being edited */
$edited_user = new WP_User( $user_id );

/* verify both users roles */
if (
    in_array( 'administrator', $current_user->roles ) &&
    in_array( 'subscriber', $edited_user->roles )
) {
    update_user_meta( $edited_user->ID, 'key', 'value' );
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.