• Is there a function or an argument that I can include in my code that would automatically password protect my posts in a certain category. I am trying to eliminate having to select password protect and enter a password. In my category these will all be password protected with the same password.

    I am using a plug-in that will allow all password-protected to automatically have the same password. So I just need to figure out code that will make all posts in a certain category password-protected.
    The reason I am trying to eliminate this step of having to go in and select password protect and enter a password is because I going to post via e-mail. If can’t eliminate these steps then after I e-mail my post I have to log into WordPress and make these changes. It defeats the purpose of posting via e-mail.

    I did find this function <?php post_password_required( $post ); ?> in the codex. I am not sure how to use it or even where to place it.
    I thank you in advance for any help.

Viewing 9 replies - 16 through 24 (of 24 total)
  • I’ll check it out, thanks for the suggestion.
    Maybe I can take some parts and put together a plugin myself.

    keep my previous comment in mind:

    Seems there’s no way to access a category page to make it password protected, and redirect doesn’t work since the category is not really protected, only the page that refirects to it.

    I was talking about wp category pages, you can do it with a custom page template and a category query, but you’d need one for each user or role, or “pet name” ect.

    and, this is only so “secure” because the category is not protected, only the page. However should be good enough for your purpose. Juat don’t allow access to categories except throgh the pages.

    Using a category-x.php file to password-protect a category is no good, since you can bypass it by going to a post directly.

    I could manually make the password appear in post.php (if category …) and have the index.php check for a post’s category and either display the excerpt or a “password-protected” message.

    What I want is a plugin, since I don’t want to implement this in every theme that I use, and sometimes I buy themes that are pretty un-friendly when it comes to edits (one-line-code and other such nonsense) so I’m mainly looking for a way to hook in to the display process and get that to check for category X.

    Thanks for the input, though. If you know how to hook in to the “displaying” process of wordpress to insert a “if category” thing, then please tell me πŸ™‚
    My previous 2 plugins were developed a long time ago and I seem to have forgotten a whole lot since then πŸ™‚

    the category is not protected, only the page. However should be good enough for your purpose

    yes, not truely secure but works for keeping content seperated per user or user level. guess I wouldn’t anticipate a need for strict security for pet posts, haha..

    I may not quite understand where you’re going with this, I’ve never made a plugin.. not sure what it entails.

    If you are just talking about

    <?php if(is_category('ID'));?>
    (output code)
    <?php else {?>
    (something else)
    <?php } ?>

    otherwise, no sure what you mean by “displaying process”

    Did my latest post with sample code not work? Did anyone try it?

    I can’t remember if I did or not, it was a while ago and I think I ended up not needing it.
    I don’t think there’s a plugin that checks posts for private categories like that. I’ll have to test it just for the heck of it.

    Maybe it will help mores..?

    Here’s the first bit of what I’m working on.

    function cat_pass($content) {
    	global $wpdb;
    	global $post;
    
    	$cat_pass_cat = get_option('cat_pass_cat');
    	if (!$cat_pass_cat) : $cat_pass_cat = 107; endif;
    	$post = get_post($id);
    	if ($post->post_type=='post') :
    		if ( in_category(107, $post) ) : $content = "Nope. You no see dis!"; endif;
    	endif;
    	return $content;
    }
    
    add_filter( 'the_content', 'cat_pass' );

    All it does is check if a post is in a certain category, then replaces the content (and excerpt) with a text.

    Next step: upgrade this to 1) create a back-end to set password and category to protect and 2) display the password field instead of my nifty little text πŸ™‚

    Final step: use cookies to save the password so you don’t need to enter it all the time.

    What’s good about using a filter is that it cannot be bypassed by going around a category-page or something – each post in this category will only show its content when the password is given.

    EDIT: this bit can be used in a functions.php too. I’ll just make it a plugin for the ease of use and a nice back-end. Otherwise you need to manually insert the right category-id.

    right, and it looks like Beer’s code may take care of #2..?

    Update for those who care πŸ™‚ :
    Plugin now replaces protected content with a password form. If you enter the password, you get to see the content. Cookie is set so you don*’t have to enter it all the time.
    Next step: back-end category selector.

    Beer’s code unfortunately wasn’t helpful for me, because it works on another level and uses the post-password feature.

Viewing 9 replies - 16 through 24 (of 24 total)

The topic ‘automatically password protecting posts’ is closed to new replies.