Stephanie Leary

Writer and WordPress consultant

  • Books
    • Content Strategy for WordPress (2015)
    • WordPress for Web Developers (2013)
    • Beginning WordPress 3 (2010)
  • Blog
    • Fascism Watch (2016-17)
    • Content Modeling for WordPress series
    • WordPress Hidden Gems series
  • Work
    • Portfolio
    • Services
    • WordPress Plugins
    • WordPress Themes
    • Presentations and Interviews
    • on GitHub →
  • About
    • Press Kit
  • Contact
    • Mailing List

Changing roles’ capabilities

February 4, 2010 Stephanie Leary 1 Comment

If you need to change one or two capabilities, it’s relatively easy to do so with a few lines of code in a plugin or your theme functions file. For example, if we wanted to allow any logged-in user to view our private posts and pages, we would need to grant them two additional capabilities.

<?php
// allow subscribers to view private posts and pages
$PrivateRole = get_role('subscriber');
$PrivateRole -> add_cap('read_private_pages');
$PrivateRole -> add_cap('read_private_posts');
?>

The first line fetches the existing subscriber role (as an object) and assigns to it a variable. In the next two lines, we add the capabilities to read private posts and pages to our variable. That’s it! Any subscribers can now read your private content — and so can authors and contributors, whose roles include all the capabilities of subscribers. (Remember that editors and administrators already had these particular capabilities.)

Adding capabilities by hand, one at a time, will be a pain if you need to make a lot of changes. If that’s the case, I recommend Justin Tadlock’s Members plugin, which provides an elegant user interface for modifying roles, and also includes some great features for managing content permissions.

WordPress capabilities, permissions, Privacy, private, Users and Roles

Comments

  1. Ben says

    March 12, 2012 at 4:01 pm

    Totally worked great! Thanks so much!!!

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Latest WordPress Book

Content Strategy for WordPress

A short book for content strategists and managers on implementing a complete content strategy in WordPress: evaluation, analysis, content modeling, editing and workflows, and long-term planning and maintenance.

Read the sample chapter

Kindle Nook iBooks Kobo Smashwords

WordPress for Web Developers

WordPress for Web Developers (9781430258667)

This is a book for professional web designers and developers who already know HTML and CSS, and want to learn to build sites with WordPress. The book begins with a detailed tour of the administration screens and settings, then digs into server-side topics like performance and security. The second half of the book is devoted to development: learning to build WordPress themes and plugins.

This is the second, much-revised and updated edition of Beginning WordPress 3, with a more accurate title. Everything’s been updated for WordPress 3.6.

WordPress for Web Developers is out now. See what's inside...

The best WordPress features you’ve never noticed

  • WordPress Hidden Gems: Screen Options
  • WordPress Hidden Gems: Bulk Edit
  • WordPress Hidden Gems: Private Status
  • WordPress Hidden Gems: Dashboard Feed Readers
  • WordPress Hidden Gems: Options.php

Content Modeling for WordPress series

  • Content modeling for WordPress, part 1: analyze content
  • Content modeling for WordPress, part 2: functional and organizational requirements
  • Content modeling for WordPress, part 3: a sample content model

This is an excerpt from Content Strategy for WordPress.My latest books are Content Strategy for WordPress (2015) and WordPress for Web Developers (2013). Sign up to be notified when I have a new book for you.

Copyright © 2022 Stephanie Leary