Allow role to delete posts but block him the wp-admin

Assuming you’re talking about a custom user role named “photographer“, I believe something like this should add the delete_posts capability to that role. function add_delete_cap_to_photog_role() { $role = get_role( ‘photographer’ ); $role->add_cap( ‘delete_posts’ ); } add_action( ‘admin_init’, ‘add_delete_cap_to_photog_role’); After adding the caps to the role, to solve the rest you could either keep blockusers_init and … Read more

How to get all users with Author role capabilities?

Here’s a way to collect roles with the publish_posts capability: $roles__in = []; foreach( wp_roles()->roles as $role_slug => $role ) { if( ! empty( $role[‘capabilities’][‘publish_posts’] ) ) $roles__in[] = $role_slug; } and then we can query users with these roles: if( $roles__in ) $users = get_users( [ ‘roles__in’ => $roles__in, ‘fields’ => ‘ids’ ] ); … Read more

Check whether user can delete a given post

After hours of fighting to get this to work, it was just a matter of changing delete_posts to delete_post. So, in it’s entirety this would be: current_user_can(‘delete_posts’, $post_id); to current_user_can(‘delete_post’, $post_id); current_user_can does accept a second parameter. Though it’s weird that the function declaration in capabilities.php does not define a second parameter as pointed out … Read more

How can I prevent a writer from being able to edit an article that has been scheduled?

Me, like @fischi think that filter ‘user_has_cap’ is the best choiche for the pourpose, however, I think that is better to the work, regardless the $_GET post or action: WordPress check the meta cabability on a per-post basis, using an additional argument. In few words, when filtering ‘user_has_cap’ for a meta capability (see https://codex.wordpress.org/Function_Reference/map_meta_cap) we … Read more

How to delete user roles?

$wp_roles = new WP_Roles(); // create new role object $wp_roles->remove_role(‘name_of_role’); If you need to check the name_of_role use $wp_roles->get_names(); you will get an array of name_of_role => Nicename of Role Alternatively, you could use the global object $wp_roles global $wp_roles;

Can wp-cli display all users and their roles across all sites in a multisite instance?

List all the admins of each site Side note: Dividing these up by site would also be handy. Let’s do that here: We can list the url of each site with: wp site list –field=url We can list all administrators of a given site with: wp user list –role=administrator –url=https://example.tld/site1 These commands can be combined … Read more

How to add another user to this remove_menu function?

Why not just add another if? function remove_menus(){ global $menu; global $current_user; get_currentuserinfo(); //check first user if($current_user->user_login == ‘user1’){ $restricted = array( __(‘Links’), __(‘Comments’), __(‘Appearance’), __(‘Plugins’), __(‘Profile’), __(‘Tools’), __(‘Settings’) ); end ($menu); while (prev($menu)){ $value = explode(‘ ‘,$menu[key($menu)][0]); if(in_array($value[0] != NULL?$value[0]:”” , $restricted)){unset($menu[key($menu)]);} } } //check second user if($current_user->user_login == ‘user2’){ $restricted = array( __(‘Links’), … Read more

How to get a user role of a specific blog in multisite?

You can use either WP_User: $wp_user_obj = new WP_User( // $user_id get_current_user_id(), // $name | login, ignored if $user_id is set ”, // $blog_id get_current_blog_id() ); Or get_users(): $get_users_obj = get_users( array( ‘blog_id’ => get_current_blog_id(), ‘search’ => get_current_user_id() ) ); As they are both blog_id perceptive, if you provide it. The former will return a … Read more

How To Remove Dashboard Menu Items for Multisite Users?

1) Install & network activate User Role Editor plugin from http://example.com/wp-admin/network/plugins.php 2) Then go to Settings > User Role Editor menu on network and make sure you have the settings as shown in following screenshot. 3) Go to “User Role Editor” settings page on your main site http://example.com/wp-admin/users.php?page=users-user-role-editor.php and select the “Administrator” role. Then remove … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)