I had a few pages on my site that were password protected using WordPress’ built-in password feature. Recently it all just stopped working and it took me a while to sort it out.

password-screenshot

Entering a password in the Quick Edit view

The WordPress feature is so easy to use – just type in what you want to be your password and save the changes. WordPress takes care of the rest, so when a user visits that page on your site they are presented with a nice little form saying that the post is password-protected and makes it easy for your visitor to enter the password and redirects to the page if they enter it correctly.

When this stopped working I did a bunch of browsing around – finding suggestions ranging from resaving permalinks, to repairing the database, to disabling plugins, to reinstalling wordpress. In my situation though, it was a problem with my theme and a recent update of WordPress.

Getting Personal

Maybe I’m too picky, but I didn’t like the way the form looked and more importantly, I wanted to change the message slightly. So I created a simple filter in my functions.php file for my theme that made a few changes to how it looked. But, in a recent upgrade, WordPress changed the file that handles the password process – the one the action in my form was using – so my version of the password form stopped working.

Old: /wp-pass.php

New: /wp-login.php?action=postpass

So – fixing it was as easy as updating the action attribute in my theme’s version of the password form.

In case you’re curious or want to pretty up the way your password form looks in your theme, here’s the filter I’m using currently. Note the now corrected form action attribute! This works in WP 3.5+…

// style the password entry form
function custom_password_form() {
    global $post;
    $label = 'pwbox-'.( empty( $post->ID ) ? rand() : $post->ID );
    $o = '<form action="' . get_option('siteurl') . '/wp-login.php?action=postpass" method="post">
    ' . __( "<p>This section of the website is password protected. Please enter your password to continue.</p>" ) . '
    <p><label for="' . $label . '">' . __( "Password:" ) . ' </label><input name="post_password" id="' . $label . '" type="password" size="20" /></p><p><input type="submit" name="Submit" value="' . esc_attr__( "Submit" ) . '" /></p>
    </form>
    ';
    return $o;
}
add_filter( 'the_password_form', 'custom_password_form' );