Change WordPress user roles and capabilities › Forums › How to or FAQ › Custom User Edit Page › Reply To: Custom User Edit Page
27/04/2017 at 15:28
#3637
Keymaster
Hi,
It’s possible to hide ‘Edit’ link under every user row at users.php and block access to user profile editing adding this code to functions.php of active theme:
add_filter('user_row_actions', 'custom_user_row_actions', 10, 2);
function custom_user_row_actions($actions, $user) {
if (current_user_can('user-manager')) {
unset($actions['edit']);
}
return $actions;
}
add_action('admin_head', 'custom_block_user_profile', 101);
function custom_block_user_profile() {
$url = strtolower($_SERVER['REQUEST_URI']);
if (strpos($url, 'user-edit.php')===false) {
return;
}
if (!current_user_can('user-manager')) {
return;
}
$url = admin_url() .'/users.php';
if (headers_sent()) {
?>
<script>
document.location.href = '<?php echo $url; ?>';
</script>
<?php
die;
} else {
wp_redirect($url);
}
}
So it seems that task was resolved as users.php has a “Grant Roles” button. But I discovered a problem here with your help. Thanks. User without ‘ure_manage_options’ capability can not use “Grant Roles” button. He will get “Not enough permissions” error message on a try to change user’s roles. It’s really wrong.
So I have to update base version of ‘User Role Editor’ to fix this issue. Let’s wait a next update – about a week.