WordPress.org

Forums

Upgraded from 3.3.3 to 3.4.2 and password protection broken (8 posts)

  1. wyclef
    Member
    Posted 1 year ago #

    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.

  2. Tara
    Member
    Posted 1 year ago #

    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

  3. wyclef
    Member
    Posted 1 year ago #

    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?

  4. wyclef
    Member
    Posted 1 year ago #

    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.

  5. Tara
    Member
    Posted 1 year ago #

    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?

  6. wyclef
    Member
    Posted 1 year ago #

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

  7. wyclef
    Member
    Posted 1 year ago #

    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>
    <? } ?>
  8. wyclef
    Member
    Posted 1 year ago #

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

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.