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

WebP, PNG, JPEG or SVG: Your Image Formats’ Guide for WordPress

WebP, PNG, JPEG or SVG: Your Image Formats’ Guide for WordPress

Do you get confused when uploading images on your website? Many website owners feel the same due to the many types of image formats available. For example, there are WebP, PNG, JPEG, and SVG. All these can be uploaded to a website, but some of these image formats are...

The Future of User Experience: Top 12 UX/UI Trends for 2024

The Future of User Experience: Top 12 UX/UI Trends for 2024

The digital world is constantly evolving, demanding fresh approaches to web aesthetics and functionality. One thing that can’t be sidelined is user satisfaction.  UX/UI (user experience/user interface) following the latest trends is more likely to retain your...

Envato Elements: Why It Is Good for Your WordPress Business

Envato Elements: Why It Is Good for Your WordPress Business

Managing a WordPress business can be overwhelming due to the time and costs involved. The tasks seem endless, from crafting a website to optimizing it for SEO and running marketing campaigns to promote your products.  For many small businesses, finding ways to...

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

Divi Extended
WPMozo
Divi WooCommerce Extended