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

2023 in Review: Celebrating Creativity and Growth at Elicus

2023 in Review: Celebrating Creativity and Growth at Elicus

2023 was a remarkable year for Elicus with new beginnings, amazing growth, and impressive contributions to the WordPress community. We not only enjoyed the pleasure of getting a new wonderful work environment but also welcomed new amazing talents to our team. We...

DiviExtended’s Black Friday Sale: Mega Savings + Win an iPad!

DiviExtended’s Black Friday Sale: Mega Savings + Win an iPad!

The Divi Extended Black Friday Sale is On The Horizon! It's that time of the year when Elicus is all set to launch its biggest sale of the year on DiviExtended.com. We are starting the sale early this year and it goes live on November 21st at 12 Noon UTC. The Elicus...

Elicus’ Journey at WordCamp Bhopal 2023

Elicus’ Journey at WordCamp Bhopal 2023

Continuing our love for WordPress and the journey we embarked on more than a decade ago, the team had the opportunity to visit the city of Lakes Bhopal for our next WordCamp event. Being a company that is fully based on products and services related to WordPress it...

How to Detect AI Content Effectively in 2024? Tips, Tricks and Tools

How to Detect AI Content Effectively in 2024? Tips, Tricks and Tools

If you want to detect AI content, consider all measures.  People are smart, and when it comes to AI content, they can go beyond all limits. Every day, there’s a new update or platform launched that provides content sensationally close to human writing, and if you...

Divi Extended
WPMozo
Divi WooCommerce Extended