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 = &#039;<p class=&quot;private visitor-content visitor-only&quot;&#039; . $align_style . &#039;>&#039; . $content . &#039;</p>&#039;;

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.

Delicious Readings plugin goes 2.0

Yesterday I pushed to the WordPress repository a new version of my plugin Delicious Readings. If you don’t know this plugin, Delicious Readings lets you publish on your blog a collection of Delicious bookmarks stored with a particular tagged of your choice. So, for example, you can publish your bookmarks stored under “readings” or “pets” or “sushi” and so on.

The new version 2.0 adds the shortcode, in order to publish this list on a page or on a post. The idea comes from a user on the WordPress forums, who asked if there were the possibility to publish this list on a page rather than on a widget in the sidebar (already full of stuff). I was replying that he could call the plugin’s main function directly in the PHP code, but I thought it were better to add a shortcode for use in the writing panel.

Usage as shortcode

The shortcode accepts the full range of options of the core function. The only mandatory option is the address of the feed. So, for example, if your username is joe and the tag is books the shortcode will be:

[dreadings feed_url=""]

The plugin will show the last 5 bookmarks by default. If you want to show 10 bookmarks, change the shortcode as follows:

[dreadings feed_url="" quantity=10]

The tags aren’t displayed by default. If you want to show them, change the line in this way:

[dreadings feed_url="" quantity=10 display_tags=true]

This is the full set of options you can use (the value shown here is the default one):

date_text="Stored on:"
archive_text="More posts"

Change default values according to your needs.

Usage as PHP function

As I already said, you can use the plugin calling the main function directly in your PHP files:

<?php if ( function_exists( &#039;dr_fetch_feed&#039; ) ) {
    $args = array(
        &#039;feed_url&#039;         => &#039;&#039;,
        &#039;quantity&#039;         => 5,
        &#039;display_desc&#039;     => false,
        &#039;truncate&#039;         => 0,
        &#039;display_date&#039;     => false,
        &#039;date_text&#039;        => &#039;Stored on:&#039;,
        &#039;display_tags&#039;     => false,
        &#039;tags_text&#039;        => &#039;Tags:&#039;,
        &#039;display_hashtag&#039;  => true,
        &#039;display_arrow&#039;    => false,
        &#039;display_archive&#039;  => true,
        &#039;archive_text&#039;     => &#039;More posts&#039;,
        &#039;display_arch_arr&#039; => true,
        &#039;new_tab&#039;          => false,
        &#039;nofollow&#039;         => true,
    dr_fetch_feed( $args );
} ?>

Make sure to check if the opening <?php and closing ?> PHP tags are needed in your code. This is the full range of options — you can obviously use only those who need change.

The plugin is available on the WordPress repository and on GitHub.

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( &#039;editor&#039;,      &#039;read_ubn_editor_notes&#039;      );
    $wp_roles->add_cap( &#039;author&#039;,      &#039;read_ubn_author_notes&#039;      );
    $wp_roles->add_cap( &#039;contributor&#039;, &#039;read_ubn_contributor_notes&#039; );
    $wp_roles->add_cap( &#039;subscriber&#039;,  &#039;read_ubn_subscriber_notes&#039;  );
register_activation_hook( __FILE__, &#039;ubn_private_add_cap&#039; );

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( &#039;editor&#039; );
    if ( ! isset( $editor_role->capabilities[&#039;read_ubn_editor_notes&#039;] ) ) {
add_action( &#039;init&#039;, &#039;ubn_private_check_capability_exists&#039; );

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! :)

Hello, World!

Hello World! This is my dev site, a corner where I’ll write about my development updates. I’m not a hardcore code worker, but I love to write some lines when I have the time.

WordPress catched all my interest and I wrote a few plugins released in the WP repository: you can find all in the sidebar under “Projects” or in the dedicated page.

Hope you can find something useful and enjoy using them.