How to assign capabilities to user NOT to User Role

Finally, I’ve figured out a way to do it using WP_user Class.

Snippet to add/remove capability to/from specific user –

//to remove capability from user
$user = new WP_User( $user_id );
$user->remove_cap( 'can_email');

//to add capability to user
$user = new WP_User( $user_id );
$user->add_cap( 'can_email');

There is special function in capabilities.php in the wp_user class to assign/revoke capability to/from user.

Leave a Comment