Skip to content

Instantly share code, notes, and snippets.

@caratage
Created April 21, 2013 10:33
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 caratage/5429203 to your computer and use it in GitHub Desktop.
Save caratage/5429203 to your computer and use it in GitHub Desktop.
Protected Posts - Custom Form, Message, Title
/**********************************************
* Custom Password Form
**********************************************/
add_filter( 'the_password_form', 'custom_password_form' );
function custom_password_form() {
global $post;
$label = 'pwbox-'.( empty( $post->ID ) ? rand() : $post->ID );
$o = '<form class="protected-post-form form-inline" action="' . get_option('siteurl') . '/wp-login.php?action=postpass" method="post">
<input class="input-medium" placeholder="Password" name="post_password" id="' . $label . '" type="password" /> <button type="submit" name="Submit" class="btn btn-primary">Submit</button>
</form><p>This page is password protected. <a href="mailto:info@bgcci.com">Contact us</a> in case you have lost your password or want to register for access. Thank you</p>
';
return $o;
}
/**
* Add a message to the password form.
*
* @wp-hook the_password_form
* @param string $form
* @return string
*/
add_filter( 'the_password_form', 'wpse_71284_custom_post_password_msg' );
function wpse_71284_custom_post_password_msg( $form )
{
// No cookie, the user has not sent anything until now.
if ( ! isset ( $_COOKIE[ 'wp-postpass_' . COOKIEHASH ] ) )
return $form;
// We have a cookie, but it doesn’t match the password.
$msg = '<div class="alert alert-error"><button type="button" class="close" data-dismiss="alert">&times;</button><p>The password you submitted was incorrect.</p></div>';
return $msg . $form;
}
/**
* Remove Protected: from Title
*/
add_filter('protected_title_format', 'blank');
function blank($title) {
return '%s';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment