Why does current_user_can(‘edit_posts’) return true, but current_user_can(‘edit_post’, $post->ID) returns false?
The post in question is published, but your user is missing the edit_published_posts capability, so they’re not allowed to edit it.
The post in question is published, but your user is missing the edit_published_posts capability, so they’re not allowed to edit it.
Is there a filter for that? Yup, there is, and the hook name is user_has_cap. So try this, which worked for me in WordPress 5.6.1 (latest release as of writing): add_filter( ‘user_has_cap’, ‘wpse_383109’, 10, 4 ); function wpse_383109( $allcaps, $caps, $args, $user ) { if ( empty( $args[2] ) || ‘edit_user’ !== $args[0] || ! … Read more
The easiest way is to use if ( current_user_can( ‘capability’ ) ) // do stuff. You’ll find more about capabilities in the codex. You can also inspect the data some user has attached with normal var_dump() and else. I also got a pretty old plugin for that. But I’m not sure if it still works … Read more
Is this right: First 5 pages – Administrators ONLY, NO subscribers Sixth page – Subscriber ONLY, NO Administrator ? If this is correct than you only have to add the capability type as ‘administrator’ when creating the first 5, and ‘subscriber’ for creating the sixth. That should work. Or add a new capability for admin, … Read more
User Role Editor plugin allows you to create custom roles easily, and if you wish, change any standard WordPress user role (except administrator) as well. This plugin is very well maintained. But just in case you haven’t, I would like to suggest that you first consider reading about the various pre-defined Roles in WordPress and … Read more
What you need first is to understand User Roles in WordPress. Then a plugin to manage custom user roles, like User Role Editor or Members. In the administrative menu Settings > General, set the default role when a user registers to your custom role: The plugin Members has more advanced features, but case you were … Read more
This one’s a little difficult, as there’s no default user role meta key or post data. The only thing we got is the user ID. // Get the posts $posts_by_author_ID = get_posts( array( ‘post_type’ => ‘post’ ,’post_status’ => ‘publish’ ,’orderby’ => ‘post_author’ ,’order’ => ‘DESC’ ) ); foreach ( $posts_by_author_ID as $post ) { static … Read more
There are two ways to do this. Almost any decent membership management plugin will enable you to restrict content to a given user role and plugins such as Role Scoper are even more flexible. For a more code-based solution you would add some variation of the following to the desired theme template files where ever … Read more
No need to apologize, and not a basic question actually. Depending on what you actually need to achieve once you have your multiple authors assigned, there are several ways to do it: Using tags or equivalent custom taxonomy If you just need to display “authorship” for any given post, you could create a custom non-hierarchical … Read more
Try to specify the following capability, it helped in my case: ,’delete_published_posts’ => ‘delete_published_mro_project’