I needed two functions on my wp-site. First I needed to change the text of password-protected-page so I picked up this code straight from this article on wordpress codex. and it works beautifully.
function my_password_form() {
global $post;
$label = 'pwbox-'.( empty( $post->ID ) ? rand() : $post->ID );
$o = '<form action="' . esc_url( site_url( 'wp-login.php?action=postpass', 'login_post' ) ) . '" method="post">
' . __( "<p>Please get in touch with us on ######## and get a password.</p>" ) . '
<label for="' . $label . '">' . __( "Password:" ) . ' </label><input name="post_password" id="' . $label . '" type="password" size="20" maxlength="20" /><input type="submit" name="Submit" value="' . esc_attr__( "Submit" ) . '" />
</form>
';
return $o;
}
add_filter( 'the_password_form', 'my_password_form' );
Second I needed to show an error message if someone puts a wrong password in the password-protected-page so I picked up another solution provided by @toscho from here at wpse and it works like charm too.
//ERROR MESSAGE FOR PASSWORD PROTECTED POSTS/PAGES
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 = '<p class="custom-password-message">WRONG PASSWORD.</p>';
return $msg . $form;
}
The issue is they do not work together for some reason. To be specific, the first code from codex works regardless of the second code commented out or not. But the second code block that pertains to error message does not work at all with the first one present. Needless to mention that both of these codes sit above one another in the functions.php. Just so you know I am using the latest wp-3.7 and testing this in live server. What am I missing, please enlighten me. thanks in advance.