Private Content 5.0 released

The Private Content plugin has reached the 5th major release with a very smart new option. Now the user can reverse the logic of the recipient option by enabling the new reverse option, so that users added in recipient are now excluded from reading the private note.

As you know, we can tell the plugin that some users can read a certain note. For example, only Alice will read the note “Text for Alice only”:

[private role="none" recipient="alice"]Text for Alice only.[/private]

You can use multiple users too, separating them with a comma:

[private role="none" recipient="alice, bob, charlie"]Text for Alice, Bob, and Charlie only.[/private]

Here comes the new reverse option. What about if I want to show the private note to all users, excluding Alice, Bob, and Charlie?

We can reverse the logic of the recipient option. The recipient option is activated with recipient=1 and this is an example:

[private role="none" recipient="alice, bob, charlie" reverse=1]Text for all users. Alice, Bob, and Charlie cannot read this.[/private]

Thanks to @blackbird69 on the WordPress forums for posting the question and giving me this idea!

Private content reaches v2.2

One of the frequently asked questions the users of my plugin Private Content do is the following:

Is there a way to display an alternate text to readers that haven’t the rights to read the hidden text

I’ve always answered that this plugin was designed to show only a simple note to the subscribers/collaborators, leaving other members/visitors out of any type of message. But often a developer can’t imagine all the possible usages a piece of software can encounter. This plugin, clearly, is used not only to display private notes/messages to some people, but also to display an alternative text if these readers haven’t the rights to read that note/message.

I’ve been always opposed to add this feature, but today I added it to Private Content. So, if you asked for it, update the plugin to version 2.2.


As usual write the to-be-hidden sentence wrapped into the shortcode, but add option alt, for example:

[private role="author" alt="Sorry, but you have not rights to read this."]Secret text for authors[/private]

In this way Authors (and higher members, like Editors and Amministrators) will read this, while lower members will read only Sorry, but you have not rights to read this.


Private content 2.1

A new version of my Private Content plugin has just been released! The new 2.1 version lets you show a note only to visitors and hide it to other users. So the shortcode now accepts this role:

[private role="visitor-only"]Text for Visitors only[/private]

As you probably know, there isn’t a role for Visitors. So, to accomplish this, the plugin makes a check if the user is logged in: if not, the note will be displayed and hidden to other logged-in users (Subscribers, Authors, and so on). Here the new code:

case 'visitor-only' :
    if ( ! is_user_logged_in() )
        $text = '<p class="private visitor-content visitor-only"' . $align_style . '>' . $content . '</p>';

As usual, the p element has an its own class, so you can stylize it as you like via CSS.

This new feature has been added thanks to Jacki, a reader of my Italian blog, who left a comment with this new idea.

Private content 2.0

My plugin Private Content has been updated to 2.0 and now you have a new feature: the possibility to exclude an higher role’s user from reading a lower role’s content. In other words, when in version below 2.0 we created a note for Subscribers, the higher roles could read this notes — and also in version 2.0 it works in the same way. But now it’s possible to hide a note to an Administrator, for example, and only the targeted group of users can read it, e.g. the Authors group.

How did I accomplish that?

The plugin creates a new capability for each role, obviously excluding the Administrator role:

function ubn_private_add_cap() {
    global $wp_roles;
    $wp_roles->add_cap( 'editor',      'read_ubn_editor_notes'      );
    $wp_roles->add_cap( 'author',      'read_ubn_author_notes'      );
    $wp_roles->add_cap( 'contributor', 'read_ubn_contributor_notes' );
    $wp_roles->add_cap( 'subscriber',  'read_ubn_subscriber_notes'  );
register_activation_hook( __FILE__, 'ubn_private_add_cap' );

The new capabilites are created on plugin activation and with this we are all done. But what in case of upgrading from versions below 2.0?

In case of upgrading, the plugin performs another check:

function ubn_private_check_capability_exists() {
    $editor_role = get_role( 'editor' );
    if ( ! isset( $editor_role->capabilities['read_ubn_editor_notes'] ) ) {
add_action( 'init', 'ubn_private_check_capability_exists' );

It looks for the presence of the capability read_ubn_editor_notes and, if it’s not in the database, the plugin will run the function for adding the new capabilities.

As usual, I’ve added the uninstall.php file to delete the new capabilities from the database: we all like to have and keep it clean. Something that every plugin develper should do.

This plugin is hosted in the WordPress repository, but you can find the development version on GitHub. Forks are welcome! :)