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've searched for plugins but while some do halfway accomplish the task they are normally very complicated.

I'd like to add option to the visibility menu when creating a page (and post, but page is more urgent).

visibility menu wordpress

These options need to be: "Only visible to logged user" and "Only visible to guest (i.e. not logged in"

Does any one know of plugin or and point me in the right direction to write my own?

EDIT: A use case for this is; only show the registration and login pages to 'guests'. A logged-in user doesn't need to see these pages.

share|improve this question

2 Answers 2

The Subscribers Only Content plugin will accomplish this.

share|improve this answer
    
This seems to have the capability of hiding content from 'guests' but not 'from' logged-in users (see question edit for more info). –  rjstelling Sep 24 '10 at 7:20

I've actually done this before with a custom page template rather than with the visibility options ... because both logged in and not logged in users ended up going to the same page. Here's some pseudo-code (i.e. do not actually use the code, but it will give you an idea)

$logged_in = is_user_logged_in();

switch($logged_in) {
    case true:
        // Do stuff for logged in users
        break;
    case false:
    default:
        // Do stuff for not logged in users
        break;
}

Basically, you check to see if the user is logged in (using a combination of get_currentuserdata() and some checks on their ID). If the user is logged in, you display one block of content. If the user is not logged in, you display another block of content.

I definitely think having a visibility option would be a more elegant solution, but then you'd need two different pages for each kind of user. Would a logged in user see a 404 error page if they went to the wrong site? Or be directed elsewhere? With two separate pages, this is a situation you'll have to handle gracefully.

share|improve this answer

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.