Support » Fixing WordPress » Child pages of password protected page

  • I have would like to have a password protected “section” that is accessible through 1 password protected page.

    My question is will the child pages of the parent page that is password protected be secure without setting passwords on each child page? I set them all to be password protected with the same password for now just to be sure, but I was a little worried users would have to enter the password for every child page.

    It is a “members” area of our church website where we want to keep our church directory along with schedules like Nursery, mowing, and cleaning. (we are a small church and take turns with the chores)
    Thank you in advance!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Hi Shelly,

    I suggest trying the Members plugin http://wordpress.org/plugins/members/

    It will allow you to choose which content is for members only. Each member can login with there own account.

    You can use this snippet in your templates to see if pages have a protected parent:

    /* In your theme's functions.php */
    function has_protected_parents ( $post ) {
    	foreach ( get_post_ancestors($post) as $parent ) {
    		if ( post_password_required( $parent ) ) {
    			return true;
    		}
    	}
    	return false;
    }
    
    /* Used in the template (i.e. page.php), inside the loop! (After the_post() has been called) */
    if ( has_protected_parents( $post ) ) {
    	// Tell them to go back!
    } else {
    	// They've already logged in to a parent, or the page doesn't have protected ancestor pages.
    }

    I only know this to work (tested) in the latest release of WordPress, 3.7.1

    BangBoomCrash

    (@bangboomcrash)

    Thanks AugustWinfield – that worked perfectly for a project I’m working on. Thanks again!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Child pages of password protected page’ is closed to new replies.