🎉 Black Friday Sale starts soon! 24 Save the date

0Days

0Hours

0Minutes

0Seconds

Feb 22, 2017 | WordPress

Use of map_meta_cap WordPress filter

This WordPress filter is used to revoke the access of edit from any particular user role. This function is called by WP_User->has_cap() to convert a meta capability to one or more primitive capabilities.

What are the meta capabilities

Meta capabilities are capabilities granted to a user on a post. Meta capabilities value could be:

  • ‘delete_page’
  • ‘delete_post’
  • ‘delete_user’
  • ‘edit_comment’ (3.1. Mapped to ‘edit_post’ meta capability.)
  • ‘edit_page’
  • ‘edit_post’
  • ‘edit_user’
  • ‘publish_post’ (3.5)
  • ‘promote_user’
  • ‘read_post’
  • ‘read_page’
  • ‘remove_user’

For regular WordPress posts grant these capabilities automatically but if you’re dealing with custom posts with custom user role you will have to set these capabilities.

Addition of custom capabilities

Before mapping the capability we will have to create a custom role at your website.

This function will add new capability in database. You can also hook this function after theme setup.

Map Meta Capabilities for Portfolio Page

If you would like to give access to the particular post/page. You will have to figure out the post id. You can get it via WordPress dashboard. After that the by using the below function the custom user will be able to edit the defined posts. Here you can define the post type as well.

This function checks that the current user has required capability to edit the specific post. If so, make this capability our only required capability.

So Many Possibilities

There are so many more things that can be done with this filter:

  • Remove Tools capabilities from all users but the primary admin
  • Let editors manage widgets
  • Let author to manage some specific posts
  • Limit user to access their own posts.
  • Limit some Super Admins from adding sites on a multisite network etc, etc

Still confused?

I tried to cover as much as possible in this tutorial still you have any confusion. You can tweet me with your questions or comment below.

Posted By:
Mohammed Arif
Arif is Development Head at Elicus and has over 10 years experience in the development industry. He is passionate about WordPress. Follow him on Twitter @themohdarif.

0 Comments

0 Comments

Best WordPress Black Friday and Cyber Monday Deals 2025

Best WordPress Black Friday and Cyber Monday Deals 2025

It’s that time again — the top Black Friday deals of the year are live for WordPress professionals! It’s that time again — your once-a-year chance to grab exclusive, limited-time deals on top-quality plugins, themes, hosting, and services designed to help you build...

Why You Should Optimize Google Shopping Images and How

Why You Should Optimize Google Shopping Images and How

When it comes to visuals, product images are at the top of the charts. In addition to being visually appealing, they also assist customers in determining the product's appearance before making a purchase.  If product images can help your buyers make the right...

Best Halloween WordPress Deals on Plugins, Themes and Hosting in 2025

Best Halloween WordPress Deals on Plugins, Themes and Hosting in 2025

Get ready for Halloween 2025 with amazing WordPress savings! From updating your design with new themes to enhancing features with plugins or getting solid hosting, these eerie offers provide huge discounts. Check out our handpicked selection of top Halloween WordPress...

The Shift In Freelance Business Due to AI and How to Adapt

The Shift In Freelance Business Due to AI and How to Adapt

Transitioning from the contemporary freelancing landscape has never been on the increase as much as in 2025. There has been an increase in demand for innovative problem solvers rather than the usual problems faced in different industries.  This brings us to...

Divi Extended membership
WPMozo
Divi WooCommerce Extended