WordPress Plugin: Logout Password Protected Posts

Latest version: 0.2 – Released November 3rd, 2012

Description

There is no built-in way for your visitors to "log out" of password protected posts once they've entered the password. Even logged in users cannot log out of password protected posts by logging out of their account. This plugin solves that problem by providing a link for your visitors to log out of password protected posts.

After installing the plugin, add <?php do_action('posts_logout_link'); ?> somewhere in your theme to display a link for logging out of password protected posts.

Installation

You can install this plugin directly from your WordPress dashboard:

  1. Go to the Plugins menu and click Add New.
  2. Search for Logout Password Protected Posts.
  3. Click Install Now next to the Logout Password Protected Posts plugin.
  4. Activate the plugin.
  5. Add <?php do_action('posts_logout_link'); ?> somewhere in your theme.

Those people who are logged in to password protected posts will now see a link to log out.

For manual installation, see the guide to Manually Installing Plugins.

FAQ

I can't see a link to log out. What's up?

Have you added the template tag somewhere in your theme? You need to add <?php do_action('posts_logout_link'); ?> somewhere in your theme for the link to show up.

I've added the template tag to my theme but I can't see the log out link. What's up?

Ensure that you have entered a password for a password protected post. The link will not show up if you're not logged into a password protected post.

Can I change the default text in the link?

Sure. Add a second parameter to the template tag with the text you'd like instead. For example: <?php do_action('posts_logout_link','Log out!'); ?>

For those who want even more control, you can also add a third paramter which will be used as the class name on the link element.

Download

Version 0.2 ZIP file from downloads.wordpress.org

Any comments, questions, queries, suggestions, complaints, etc, please leave a comment!

