• Until now, I have used the plug-in “User Access Manager” (“UAM”) by Alexander Schneider to protect the family area of my mainly private homepage; I do not need more functions than this plug-in offers. Unfortunately, User Access Manager consumes a lot of resources, so I looked for an alternative and found it in “Members”. I only need access authorisation to separate the private image area from the actual homepage.

    For further understanding: I use the theme “GeneratePress”, a column at the right side shows an overview of the current blog postings (see screenshots). The rest of the configuration can be found below.

    Now two problems occur with Members:

    On the one hand, Members uses the user roles created by UAM in the user database, but not the entries in the pages and blog posts (done while using User Access Manager). This means that I have to manually rework more than 400 pages and posts. Only a problem of working time, I will have to live with that and spend a day or so.

    On the other hand, however, post titles and post images from the (restricted) family area are displayed in the overview (right-hand column) even for visitors who are not logged in and have been restricted to users with the role “family”. Only after that is an error message displayed (see screenshots).

    This is neither desirable nor useful.

    How can I ensure that posts with restricted access for non-authorised persons are not displayed in this overview from the outset and in their entirety – as it was happening, for example, with User Access Manager all by itself? Please take into account that I am not a programmer with special skills, but only a very simple user of WordPress.

    Currently, the homepage is rather daunting for all visitors except family members.

    Website: https://www.weinzettl.info
    WordPress: V6.2.2
    PHP: V8.2.1
    Theme: GeneratePress V3.3.0
    Plugin: Members V3.2.5

    Additional Feature Request: About the error message regarding an access restriction that can be defined in the settings: Wouldn’t a(n alternative) link to a designed page make sense there?

    Kind regards
    Ernst

    The page I need help with: [log in to see the link]

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Caseproof

    (@caseproof)

    Hi Ernst,

    The content permission tool in Members protects the post content (that’s what you write in the post editor), post excerpt, and post comments. It does not block anything else including meta fields that some plugins might use. That is the reason why you can still see the post title and featured image in the post list or sidebar.

    To remove posts from the main loop (main posts area) you can add the code below at the end of your theme’s functions.php file:

    add_action( 'pre_get_posts', function ( $query ) {
    	if ( is_admin() ) return;
    	// Replace family_role below with Family role slug
    	if ( current_user_can( 'administrator' ) || current_user_can( 'family_role' ) ) return;
    	if ( !$query->is_main_query() ) return;
    	
    	$posts = get_posts( array( 'post_type' => 'post', 'post_status' => 'publish', 'numberposts' => -1 ) );
    	if( empty( $posts ) ) { return; }
    	$protected_posts = array();
    	foreach( $posts as $post ) {
    		if( !members_can_current_user_view_post( $post->ID ) ) {
    			$protected_posts[] = $post->ID;
    		}
    	}
    	if( empty( $protected_posts ) ) { return; }
    
    	$query->set( 'post__not_in', $protected_posts );
    } );

    Removing protected posts from sidebar requires determining if the query runs in the sidebar. Please contact theme author and see if they can help you with modifying sidebar query via pre_get_posts action hook.

    Best

    Thread Starter Ernst Weinzettl

    (@ernstw)

    Hi!

    Thank you for your quick reply. As there was a “typo”*) in your code (I copied from mail, here in post the typo is not existing) I needed some time to get my site working after inserting the code. ??

    BUT hooks to get your code working as intended in GeneratePress are made by users. And I really do not understand theese options well enough. So thanks für your help but at least for next weeks I have to return to User Access Manager where the news column works well as expected. So sorry.

    At this moment there is so much (other) work to do. Maybe I come back later.

    Kind regards
    Ernst

    *) “$protected_posts[] = $post->ID;” in the mail is “$protected_posts[] = $post->ID;”

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Restricted access does not work as expected’ is closed to new replies.