Support » Plugin: Ultimate Member – User Profile, Registration, Login, Member Directory, Content Restriction & Membership Plugin » Restricted Content + Ultimate Layouts Filter – still show preview of the post?

  • Resolved mantachris

    (@mantachris)


    Hi Ultimate Member Support Team,

    I have a question regarding the restricted content settings. I am using the Ultimate Layouts Filter Plugin to show previews of some of my posts on one of my pages. I am using the excerpt to be shown on the previews + the dedicated title and picture.

    When I restrict the content, the previews are not shown anymore and only the title is visible. Is there a way to restrict the post but still show the preview (excerpt and picture)?

    Here is a link to visualize my question:
    https://paste.pics/ed39adef151e11e89860c47dc06f93df

    I am sorry if this question has been solved / answered before. I am fairly new to WordPress and try to add some changes to the website.

    Thanks in advance!

Viewing 11 replies - 1 through 11 (of 11 total)
  • Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @mantachris

    Please try adding this code snippet to your theme/child-theme’s functions.php file or use the Code Snippet plugin to run the code:

    function um_custom_data_restricted_singular_post( $post, $restriction_settings, $original_post ) {
    	// if you want to show the original post title instead of the restriction content title
    	// use these object keys https://developer.wordpress.org/reference/functions/get_post/#comment-876
        	$post->post_title = $original_post->post_title;
    	// sometimes $original_post is already customized then please use this way
    	$p = get_post( $original_post->ID );
    	$post->post_title = $p->post_title;
    
            // please use this line if you need to restore the post excerpt
    	$post->post_excerpt = $p->post_excerpt;
    	return $post;
    }
    add_filter( 'um_restricted_singular_post', 'um_custom_data_restricted_singular_post', 10, 3 );

    The above code will show the post excerpt for restricted post.

    Regards,

    Thread Starter mantachris

    (@mantachris)

    Hi @champsupertramp, thanks for your reply and help!

    Sorry for asking maybe too much (codes and coding is not my strength) but could you show me an example on how I can implement the code for a specific post via the Code Snippet Plugin?

    How am I supposed to define the variables for a specific post to make it work?

    Thanks.

    Best,

    • This reply was modified 2 years, 5 months ago by mantachris.
    Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @mantachris

    You can try the following code snippet. Just change the ID 123 to your post ID.

    function um_custom_data_restricted_singular_post( $post, $restriction_settings, $original_post ) {
            if( $original_post->ID == 123 ){
    	// if you want to show the original post title instead of the restriction content title
    	// use these object keys https://developer.wordpress.org/reference/functions/get_post/#comment-876
        	    $post->post_title = $original_post->post_title;
    	// sometimes $original_post is already customized then please use this way
    	   $p = get_post( $original_post->ID );
    	   $post->post_title = $p->post_title;
    	   // please use this line if you need to restore the post excerpt
    	   $post->post_excerpt = $p->post_excerpt;
            }
    	return $post;
    }
    add_filter( 'um_restricted_singular_post', 'um_custom_data_restricted_singular_post', 10, 3 );

    Regards,

    Thread Starter mantachris

    (@mantachris)

    Hi @champsupertramp, thanks for the help. Sadly, changing the ID to one of my post IDs didn’t work when using the code snippets plugin.

    I believe that the ultimate layouts filter plugin is conflicting with ultimate member or preventing running the code.

    Interestingly, I found out that when I change the global site access in ultimate member to logged in useres only and exclude only the page in question, it shows the previews of all posts but still keeps them restricted.
    That would be an option but I still would need to add every single URL from the rest of my site to be excluded by the restriction…

    Do you maybe have any other idea on how to work around this or would you just recommend trying it this way?

    BR and thanks again for the help,
    mantachris

    Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @mantachris

    Does the code without the post ID work? Does it show the excerpt and post title?

    Regards,

    Thread Starter mantachris

    (@mantachris)

    Hi @champsupertramp, sadly not. Here’s is how I copied both codes into the code snippet plugin, maybe I did something wrong:

    without ID: https://paste.pics/8f8f9574e2b128809d53c57a9a268939

    with ID: https://paste.pics/3881e8e8315ec5c959016756d933451f

    Restriction settings at post /wp-admin/post.php?post=8833&action=edit&lang=en: https://paste.pics/1a20c8eaefae14f78de9e341814add2f

    The outcome is still the same as in the first picture I shared at the beginning of this thread.

    BR,
    mantachris

    Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @mantachris

    Could you please try adding this code along with the previous code provided above?

    add_filter( 'um_ignore_restricted_title', '__return_true' );
    add_filter( 'um_ignore_restricted_excerpt', '__return_true' );
    add_filter( 'um_ignore_restricted_content', '__return_true' );
    

    Regards,

    Thread Starter mantachris

    (@mantachris)

    Hi @champsupertramp, works like a charm!

    Only thing that’s left, if it’s possible, is there anyway to also show the post thumbnail?

    Currently it looks like this: https://paste.pics/7f85d907b104303f14ce1c12946d4f7e

    I tried to add these codes:

    $post->post_thumbnail = $p->post_thumbnail;

    and add_filter( 'um_ignore_restricted_thumbnail', '__return_true' );

    I also tried the line add_filter( 'um_ignore_restricted_post_thumbnail', '__return_true' );

    Both did not work…

    Do you have any idea how to also restore the post thumbnail / featured image?

    THANKS!

    BR,
    mantachris

    • This reply was modified 2 years, 5 months ago by mantachris.
    • This reply was modified 2 years, 5 months ago by mantachris.
    Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @mantachris

    For the thumbnail/featured image, you can try the following:

    add_filter("um_restrict_post_thumbnail","__return_true");

    Regards,

    Thread Starter mantachris

    (@mantachris)

    @champsupertramp perfect, thanks so much for the help!!!

    Have a nice day 🙂

    Plugin Contributor Champ Camba

    (@champsupertramp)

    Thanks for letting us know.

    Regards,

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Restricted Content + Ultimate Layouts Filter – still show preview of the post?’ is closed to new replies.