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

Grasping Gravatar: Your Digital Identity Across the Web

Grasping Gravatar: Your Digital Identity Across the Web

Are you tired of uploading your profile photo on different online platforms? Is your digital identity not synched? Digital identity helps you present yourself on the internet through your personal picture. It helps people recognize you. But is it uniform across...

5 Reasons Why You Should Hire a Custom WordPress Developer

5 Reasons Why You Should Hire a Custom WordPress Developer

A custom WordPress developer can develop your site perfectly based on your requirements. If you are considering building a WordPress website, it's possible you are unsure whether to hire a WordPress developer or do it yourself.  With the vast amount of resources on...

What’s Apple Business Connect and How to Use it for SEO

What’s Apple Business Connect and How to Use it for SEO

If you want your business to thrive, SEO is a must. When it comes to SEO, local SEO cannot be ignored, which simply means the presence of your platform on Google My Business. Well, that's good for people with Android devices who use Google Maps as their navigation....

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

Divi Extended
WPMozo
Divi WooCommerce Extended