WordPress is great. And a lot of people use the free blogging service they supply for writing those cool updates and sarcastic posts bashing the latest Michael Bay film. I, however, run my own version of the blog and use it a little differently than most people.
In fact, a majority of the post I make never make it to the light of day, as most of them are private. The reason I do this is I use WordPress to save a bunch of different things, journal entries, writing prompts, and photos on my site. I have a bunch of pages set up that feedback all the posts matching a certain category (for instance, the “Writing” tab in my header is a collection of all my posts with the writing category. All of that is rather straight forward, but what you don’t know, is that when I log in I see a bunch of extra tabs for private pages up top.
I don’t like the security risk of “password” protected pages, because that lets the public know that something exists. Something I don’t want them to see. So I publish private pages and changed some word press code to display those to logged in users. I should note that I’m the only user that logs into this site, so I can see everything once logged in, there is no need for levels, such as user, contributor, and administrator, but the following code is malleable to that as well.
in $WORDPRESS/wp-include/post.php file
There is a line in the “get_pages” function that looks like this:
$query = "SELECT * FROM $wpdb->posts $join WHERE (post_type = 'page' AND post_status = 'publish' ) $where ";
Just below that line, add in the following code:
if ( is_user_logged_in() ) { $query = "SELECT * FROM $wpdb->posts $join WHERE (post_type = 'page' AND (post_status = 'publish' OR post_status='private') ) $where "; }
UPDATED for wordpress 3.0:
There is a line in the “get_pages” function that looks like this:
$where_post_type = $wpdb->prepare( "post_type = '%s' AND post_status = '%s'", $post_type, $post_status );
Just below that line, add in the following code:
if ( is_user_logged_in() ) { $where_post_type = $wpdb->prepare( "post_type = '%s' AND (post_status = '%s' OR post_status = 'private' )", $post_type, $post_status ); }
This now checks to see if a user is logged in, and if so, will output private pages to the caller of this function (usually wp_list_pages()).
That’s all there is to it. Be warned, it might will get overwritten during WordPress updates, as I have not gone to version 3.0 yet, and this seems like a feature they’ll add at some point.