WordPress protected posts giving a ‘Page not found’ and ‘wp-pass.php’ url

I’m trying to style password protected posts in WordPress using the following code in my functions.php. It’s giving me a ‘Page not found’ and redirects to a ‘wp-pass.php’ url. Any ideas on how to get round it would be much appreciated.

<?php 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" action="' . get_option('siteurl') . '/wp-pass.php" method="post">
    ' . __( "" ) . '
    <label for="' . $label . '">' . __( "Password Protected" ) . ' </label><input name="post_password" id="' . $label . '" type="password" size="20" /><input type="submit" name="Submit" value="' . esc_attr__( "Submit" ) . '" />
    </form>
    ';
    return $o;
}
?>

Related posts

Leave a Reply

2 comments

  1. Correct way to customize password protected page is

    <?php
        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">
            ' . __( "To view this protected post, enter the password below:" ) . '
            <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' );
        ?>
    

    Source: http://codex.wordpress.org/Using_Password_Protection#Customize_the_Protected_Text

  2. You have written wrong url in action of the form which is get_option('siteurl') . '/wp-pass.php. So you are redirected to wp-pass.php after submitting the password. So your code should be:

    function custom_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">
        ' . __( "To view this protected post, enter the password below:" ) . '
        <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', 'custom_password_form' );