Skip to content

Instantly share code, notes, and snippets.

@cfxd
Last active August 29, 2015 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cfxd/2b2b8be1d4d57f7f59b6 to your computer and use it in GitHub Desktop.
Save cfxd/2b2b8be1d4d57f7f59b6 to your computer and use it in GitHub Desktop.
Roots theme password protected post form function. Use the Bootstrap free markup with the Bootstrap LESS or use the Bootstrap markup version as standalone.
<?php
global $post;
$label = 'pwbox-'.(empty($post->ID) ? rand() : $post->ID);
?>
<form action="<?php echo esc_url(site_url('wp-login.php?action=postpass', 'login_post')); ?>" class="post-password-form form-inline" method="post">
<p><?php _e('This content is password protected. To view it please enter your password below:', 'roots'); ?></p>
<p><label for="<?php echo $label; ?>" class="sr-only"><?php _e('Password:', 'roots'); ?></label></p>
<div class="input-group">
<input name="post_password" id="<?php echo $label; ?>" type="password" placeholder="<?php _e('Enter password', 'roots'); ?>" class="form-control" />
<span class="input-group-btn">
<button type="submit" class="post-password-submit btn btn-default"><?php _e('Submit', 'roots'); ?></button>
</span>
</div>
</form>
<?php
global $post;
$label = 'pwbox-'.(empty($post->ID) ? rand() : $post->ID);
?>
<form action="<?php echo esc_url(site_url('wp-login.php?action=postpass', 'login_post')); ?>" class="post-password-form" method="post">
<p><?php _e('This content is password protected. To view it please enter your password below:', 'roots'); ?></p>
<p><label for="<?php echo $label; ?>"><?php _e('Password:', 'roots'); ?></label></p>
<div>
<input name="post_password" id="<?php echo $label; ?>" type="password" placeholder="<?php _e('Enter password', 'roots'); ?>" />
<span>
<button type="submit" class="post-password-submit"><?php _e('Submit', 'roots'); ?></button>
</span>
</div>
</form>
function roots_get_the_password_form($output) {
$output = '';
locate_template('/templates/passwordform.php', true, false);
return $output;
}
add_filter('the_password_form', 'roots_get_the_password_form');
article {
.post-password-form {
> p > label {
&:extend(.sr-only);
}
> div {
&:extend(.input-group all);
@media (min-width: @screen-sm-min) {
display: inline-table;
vertical-align: middle;
}
> span {
&:extend(.input-group-btn all);
@media (min-width: @screen-sm-min) {
width: auto;
}
}
}
input[type=password] {
&:extend(.form-control all, .input-group .form-control all);
@media (min-width: @screen-sm-min) {
width: 100%;
}
}
.post-password-submit {
&:extend(.btn all, .btn-default all, .input-group-btn:last-child > .btn, .input-group-btn > .btn all);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment