Skip to content

Instantly share code, notes, and snippets.

@davidsword
Last active February 3, 2018 03:01
Show Gist options
  • Save davidsword/fd1f805789ba84a9366d42b382dfb300 to your computer and use it in GitHub Desktop.
Save davidsword/fd1f805789ba84a9366d42b382dfb300 to your computer and use it in GitHub Desktop.
<?
// in functions.php
add_filter( 'the_password_form', 'ds_password_form' );
function ds_password_form() {
global $post;
$label = 'pwbox-'.( empty( $post->ID ) ? rand() : $post->ID );
$link = esc_url( site_url( 'wp-login.php?action=postpass', 'login_post' ) );
return "
<form action='{$link}' method='post' id='passwordForm'>
<input name='post_password' id='{$label}' type='password' size='20' maxlength='20' placeholder='Password' />
<input type='submit' name='Submit' value='Unlock' />
</form>\n";
}
// above your main loop
if ( post_password_required() ) : ?>
<a href='#' data-featherlight='#passwordForm'>Unlock All Posts</a>
<div id='passwordInput' style='display:none'>
<?= get_the_password_form(); ?>
</div>
<? endif;
// in your loop
//...
if (post_password_required()) {
echo "This is locked.. <a href='#' data-featherlight='#passwordForm'>unlock it</a>";
} else {
// unlocked post
}
//...
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment