Password Protect Children Pages
By Glenn Ansley | May 23rd, 2009 | Published in Projects, WordPress Plugins | 11 Comments
This plugin does one thing. If a page that is password protected has children pages, all children pages will be protected with the same password. If the correct password is entered on the parent page or any of its children pages, all related pages will be viewable to the user.
The following logic is invoked whenever the_content or the_excerpt is called from your theme.
- Is this a page?
- Does this page have an ancestor page
- If it does, does the ancestor page require password protection?
- If it does, treat this page the same way you would treat the top level ancestor page.
Version 0.2 uses the $post->ancestors property and allows protection of grandchildren pages as well
June 15th, 2009 at 4:28 am (#)
Hi, I installed your plugin (WP 2.8) but it doesn’t work. Is there an update for the new version of wordpress?
I would be glad if you can help me, because your small plugin would be the perfect solution for my site
Thanks a lot!
Jens
June 25th, 2009 at 7:36 pm (#)
how do I emplement this. sorry for a stupid question. it is just what i need. thanks again!
August 26th, 2009 at 8:20 am (#)
I’ve implemented a “Members Only Area” on my website where the top page is password-protected, and using this plugin all sub-pages are now automatically protected too.
Works exactly as I hoped it would, thanks!
October 18th, 2009 at 8:17 pm (#)
Hi there,
Thanks for the plugin – sadly it only works with child pages not grandchild pages.
Is there someway this could be added using get_post_ancestors rather than post->parent?
Cheers,
Gareth.
October 22nd, 2009 at 8:38 pm (#)
I'd like to use this for my website under construction, but a) should I update to newest version of WordPress first? and b) what are some responses to common glitches?
October 22nd, 2009 at 9:01 pm (#)
I downloaded this into my website's admin and it doesn't even show up anywhere. What happened? Does it even show up? How can I use it if there's no control panel anywhere?
October 23rd, 2009 at 5:43 am (#)
What kind of interface do you need? I didn't build any options into it. If you password protect a page, its child gets password protected too. Pretty simple.
March 4th, 2010 at 3:10 pm (#)
In case anyone is interested in making this plugin protect ALL subpages (not just the immediate children), you can edit the plugin file as follows:
<span class='code' name='php' >
// This function prints the password form if the parent page is password protected. It is called whenever 'the_content' is invoked.
function ft_password_protect_children_page_contents( $org_content ){
if ( is_page() ){
global $post;
$ancestors = end($post->ancestors);
if ( !empty($ancestors) ){
if ( post_password_required( $ancestors ) ) {
$real_post = $post;
$post = $ancestors;
echo get_the_password_form();
$post = $real_post;
return;
}
}
}
return $org_content;
}
add_filter( 'the_content', 'ft_password_protect_children_page_contents' );
</span>
April 14th, 2010 at 10:14 am (#)
This is going to sound like the dumbest questions of all, but I'm looking for the way to password protect the PAGES in the first place! After I've figured out how to do that, your plugin will be perfect for what I need.
Anybody's got any idea how to password protect each page (and possibly their child pages) with a different password?
A million thanks !
marie
June 16th, 2010 at 7:34 am (#)
@marie This is found on the post edit screen in the top-right.
June 16th, 2010 at 11:33 am (#)
Thanks Trevor. I’ve integrated this with the code and credited you in readme.txt