🔥 Cyber Monday Sale is Live! 30% Off Sitewide

Grab the biggest deal of the year 🛍️ Buy Lifetime Membership

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

WordPress Black Friday Sale
What Is a Blog: Definition of Blogging + Examples of Blog Websites

What Is a Blog: Definition of Blogging + Examples of Blog Websites

Do you know approximately 70 million blog posts are published each day? Yes, this much. Almost 77% of internet users still read blogs online. In today’s digital era, blogs are significant in social media marketing. They are more than just a kind of online journal,...

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...

Divi Extended cyber monday sale
Cyber Monday Popup