Forums

Making Private Posts visible for Subscribers (3 posts)

  1. Tony Stark
    Member
    Posted 2 years ago #

    Hi All!

    As always, loving WP ;-) I have setup a series of private posts which I want to visible by subscribers. it seems that out of the box this is not possible? I searched around and found this following link: http://sltaylor.co.uk/blog/wordpress-subscribers/

    I have added the code it stated to my functions.php in my theme but it doesnt seem to have worked (unless I need to restart PHP/Apache).

    Anyone know a good way/process of doing what I want without an elaborate group/permissions plugin?!

    Thanks

    Tony

  2. nouveller
    Member
    Posted 2 years ago #

    Let's say you set up a category called 'private' first then you could use this on your single.php.

    The current_user_can('read') should detect that they're at least a subscriber and in_category('private') will detect the posts you want to protect in that category.

    <?php 
    
    	if(current_user_can('read') && in_category('private'){
    
    		//insert your loop
    
    	} else {
    
    	echo "You are not permitted to view this posts";
    
    	}
    
    ?>
  3. gregarose
    Member
    Posted 2 years ago #

    Tony,

    Don't know if you solved your issue but I think the reason your edits to function.php in your theme didn't work is because the blog post you mentioned used this code:

    $subRole = get_role( 'subscriber' );
    $subRole->add_cap( 'read_private_pages' );

    This will allow Subscribers to see private Pages but not private Posts. You also need to add

    $subRole->add_cap( 'read_private_posts' );

    in order for your Subscribers to see private Posts. At least this worked for me. But now I have a problem that my private posts, categories that only have private posts and private pages do not show up in the widgets in my sidebar even when I am logged in as Administrator or as Subscriber. This happens for the Administrator even without the changes to function.php. I can make a category show up in the sidebar widget if I add one public post to it but I can't make a private page show up at all. I don't know enough about WordPress to tell whether a fix for this requires just an edit to the theme files or for the core WordPress files.

    Greg Rose

Topic Closed

This topic has been closed to new replies.

About this Topic