Last active
May 21, 2016 02:17
-
-
Save kjbrum/a41477bbcab7c899eb4f to your computer and use it in GitHub Desktop.
Password protect child pages so you don't have to create a password for each page.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Create a custom length content string. | |
* | |
* @param integer post ID of the parent page | |
* @return void | |
*/ | |
function wp_password_protect_children( $post ){ | |
foreach( get_post_ancestors( $post ) as $parent ) { | |
if( post_password_required( $parent ) ) { | |
$location = get_permalink( $parent ); | |
wp_redirect( $location ); | |
exit; | |
} | |
} | |
} | |
add_action( 'template_redirect', 'password_protect_children' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment