Custom capability for a single user

I solved it myself 🙂 I just added custom capability to the user- $user = new WP_User(1); //1 is the admin ID $user->add_cap( ‘see_encrypted_pass’ ); Then checked- if(current_user_can(‘see_encrypted_pass’)){ //encrypted password } It works!!

same user role or copy the user role to be same as the other role

Contributor has the following capabilities delete_posts edit_posts read You can create the “Seller” role to have same capabilities as Contributor add_role( ‘seller’, __( ‘Seller’ ), array( ‘read’ => true, ‘edit_posts’ => true, ‘delete_posts’ => true, ) ); Warning from codex NB: This setting is saved to the database (in table wp_options, field wp_user_roles), so it … Read more

Add capability to a role , so user is only able to view his own posts

First of all you need to remove capability edit_others_posts if assigned to vendor role. Then use the code snippet given below: function posts_for_current_author($query) { global $pagenow; if( ‘edit.php’ != $pagenow || !$query->is_admin ) return $query; if( !current_user_can( ‘edit_others_posts’ ) ) { global $user_ID; $query->set(‘author’, $user_ID ); } return $query; } add_filter(‘pre_get_posts’, ‘posts_for_current_author’); Above code allows … Read more

Let editors view post in admin but not be able to perform a save/edit

How about remove_meta_box( $id, $page, $context );? https://codex.wordpress.org/Function_Reference/remove_meta_box This will remove the Publish meta box which contains the save button… function disable_save() { if( !current_user_can( ‘edit_post’ ) ) { // Or whatever check you need to make remove_meta_box( ‘submitdiv’, ‘your-chosen-post-type’, ‘side’ ); } } // disable_save add_action( ‘admin_menu’, ‘disable_save’ );

Redirect admin 403 “Cheatin uh?” admin pages

Sounds like this is what you’re running into. admin_page_access_denied may be the hook you want to use for this. try function dont_show_cheatin_page() { if ( current_user_can( ‘do_not_allow’ ) ) { wp_safe_redirect( admin_url()); // custom redirect instead of Cheatin 403 page exit; } } add_action(‘admin_page_access_denied’, ‘dont_show_cheatin_page’);