WordPress Plugin: Cat-Pass
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
“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.
4 replies to “WordPress Plugin: Cat-Pass”
Roger Masse
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?
Daniel
Hmm, I need to look into this.
I don’t have this error. What Version of WP are you using?
Roger Masse
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();
}
}
}
Roger Masse
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