How to Customize WordPress Roles and Capabilities Without Hacking the Core

How to Customize WordPress Roles and Capabilities Without Hacking the Core

Here’s a handy tip for site admins who want to customize what user roles can and cannot do.

The best thing is that you can make these changes without hacking the WordPress core. You can add the changes directly to your functions.php file. Here are a few examples, courtesy of isitwp.com:

<?php
# Get the user role #
$edit_contributor = get_role('contributor');
# Contributor can upload media #
$edit_contributor->add_cap('upload_files');
# Contributor can no longer delete posts #
$edit_contributor->remove_cap('delete_posts');
?>

It’s important to note here that these capabilities are written to the database. If you need to give back a capability to a role, you have to use the add_cap() function.

Free Video Why 100 is NOT a Perfect Google PageSpeed Score (*5 Min Watch) Learn how to use Google PageSpeed Insights to set realistic goals, improve site speed, and why aiming for a perfect 100 is the WRONG goal.
Tags: