WordPress.org

Ready to get started?Download WordPress

Forums

How to password protect a post? Not just the content area. (11 posts)

  1. mattmikulla
    Member
    Posted 2 years ago #

    I would like to password protect a post. Specifically a custom post type WooCommerce product page.

    Unfortunately WordPress's lame pasword protect feature only protects the_content and not the post image or anything else.

    I don't care if the whole page disappears and just a password login is displayed or the header and footer are still present. I want more than the_content hidden.

    A plugin would work fine or a functions.php edit.

  2. esmi
    Theme Diva & Forum Moderator
    Posted 2 years ago #

    WordPress' "lame password protect feature" works fine in Twenty Eleven, so try asking on http://www.woothemes.com/support/

  3. mattmikulla
    Member
    Posted 2 years ago #

    esmi. WordPress's password protection is lame. Lame by definiton: weak; inadequate; unsatisfactory; clumsy:

    It has nothing to do with WooCommerce and Twenty Eleven doesn't work better than any other theme.

    WordPress only password protects whatever get's output in php the_content. It doesn't hide the post title, author or anything else.

    Think about how many posts and pages use custom fields, featured images and more. Yep, all that is visible.

  4. esmi
    Theme Diva & Forum Moderator
    Posted 2 years ago #

    It doesn't hide the post title, author or anything else.

    That's covered by the theme.

  5. mattmikulla
    Member
    Posted 2 years ago #

    I tested with Twenty Eleven to no avail. It still hides only the content. Am I missing something?

  6. esmi
    Theme Diva & Forum Moderator
    Posted 2 years ago #

    Twenty Eleven does not hide the post title, the author etc because that's how Twenty Eleven is designed to work. You can stop the display of a post at ant point using the post_password_required() function as a display conditional. Eg:

    <?php if( ! post_password_required() ) :
    [ normal display ]
    else :
    [ default message/form on password protected post ]
    endif;?>

    Like every other tool, it's how and when you use it that counts ;-)

  7. mattmikulla
    Member
    Posted 2 years ago #

    I found a code snippet from a few years ago here that is very similar to your snippet. The difference is it uses an if statement.

    <?php
        if ( !post_password_required() ) {
                echo 'protected stuff';
        }
    ?>

    Warning: I am not a developer but I hack my way through things.

    So basically the concept would be to wrap whatever I want to hide within the snippet correct?

  8. esmi
    Theme Diva & Forum Moderator
    Posted 2 years ago #

    Sorry! My bad! I managed to miss out the if statement in my version (now corrected). But the premise is exactly the same in both versions. Your theme "decides" what content is displayed to a passing visitor from a password protected Post or Page.

  9. mattmikulla
    Member
    Posted 2 years ago #

    Getting there. I tested the concept and it works. However, I am unsure about how to implement it into my theme without relying on echo.

    Take single.php as an example. Lets assume I want to password protect everything between the header and footer.

    Again, my PHP skills are at the 3rd grade level.

  10. esmi
    Theme Diva & Forum Moderator
    Posted 2 years ago #

    Using your example above, you start the if conditional immediately after the call to header.php and end if immediately before the call to footer.php.

    <?php get_header();
        if ( !post_password_required() ) {
                [the rest of the page & normal Loop goes here]
        }
    get_footer();
    ?>
  11. Moritz
    Member
    Posted 1 year ago #

    You can stop the display of a post at ant point using the post_password_required()

    hi, I have the same problem: basically the woocommerce plugin transforms the shop-page into custom post type, so the password protection in the adminarea doesnt work. So i would like to password protect a "custom post type" in wordpress. As far as I understood it is outside of the_content. ok, the code is already shown above, but where would I have to implement it? Is this depending on my themefiles?
    Any help appreciated. thx.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.