36 thoughts on “WordPress Plugin: Logout Password Protected Posts

  1. Sorry to ask such a noob question but what do you mean by “Add somewhere in your theme.”?

    This is a feature I could REALLY use but can’t figure out how to implement it.

    I installed the plugin and see it in my plugin directory. I then tried pasting that code into the password protected page in wordpress but (as you might have guessed) didn’t work.

    I am comfortable editing the theme filed but do I put into sidebar.php or into a .css file?

    Thanks for your time and for this great plugin!

  2. Gabriel: Where would you like the log out link to show up? I find that the best place is near the WordPress log out link which is in the sidebar on most themes.

    Try adding the code somewhere in sidebar.php. If your sidebar uses widgets it might not show up, so if not, try adding it to footer.php.

    Remember you have to be “logged in” to a password protected post in order for the link to even show up, so make sure you’ve entered a password to a post when you check for the link. Once you’ve got the link to show up, you can then experiment with its placement.

    I know this isn’t the simplest of solutions, and when I have the time I’ll be adding an automatic insertion option to the plugin to make it easier in the future.

    John.

  3. Thank you, putting it in the footer.php worked perfectly.
    Thanks again for this great plugin and I look forward to future releases.

  4. John,
    I tried adding the code in both the sidebar.php and footer.php and it just shows the raw code. I have the newest version of WordPress, 2.8.4, so I’m not sure if this matters.

    Thanks,
    Sandra

  5. Hi, your plugin works great. I just miss a function for entering an wrong passwort. If you enter a wrong password now, the “Protected Article”-Message does not change, but the Logout-Button appears anyway. This might be a little confusing for the visitor. A message like “wrong password, please try again” would be better.

  6. Carsten: Nice idea. Something notifying the visitor of an incorrect password should definitely be in WordPress as standard. I might see about adding it to this plugin if I get the time, but don’t hold your breath! :)

  7. I wanted to thank John for helping me out after I had posted a message stating that I was having problems installing the plugin. John responded quickly and I was able to get the plugin working….plus John provided some helpful tips regarding other plugins that may be useful on my website. And yes, the plugin works great!

    Thanks John,
    Sandra

  8. This works perfectly! I think this is the only plugin out there that properly addresses this important issue. Thanks!

  9. Hi there,

    Thanks for writing this plugin! I just wanted to let you know that I was also having a problem with the link showing up even if the password was incorrect. I solved it by having it check the cookie’s value against the post password rather than just checking if it’s set. It seems to be great now – thanks for a great start to a plugin.

  10. Helen: Thanks for the comment! I seem to recall there was a reason I didn’t make the plugin check the cookie against the password, but I can’t remember why. I’ll see about updating the plugin soon to address this issue.

  11. This is a great plugin, and something I was looking for. One possible addition would be to be able to change the text for the logout, without having to find it in the code. Simple admin option for this would be great.

    Another possible addition would be once logged out, redirect to a certain page / homepage so you can say where you want to be redirected.

    But great plugin.

  12. John,

    Thanks for the plugin. This solution does allow the use of PWP page and not have it/them going around cocked all the time. “.)

    I’m curious though, as to why you didn’t code it so that once either:

    1: the person – moves to or opens – another page in the site
    2: the page is closed
    3: the blog is closed
    4: the browser is closed

    the PWP page reverts to a LOGIN required status. IE, auto-logout.

    Is there a reason for WHY this was not done?

    Or is there something I could add to the PHP code to cause an auto-logout?

    Thanks again. ‘Tis far better than no logout at all!

  13. Hi Les,

    When you enter a password for a protected post, a cookie is set in your browser (just like when you log into the WordPress admin). The expiry of this cookie is determined by WordPress, not this plugin. I believe it’s expiry is set to 48 hours but I haven’t checked.

    It’s not possible to expire a cookie when a page/tab is closed or when you leave the blog. It is however possible to set the cookie to expire when the browser is closed, but this is determined by WordPress currently.

    I could add an option to this plugin for that purpose, but to be honest it’s unlikely to happen unless I find the need arises.

    John

  14. Great plugin, thanks!

    Is there a way we can get informed when the update of the plugin takes place? I think it only misses the function, of not appearing when a wrong password is entered.

    Remco!

  15. I’ve installed the plugin and I’ve noticed the logout link does not show up on all of the pages and there doesn’t seem to be any rhyme or reason to which pages it does show up on.

  16. How would I change the css to make the text appear as a button and be able to alter the position (right)?

    Thank for the great plug in ;)

  17. Cody:

    The call to <?php do_action('posts_logout_link'); ?> accepts two optional parameters. The first is the text to display as the link and the second is the class name to apply to the link. If you specify a class name in the second parameter you’ll then be able to style it with CSS.

    For example:
    <?php do_action('posts_logout_link','','logout_button'); ?>

    I can’t help you with your CSS I’m afraid as it depends on your theme, what you want the button to look like, etc.

    John

  18. Thank you John,

    This is what I needed. I have the css code already.

    I have to say, this plug in is great. Some of us don’t need all the bells and whistles, not to mention site slowing code of the other log in scripts.

  19. This was working, but now the logout link isn’t showing. Could the latest WP update have knocked it out?

  20. Whoops – figured it out. It’s back to working fine now. Another admin had changed the page from “password protected” to “private” — and that’s why it wasn’t showing up. THanks for this great plugin!!

  21. I am still new at WP and webpage design, but I find this plugin to be what I was hoping for. One question: is there a way to change the size of the font?

    Thank you!

  22. jdowning: The size of the font is controlled by your website’s style sheet. Use this in your template:

    <?php do_action('posts_logout_link','my_logout_link'); ?>

    then in your style sheet, style the link using:

    .my_logout_link {
      font-size: 10px;
    }

    John

  23. Thank you very much. I was not able to affect a change in the size, but I do appreciate your help!

  24. Excellent plug-in, only that I have the same issue comment Carsten (August 17th, 2009 at 3:53 pm) and that this issue will create confusion to the visitor, and that this matter suggests that if you entered the correct password.

    Anything new with this issue.

    Thanks in advance.

    • Hi Pablo,

      This issue was brought up again recently on the WordPress forums. Unfortunately it’s not possible (and also beyond the scope of this plugin) to determine whether the password is correct or not due to the simplistic nature of password protected posts in WordPress. Take a look at the question here and my response.

      John

  25. Could you advise how to reverse the post Logout? I wish to have a link the user can login using. Is this possible? I want to be able to email someone the link so they can login. It appears when you set the same password for multiple posts it requires just one login. I woul dlike to be able have a url like domain.com/login?password=1234.

    Is this possible or impossible?

  26. Jesse: That would be fairly easy to accomplish, but I don’t know of any plugins that do it. I’m sure a quick search on the plugins directory would bring something up.

  27. This plugin was last updated on 16th August 2011 and works well up to version 3.2 of WordPress. It’s not been tested with 3.3 but more than likely works.

    The plugin is no longer maintained. If anyone wishes to take over the plugin, feel free to email me.

Comments are closed.