Private Content plugin and custom roles

A short post to explain how to use custom roles with Private Content plugin.

As you already know, my Private Content Plugin works fine with WordPress built-in standard roles. Sometimes a user asks for more informations on how the plugin works with custom roles. Let’s see that in this post.

The form of the shortcode is the following:

[private role="author"]Text for Authors[/private]

This shortcode will show the text “Text for Authors” to these roles: Administrators, Editors, and Authors, because Authors is a role lower than the two others according to this list:

  • Administrator
  • Editor
  • Author
  • Contributor
  • Subscriber

As you know, the Private Content plugin can show a text to the intended role only. So, for example, we can write a note that only Editors can see:

[private role="editor-only"]Text for Editors only[/private]

Now, let’s say that we have a custom role, for example “Friends”, and we want to show them some notes inside our posts. In this case, we cannot use the following form:

[private role="friends"]Text for Friends[/private]

since friends is not a standard WordPress role. In this case we must pick up one of the standard WordPress roles and assign it one of the capabilities defined by Private Content plugin. These capabilities are:

  • read_ubn_editor_notes
  • read_ubn_author_notes
  • read_ubn_contributor_notes
  • read_ubn_subscriber_notes

Mapping one of the capabilities to one WordPress role is easy with a plugin like Members or Capability Manager Enhanced.

Let’s say we decide that Friends can read notes for Editors. Using one of those plugins, assign the capability read_ubn_editor_notes to the Friends role. Now Friends can read the notes for Editors only. Note the difference: now Friends can read notes marked with the option role="editor-only" while cannot read notes marked simply as role="editor".

I hope that things are clearer now. Someone asked why the plugin hasn’t an internal management of roles and capabilities. The answer is that the plugin was developed to remain simple. It was created to give a simple way to show some text to some users while hiding it to others. Adding more features will require a total reorganization of the plugin, and this is beyond the scope of its development.

Photo courtesy: geralt, Untitled, CC0 Public Domain.

Author: aldolat

A WordPress fanatic.

Leave a Reply

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