So, what’s your question? Are you asking how you should modify the code you provided in order to have it display an error?
Hello Curtiss,
Yes, like: “you enter the wrong password try again”
Something simple like this…
Thanks!
Try something like:
<?php
function fb_the_password_form() {
global $post;
$label = 'pwbox-'.(empty($post->ID) ? rand() : $post->ID);
$output = '<form action="' . get_option('siteurl') . '/wp-pass.php" method="post">';
if( isset( $_REQUEST['post_password'] ) ) {
$output .= '<p>' . __("The password you entered was incorrect. Please try again:") . '</p>';
} else {
$output .= '<p>' . __("My post is password protected. Please ask me for a password:") . '</p>';
}
$output .= '<p><label for="' . $label . '">' . __("Password") . ' <input name="post_password" id="' . $label . '" type="password" size="20" /></label> <input type="submit" name="Submit" value="' . esc_attr__("Submit") . '" /></p>
</form>';
return $output;
}
add_filter('the_password_form', 'fb_the_password_form');
?>
That code should check to see if the form was already submitted (by checking to see if the value post_password form field was sent already) and output different intro text.
Thanks Curtis,
But for a reason I don’t know it doesn’t display the first output message.
Do we have a problem with the wp-pass.php you think ?
Thanks again.
I forgot that WordPress uses an intermediate page in between submitting the form and returning to the protected post/page.
I think you’ll need to use the referer instead of trying to check the submitted information.
You might try something like:
<?php
function fb_the_password_form() {
global $post;
$label = 'pwbox-'.(empty($post->ID) ? rand() : $post->ID);
$output = '<form action="' . get_option('siteurl') . '/wp-pass.php" method="post">';
$prepg = wp_get_referer();
if( false === $prepg || !stristr( $prepg, 'wp-pass.php' ) ) {
$output .= '<p>' . __("My post is password protected. Please ask me for a password:") . '</p>';
} else {
$output .= '<p>' . __("The password you entered was incorrect. Please try again:") . '</p>';
}
$output .= '<p><label for="' . $label . '">' . __("Password") . ' <input name="post_password" id="' . $label . '" type="password" size="20" /></label> <input type="submit" name="Submit" value="' . esc_attr__("Submit") . '" /></p>
</form>';
return $output;
}
add_filter('the_password_form', 'fb_the_password_form');
?>
Hello Curtis,
No such a luck, doesn’t work….
I don’t even get it why wordpress make this complicated…