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 by @amit. May be someone can clarify why it is so.
Related Posts:
- What action should I hook into when adding roles and capabilities?
- What’s the difference between Role and Meta capabilities; When to use map_meta_cap() filter
- Disable posts, only allow to edit existing pages, not create new ones (create_posts)
- How to get all capabilities of an existing user role
- Does the “promote_users” capability allow someone to create a new admin account?
- Add Media Upload Capabilities Needed for Custom Role for non-Posts
- How can I prevent a writer from being able to edit an article that has been scheduled?
- Allow unfiltered HTML in titles for low level users?
- Allow users to set a post author
- Unify the roles and caps?
- Filter list of rules based on a capability
- Using author_can() on custom post types in WordPress
- How to show a admin bar menu item only to users with certain capabilities?
- Theme option editing capability problems
- Assign multiple roles , overlapping capabilities
- WordPress remove capability post ,media completely for custom role
- Add capability to a role , so user is only able to view his own posts
- Is there a way of retrieving the core WP capabilities?
- Best Roles and Capability on a site with review features using a front end custom post
- Manage Roles and Capabilities on Multi-site
- Getting a List of Currently Available Roles on a WordPress Site?
- Editor can create any new user except administrator
- Allowing custom role access to custom post type in back end
- Allow Contributor to change the author of his own post?
- What do unfiltered_html and unfiltered_upload actually filter?
- Temporary capability for current_user_can()
- How can I modify the Capability needed to access a plugin’s options?
- How to enable a site administrator to edit users in a WordPress network/ multisite setup?
- Can I make user role that can only access a certian content type?
- How to check user role without using current_user_can()
- How to update role capabilities
- Menu capability in WordPress
- Roles & capabilities GUI that does not create separate table
- How to assign capabilities to user NOT to User Role
- Add user capability and check against it
- how to add custom user capabilities using add_user_meta or something else?
- add_cap only adding the first two in array
- New Roles and Capabilities in WordPress
- Capability for allowing user to post own comments without moderation
- Custom role based users are not able to access wp-admin
- Limit access to page depending on user level
- Prevent custom user role to add new pages
- how to assign more permission to wordpress author
- The delete_posts capability?
- Capabilites not working [closed]
- Allow Administrator role access to custom capabilities [duplicate]
- create_users capabilities on a role on multisite
- Get User Role by ID not working
- Remove menu items from admin page and limit capabilities
- How to get an array of user roles with or without a specific capability?
- How to restrict CPT post’s fronted view only for specific user roles?
- Adding Capabilities to a WordPress User Account
- User capability per post
- Adding Custom Capabilites
- User: Editor, can’t see edit taxonomy screen
- Custom post types as sub menu pages and role capabilities issue
- How to set individual capability of post type in individual category
- Why is unfiltered_upload not working despite being enabled?
- WooCommerce Customer Role Delete Custom Post Type
- bbPress plugin moderator roles
- Allowing user to edit posts based on the post status
- Disable user from updating certain posts
- Access to CPT but not to ‘post’ post type
- Make nav-menus.php available for editor
- Where are $current_user->allcaps set?
- Purpose of Adding Capability to Role But Not Grant?
- Create a User Role with permissions to only upload files to the media library?
- How to get a users list by who created them?
- WordPress custom post type capabilities issue
- Hiding custom theme functionality using capabilities
- How to keep the capability of users and disable Gutenberg editor in WordPress?
- How to write conditions based on user capabilities not on user role?
- What Capability is required to let a role RUN code in Edit Theme?
- Can I Create a Second Admin Level User Role?
- The Capability to choose post/page template
- Add capability to “Editor” role to be able to view all users attachments
- how do I add role and capability after I create a new user
- Creating a folder structure
- How to hide plugin options for editors via functions.php
- Adding plugin editing capability for Author
- Why can my subscribers create new posts for review?
- Disabled delete_others_posts if post is from admin
- Why “Mine” is the default view when adding ‘capability_type’ in register_post_type
- How can restrict certain users from delete a category but can view only in wordpress?
- How to only display all posts to a custom User Role?
- Delete admin edit/delete links in users list wordpress admin
- How to give custom roles the capability to edit one Menu instead of every Menu
- Role and Capabilities: How do I allow user role to access theme options without enabling ‘manage_options’?
- fine-grained capabilities for user related capabilities
- Multiple useres editing specified content
- Remove dashboard links from wordpress
- Capability to edit post slugs
- Capibilities of CPT WordPress
- Why user profile update creates Additional Capabilities
- A different role for each site in a multisite
- Changing capability type without altering plugin
- Need to create admin user without capability to create user
- Custom role, capabilities, and post type: preview button wrecks things
- Grant access to admin menu?
- edit slider plugin capability for custom_role