WordPress Plugin: Cat-Pass

By Daniel, 29. Oktober 2012

For some reason or other, you might want to allow access to certain posts only to certain people. You can use password-protection on Pages and Posts, but those need to be set individually.
It’s far simpler to just write a Post, specify a category and all posts in that category are password protected.
Imagine a family blog where certain posts are only visible to people who know the birthday of your first child, or remember your pet’s name.
Cat-Pass is not for super-sensitive information, it’s for casual use.

Installation is simple:

  • Download Cat-Pass
  • Unzip
  • upload cat-pass.php to yoursite/wp-content/plugins directory
  • activate
  • customize

Or:

  • In your WordPress Dashboard go to Plugins -> Install Plugins
  • Search for Cat-Pass
  • Install

Download Cat-Pass

“Awesome! This plugin is just what I’ve been looking for”

I’m so glad to hear that. I’ve been looking around for a feature such as this one and haven’t found anything similar, so I had to make it myself.
So here it comes: please donate a beer or two if I have been able to make your life easier. It’ll make my feel all warm and fuzzy inside, and you will feel it too.

11 Comments

  1. Roger Masse sagt:

    I really like the simplicity of the cat-pass plugin. It works as expected except that once I type the password and the content is rendered, I get the following error:

    Warning: Cannot modify header information – headers already sent by (output started at /home/content/27/5131427/html/wp-content/plugins/cat-pass/cat-pass.php:1) in /home/content/27/5131427/html/wp-content/plugins/cat-pass/cat-pass.php on line 17

    …on the resulting page. Line 17 is the setcookie call in the init function cat_pass_cookie.

    Any ideas?

  2. Daniel sagt:

    Hmm, I need to look into this.
    I don’t have this error. What Version of WP are you using?

  3. Roger Masse sagt:

    Hi Daniel —

    Sorry I didn’t include that. WordPress 3.5.1 It looks like at least one other person in your forum has the same issue. I suspect calling setcookie before any header output leads to this error… at least in 3.5.1. I ended up, temporarily anyway, using this hack in my theme’s functions.php. This leaves the setcookie work to the action target of the get_the_password_form(). This will only work for the newest versions of wordpress due to the cookie hashing that’s been recently added. However, I could quickly write up a version that works for older wordpress too if you’re interested. I prefer to use your plugin since it has such a nice configuration interface instead of hardcoded values in my hack.

    add_action( ‘wp’, ‘category_protect’ );

    if ( ! function_exists( ‘category_protect’ ) )
    {
    function category_protect() {

    global $post;

    if ( ! is_single() ) return false;

    if ( empty( $wp_hasher ) ) {
    require_once( ABSPATH . ‘wp-includes/class-phpass.php’ );
    // By default, use the portable hash from phpass
    $wp_hasher = new PasswordHash(8, true);
    }

    $password = ‘mysecretpassword’;
    $protected_categories = array(‘password-protected-category’);

    $stored_hash = stripslashes( $_COOKIE[ 'wp-postpass_' . COOKIEHASH ] );

    if ( in_category( $protected_categories, $post->ID ) && ! $wp_hasher->CheckPassword( $password, $stored_hash ) )
    {
    $post->post_content = get_the_password_form();
    }
    }
    }

  4. Roger Masse sagt:

    In my previous post I mentioned other posts in “your forum” I mean’t the wordpress support forum for the cat-pass plugin:

    http://wordpress.org/support/topic/error-in-wordpress-35

  5. Fredrik sagt:

    Hi!

    I’m running your Cat-Pass plugin on my WordPress website and it’s just perfect, thank you!
    I’m running WP 3.5.1. Now I have made an external page for mobiles which fetches a passwordprotected catagory and that’s works great. But for some reason i can’t get the password to be saved in a cookie so i have to type it in every time.
    Can you please help me?

  6. Davide sagt:

    Hi. your plugin is what I need.

    But, It’s possible to use the SAME password for ALL categories ?

    It seems not work.

    Thanks

    Davede

  7. Vadim sagt:

    Tell me how to put on each category unique password?

  8. Daniel sagt:

    Not possible, only one password for one category.

  9. Daniel sagt:

    No, sorry, it’s only possible to use one password for one category.
    It is a limited plugin I basically did for a special case and then gave to the world. And since nobody’s paying me to keep working on it … I can’t take it any further, sorry.
    You might want to look into using .htaccess to add a password to all your posts. You can use permalinks to create a “directory” for your posts and set in the .htaccess file that this directory requires identification.
    Hope it helps.

  10. Daniel sagt:

    The cookie-setting portion of the code is faulty or outdated, as someone pointed out to me.
    I don’t really have time or energy to continue development and, to be honest, I think I even forgot how to get my plugin into the WP Plugin Repository.

    Seeing a bunch of comments here, I think I will take another whack at it but that won’t be for another few weeks. Hope you can wait that long, and I hope I can fix it.

  11. Daniel sagt:

    Thank you,Roger.
    I want to look into my plugin again in a few weeks’ time. If it’s not yet too late, or you want to use my plugin as a base to publish your own, feel free to use it. (well … please credit me when you do :)
    I can see future versions supporting multiple categories and multiple passwords.
    But only 600something downloads might not be worth the effort. Especially since I did not receive one single buck in donations and that is kind of depressing.

What do you think?

Hinterlasse eine Antwort

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind markiert *

Du kannst folgende HTML-Tags benutzen: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>