cjblue
cjblue

Reputation: 1

WordPress - remove capabilities based on user id

I current have this code written:

add_action( 'init', 'hide_user_caps' );
function hide_user_caps() {
    $user_id = 1;
    $user = new WP_User( $user_id );
    $user->remove_cap( 'edit_posts' );
}

However, this doesn't seem to be doing anything. Any ideas?

Thank you

Upvotes: 0

Views: 331

Answers (1)

BOZ
BOZ

Reputation: 2020

If you want to specifically deny a capability from a user (not a role), you need to use the add_cap()[1] method and specify that the $grant parameter is false. [2].

$user_id = 1;
$user = new WP_User( $user_id );
$user->add_cap( 'edit_posts', false );

Upvotes: 0

Related Questions