Password Protect Children Pages
By Glenn Ansley | May 23rd, 2009 | Published in WordPress Plugins | 31 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
July 2nd, 2010 at 9:17 am (#)
Hi,
I’ve run into a problem with WordPress 3. I created a test page called “Test1″ and a child page called “Test2″. When I view “Test2″ it puts “PROTECTED” in the name of the page even though “Test1″ nor “Test2″ are marked as protected.
If i deactivate the plugin then “PROTECTED” goes away from the page title. Any thoughts?
scott.
July 2nd, 2010 at 9:22 am (#)
Another item I just noticed is that pages that I truely have protected show “PROTECTED: PROTECTED:” in the title. Looks like the protected is shown twice for protected pages.
July 4th, 2010 at 11:32 am (#)
I just deleted the entire part of the code that adds "protected." I guess that will work for now.
July 4th, 2010 at 3:06 pm (#)
Hi Glenn,
I love your plugin. It is just what I need for my site. I am having a little problem that is coming up though that I thought I would ask you about:
Since I’ve installed your plugin, whenever I go to _any_ child page on my site the menu changes to prefix _every_ file with “Protected,” even though none of those pages are password protected.
See here: http://lessonswithgreg.info/students/student-pages/madi/
Any idea what might be causing this?
July 4th, 2010 at 10:56 pm (#)
Ok. That got rid of the “protected”s but none of the children pages are password protected. I deleted then reloaded the original plugin but the children pages are still unprotected. Does this plugin not work with the latest WordPress build?
July 9th, 2010 at 11:38 am (#)
Thank you, thank you, thank you. It’s simplicity is perfect for our needs.
July 9th, 2010 at 3:29 pm (#)
Hi
The 0.2 version doesn’t seem to be compatible with WordPress 3.0 (danish). Alle subpages are treated as private pages and the word ‘beskyttet’ (danish for private) is added to all titles. The parent page is not protected.
August 8th, 2010 at 1:13 pm (#)
I'm running into an issue after installing this plugin on a site I'm working on. I'd installed this on a different server and had no problems, so I assume this is something about configuration on this new server. But if there's a way around it…
Here's the error I get now above the page headline on each page:
Warning: end() [function.end]: Passed variable is not an array or object in /home/content/k/n/s/knscoop/html/test/wp-content/plugins/ft-password-protect-children-pages/ft-password-protect-children-pages.php on line 63
And then just before the page content (or the password form):
Warning: end() [function.end]: Passed variable is not an array or object in /home/content/k/n/s/knscoop/html/test/wp-content/plugins/ft-password-protect-children-pages/ft-password-protect-children-pages.php on line 22
Any idea what could be happening? It's such a great solution for my site, I'd really hate to have to stop using it!
Thanks!
August 22nd, 2010 at 10:43 am (#)
How do you change the look of how it looks on the site? Right now I have a large "This page is password protected" and login button on the top of the page in large type, with the same thing smaller and more typical where it should be in the middle of the page. I'd like to remove it from the top of the page and control the look of the login area/button. How does one adjust the look of the plugin?
August 25th, 2010 at 4:02 pm (#)
Plugin works great on my computer, but one person is complaining that on his computer he needs to login to see the “unprotected pages” Any ideas ?
Great program
Andrew
August 26th, 2010 at 9:01 am (#)
We are having some issues, with some people stating that when they go to non protected areas they are prompted for a password. Thus we had to disable the plugin. Any thoughts would be appreciated.
Andrew
September 1st, 2010 at 8:27 am (#)
Ihave installed and used the plugin. It works fine, although, it puts the word “protected” on some header areas of pages that are not child pages. the word still shows up Even after I delete the orig pass protected pages. Any help would be appreciated.
September 1st, 2010 at 8:11 pm (#)
Hi!
I don't know if it's me but with something like that this plugin don't work :
Page 1 (no password)
-Page 2 (no password)
–Page 3 (password)
—Page 4 (no password)
—-Page 5 (no password)
With this configuration pages under page 3 didn't get password protection, so I modify your plugin to protect all page under a page with password and it with any location.
My code is here : http://pastebin.com/mfF4xPym
September 21st, 2010 at 1:06 pm (#)
Hi!
I like the functionality of this plugin–however, in practice it seems to tag all child pages with "Protected:" in the h1 head, regardless of whether the Parent page was protected or not…
-p
September 22nd, 2010 at 4:05 am (#)
0.3 was just released. It fixes all bugs mentioned above this comment.
== Changelog ==
= 0.3 =
* Fixed bug where children pages of non-protected parents had 'Protected: ' prepended to the title.
* In case where grandparent page is not protected but parent page was, child pages are now protected.
September 22nd, 2010 at 6:43 am (#)
I'm going to install 0.3 right now — thanks for your work on this.
I've got another question which may or may not be something I could configure your plugin to handle: I'd like to display the content of certain blog categories on protected pages. For example, on a protected page I'd have a brief introductory message and then excerpts of three blog posts in the protected category.
Obviously the content on the pages themselves is the only part that's password-protected at this point and not any blog posts I'm pulling in through the template. So right now the posts show up no matter yet while the page content itself remains protected.
Is it possible to set up blog posts to be children of protected pages so that they inherit the protection themselves? Or to set up the content rendered by the template to be treated part of the page content? Alternately, do you think I'm barking up the wrong tree and should find a different solution altogether?
Thanks again for the plugin.
September 22nd, 2010 at 8:26 am (#)
Hi Mike,
I just emailed you some code that may accomplish what you're looking to do.
September 22nd, 2010 at 5:33 pm (#)
Thanks for upgrading
September 26th, 2010 at 9:06 pm (#)
Yes, how do you implement this. You may want to add quick user directions…
thanks,
Joe
September 26th, 2010 at 9:08 pm (#)
Hi Joe,
You just need to password protect a page like normally in WordPress and then the children pages will be protected as well. When you’re editing a page, this can be done at the top-right by changing the visibility options.