Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

You have to control the order of execution. To do that, use the third parameter for add_filter(), the priority. A higher priority equals to later execution.

add_filter( 'the_password_form', 'my_password_form', 9 );
add_filter( 'the_password_form', 'wpse_71284_custom_post_password_msg', 10 );
share|improve this answer
    
thank you @toscho. –  gurung Oct 26 '13 at 14:43
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.