Skip to content

Instantly share code, notes, and snippets.

@kjbrum
Last active May 21, 2016 02:17
Show Gist options
  • Save kjbrum/a41477bbcab7c899eb4f to your computer and use it in GitHub Desktop.
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.
<?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