WordPress.org

Support

Support » How-To and Troubleshooting » Upgraded from 3.3.3 to 3.4.2 and password protection broken

Upgraded from 3.3.3 to 3.4.2 and password protection broken

  • Hello,

    I have a password protected page that was using /wp-pass.php in 3.3.3 and I’ve recently upgraded to 3.4.2 and it appears this is no longer working. From what I’ve found /wp-login.php?action=postpass is what I should replace /wp-pass.php with but am having problems as the area that controlled a login/logout button also is not working.

    This is the code I was using in functions for the password form

    // Customize Password Form in Functions
    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">
    	<input name="post_password" id="' . $label . '" type="password">
    	<input type="submit" name="Submit" class="pass" value="' . esc_attr__( "Submit" ) . '">
    	</form>
    	';
    	return $o;
    }

    and this is the code in the template I was using to control the login/logout button:

    // Code to control logout buttons
    <?php wp_nav_menu('menu=about-us&menu_class=child-navs&container=&container_class=&menu_id='); ?>
                        <?
                        $sql = "SELECT post_password FROM wp_posts WHERE ID = '173'";
                        $result = mysql_query($sql) or die('Content was not loaded. Please refresh your page.');
                        while($post = mysql_fetch_array($result)) {$pagePass = $post['post_password'];}
                        ?>
                        <? if (isset( $_COOKIE['wp-postpass_' . COOKIEHASH] ) && $pagePass == $_COOKIE['wp-postpass_' . COOKIEHASH]) { ?>
                          <a href="<? echo site_url('/members/logout'); ?>" class="open">Member Logout</a>
                        <? } else { ?>
                          <a href="<? echo site_url('/members/'); ?>" class="close">Member Area</a>
                        <? } ?>

    If anyone has any thoughts as to how I could fix this would be appreciated. Thanks.

Viewing 7 replies - 1 through 7 (of 7 total)
  • Moderator t-p

    @t-p

    Volunteer Moderator

    Password protect post/page:

    This is built into WordPress. Just put in a password when creating the post or page. Look on the upper right hand corned on Edit Page or Edit Post > visibility > pick Password Protect.

    This does not require any extra code snippet such as the one your are using in your functios.

    For more info, review this codex: http://codex.wordpress.org/Using_Password_Protection

    ah, thanks for the link. it looks like the top bit of code is basically fine once I swap out the wp-pass.php. I need to have the extra code snippet because I’m customizing it some. As far as the bottom bit of code is wp-postpass_ no longer valid in 3.4.2?

    It looks like someone in another post that’s been closed for replies touched on what I’m trying to work out but I don’t fully understand.

    They said…

    anyone else who stumbled upon this and has any pre-3.4 conditional code comparing $post_object->post_password with $_COOKIE[‘wp-postpass_’ . COOKIEHASH]: you must now use wp_check_password() instead, as the post password is (wisely!) no longer saved in plaintext in the user’s browser.

    Moderator t-p

    @t-p

    Volunteer Moderator

    As far as the bottom bit of code is wp-postpass_ no longer valid in 3.4.2?

    Sorry, I have no idea.

    Also, why not update to the latst 3.8.1 instead of 3.4.2?

    it’s an older build and there is limited time. far too many things would break at once. trying to ease into the upgrades.

    To simplify things it seems like the code I really need help with is the conditional I had set up to control the login/logout button. This no longer works.

    <? if (isset( $_COOKIE['wp-postpass_' . COOKIEHASH] ) && $pagePass == $_COOKIE['wp-postpass_' . COOKIEHASH]) { ?>
    <a href="<? echo site_url('/members/logout'); ?>" class="open">Member Logout</a>
    <? } else { ?>
    <a href="<? echo site_url('/members/'); ?>" class="close">Member Area</a>
    <? } ?>

    is anyone familiar with the above code using wp-postpass?

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Upgraded from 3.3.3 to 3.4.2 and password protection broken’ is closed to new replies.
Skip to toolbar