• Hi,

    I am new to customising WordPress.
    I want to create a guest user account that basically have all the access except for seeing the Users menu.

    I’ve found this page on the function that will do the job but have not sure where to put the code to run it.

    https://codex.wordpress.org/Function_Reference/remove_cap

    Can anyone please tell me where to write this code and how to run it?

    I’ve read that maybe creating a page template?
    But I think I only need to do this once and that specific user will have no access to the Users menu.

    Or should remove that capability from the db?

    Thanks.

Viewing 3 replies - 1 through 3 (of 3 total)
  • You can put the code to the active theme’s functions.php file.

    Thread Starter fedomain

    (@fedomain)

    Thanks, Rajesh.
    I’ve added the following code to my functions.php in my child theme folder but it is not doing anything.

    function remove_edit_users_from_specific_user() {
    // Remove a capability from a specific user.
    $user_id = 2; // The ID of the user to remove the capability from.
    $user = new WP_User( $user_id );
    $user->remove_cap( 'edit_users' );
    }

    Do I need to refresh or reload something?

    Thanks.

    You also need to call that function.

    Add this…

    remove_edit_users_from_specific_user()
Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Adding custom code to WordPress’ is closed to new replies.