How to allow “Add New” capability of CPT when links to its UI are placed as a submenu?

The problem is that when the special subscriber tries to Add New a sub-cpt post, it is denied permission. However, when the CPT menu is a top-admin-menu, then everything works out fine. The issue is related to the placement of the CPT’s UI menu in the back-end: if it’s top-level (show_in_menu=TRUE), all is well; if … Read more

Prevent author role from editing all posts in custom post type?

You should declare your desired capabilities when you are registering the post type. Justin’s article here is a good one for custom post types: http://justintadlock.com/archives/2010/04/29/custom-post-types-in-wordpress When you are registering your custom post type, you can set this to be standard capabilities for posts, eg: ‘capability_type’ => ‘post’, or to be standard capabilities for pages, eg. … Read more

Custom role capabilities to administrator not taking effect (no plugin)

Capabilities are stored in database, that is why they keep active even if you remove your function. Capabilities need to be expressly removed: $admin = get_role(‘author’); $admin->remove_cap( ‘edit_teacher’ ); And, because they are stored in database, you should stop adding them in every page load (as you are doing in init event). Usually, you should … 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

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