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
update_user_meta($subscriber_user_id,"name","value");
How can i populate the $subscriber_user_id
value correctly?
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.Hence:
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: