The enable_edit_any_user_configuration WordPress PHP filter allows administrators on a Multisite network to edit every user’s information.
Usage
add_filter('enable_edit_any_user_configuration', 'my_custom_function'); function my_custom_function($allow) { // your custom code here return $allow; }
Parameters
$allow
(bool) – Whether to allow editing of any user. Default is true.
More information
See WordPress Developer Resources: enable_edit_any_user_configuration
Examples
Restrict administrators from editing any user
Prevent administrators from editing any user on a Multisite network.
add_filter('enable_edit_any_user_configuration', '__return_false');
Allow administrators to edit users only with a specific role
Allow administrators to edit only users with the ‘author’ role.
add_filter('enable_edit_any_user_configuration', 'allow_edit_authors_only', 10, 2); function allow_edit_authors_only($allow, $user_id) { $user = get_userdata($user_id); return in_array('author', $user->roles); }
Disable user editing for specific user IDs
Disable user editing for user IDs 2, 5, and 7.
add_filter('enable_edit_any_user_configuration', 'disable_edit_for_specific_users', 10, 2); function disable_edit_for_specific_users($allow, $user_id) { $restricted_users = array(2, 5, 7); return !in_array($user_id, $restricted_users); }
Allow user editing only for administrators with a custom capability
Allow user editing only for administrators with the ‘edit_custom_users’ capability.
add_filter('enable_edit_any_user_configuration', 'allow_edit_for_custom_capability', 10, 2); function allow_edit_for_custom_capability($allow, $user_id) { return current_user_can('edit_custom_users'); }
Restrict user editing based on the logged-in user’s ID
Disallow user editing if the logged-in user’s ID is less than the user being edited.
add_filter('enable_edit_any_user_configuration', 'restrict_editing_based_on_logged_in_user', 10, 2); function restrict_editing_based_on_logged_in_user($allow, $user_id) { return get_current_user_id() >= $user_id; }