WordPress.org

Support

Support » How-To and Troubleshooting » Add a "wrong password" message to protected posts?

Add a "wrong password" message to protected posts?

  • Hi!

    I’m trying to get wordpress to show a “wrong password” message when a user tries to access a protected post (front-end) and enters an incorrect password. Currently it just shows the exact same form again.

    I know the form can be customised with the ‘the_password_form’ filter, but can’t see any variables passed back in the HTTP request that would allow me to conditionaly display some “wrong password” text from here.

    Anyone have any idea how to go about doing this?
    Bright ideas much appreciated!

    Cheers

Viewing 3 replies - 1 through 3 (of 3 total)
  • bjdr
    Participant

    @bjdr

    ttr738 did you manage to figure this out?
    Or maybe someone else have an idea?

    Nope. Still don’t have a clue about it I’m afraid! You?

    Not the cleanest thing ever but here is a solution:

    if (!function_exists('theme_the_password_form')) {
    	function theme_the_password_form( $form) {
    		if (isset($_COOKIE['wp-postpass_' . COOKIEHASH]) && get_permalink() == wp_get_referer()) {
    			$form = '<p class="error">Invalid Password. Please try again.</p>' . $form;
    		}
    		return $form;
    	}
    }
    add_filter( 'the_password_form', 'theme_the_password_form');

    hopefully that helps

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Add a "wrong password" message to protected posts?’ is closed to new replies.