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.

What is the easiest method to make all my articles accessible only to registered users?

My homepage contains titles and excerpts but I want to allow access to the full content only to registered users.

I remember there was an admin setting for that but I cannot find it.

Maybe Im wrong. Any ideas?

Thanks.

share|improve this question
add comment

2 Answers

up vote 2 down vote accepted

You could hook into template_redirect, check if it is a singular page (post, page, custom post type) and force a log in:

add_action( 'template_redirect', 'login_to_see_content' );

function login_to_see_content()
{
    if ( is_singular() && ! is_user_logged_in() )
        auth_redirect(); // does nothing for logged in users
}

As suggested by @s_ha_dum in the comments, an additional ! is_user_logged_in() might be necessary. In theory, it shouldn’t (and it isn’t in my setup).

share|improve this answer
    
Thanks. Where do I add this? functions.php ? –  p.a. May 24 '13 at 7:14
    
@p.a. Make a little plugin, so you can turn it off easily. –  toscho May 24 '13 at 7:15
    
Thanks, my needs are minimal so I ll just drop this into functions.php. I just check for a "public" category and redirect for all other categories to the login box. –  p.a. May 24 '13 at 10:02
    
No it does not work; it always redirects me to login. Even if I am connected as admin! In addition, when redirected, login does not work! I supply valid credentials and return to login screen. –  p.a. May 24 '13 at 15:43
    
@p.a. I tested my solution: It works. Do you have by any chance another plugin enabled that breaks this functionality? –  toscho May 24 '13 at 18:09
show 9 more comments

I recommend a plugin like User Access Manager for that purpose. It gives more function and control than using native function such as making posts Private.

share|improve this answer
add comment

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.