• Hello all,

    The majority of posts on my site are standard blog entries, however there are a couple which I wish to password protect. If a post is password protected I do not wish to have it show up at all on the main blog page. (i.e. is_home() )

    However, if someone goes directly to the permalink for the password protected post they are given the standard “this page is password protected” form and asked to enter the password.

    The goal is for casual visitors to the site to not know of the existence of the password protected posts. I will send an e-mail to someone with the link to the permalink and password for that post if I wish them to know of its existence.

    I have tried writing a very basic plugin which would do the job (as I don’t want to alter the core), but am having ‘issues.’ Is there a way for me to address only posts that are flagged as password protected and have them not display when the_content() is called?

    Any help greatly appreciated! Thanks in advance

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter 760110

    Just as a follow-up, here’s what I’ve written already. It was a test to see if I could remove the title from password protected posts:

    function really_simple_function(){
    	$post = &get_post($id);
    	$title = $post->post_title;
    
    	if(substr($title, 0, 10) == 'protected:'){
    		$my_title = '';
    		return $my_title;
    	}else{
    		return $title;
    	}
    
    }
    
    add_filter('the_title', 'really_simple_function');

    What this does is remove the “Protected:” prefix to the posts that are password protected and not remove the whole title itself… some might find this actually useful, but it isn’t doing what I’d hoped. Any advances?

    Thread Starter 760110

    Just as a follow up, the existing plugin at http://www.schloebe.de/wordpress/admin-management-xtended-plugin/#english does as intended, just need to work out why 😉

    Thread Starter 760110

    As a further follow up it doesn’t appear the the Admin Management Extended doens’t work flawlessly. So i have written some PHP to modify the them, it is as follows:

    <?php if(have_posts()) : ?><?php while(have_posts()) : the_post(); ?>
    
    <?php
    	$post = &get_post($id);
    	if ( !empty($post->post_password) ) { //if the post has a password
    	if ( is_home() ) { //and if we're on the home page
    			//then don't print out that post at all
    	?>
    	<div class="no_content">
    
    	</div>
    
    	<?php
    
    	}else{	//we're not on the home page, so print out the post
    		//which would be the password form
    
    	?>
    <div class="content">
    <h2>
    <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a>
    </h2>
    
    <?php the_content("...continue reading:  " . get_the_title('', '', false)); ?>
    <?php edit_post_link('Edit', ' | ', ' | '); ?>
    
    </div>
    
    <?php
    	}
    }else{	//there is no password for the post
    	//so print out the actual post
    
    	?>
    
    <div class="content">
    
    <h2>
    <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a>
    </h2>
    
    <?php the_content("...continue reading:  " . get_the_title('', '', false)); ?>
    <?php edit_post_link('Edit', ' | ', ' | '); ?>
    
    </div>
    
    <?php
    	}
    ?>
    
    <?php endwhile; ?>
    
    <?php endif; ?>

    This grabs the post, finds out whether it has a password attached to it, if it is, then finds out if it is on the home page, if it is, then it just prints out a blank div (you can add some content here if you wish).

    If the post has a password but we’re not on the homepage then we want to go through the normal loop and display the post (which would initially be the ‘enter password’ form).

    If the post doesn’t have a password then just carry on about your normal business.

    I wonder if it is possible to turn this into a plugin … ideas ?

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Removing posts which are password protected from main ‘blog’’ is closed to new replies.