Support » Plugin: Client Portal - Private user pages and login » Hide Custom Content on Private Pages Template?

  • Resolved Kenneth Feldman

    (@kenneth-feldman)


    Hello,

    I absolutely LOVE this plugin, it’s great!

    Here’s my question, (along with maybe a clue to the answer?).

    ISSUE IN SHORT:

    I have a custom page template for Private Pages, and I want to include ACF Fields (custom content) in the hidden area of the users’ Private pages.

    But anything outside of <?php the_content(); ?> is not hidden from non-logged-in visitors to the private page URL.

    LONGER EXPLANATION:

    TO START

    I can see that Client Portal creates custom post types for the Private Pages.

    I have created a new template in my child theme called content-private-page.php which is successfully used as the template when Private Pages are shown.

    By design, Client Portal hides all page/post content inside of (the_content) <?php the_content(); ?> when a visitor/user is NOT logged in and tries to visit the private page url, e.g. https://www.domain.com/private-page/user-name/

    MY ISSUE

    I want to use Advanced Custom Fields to create customized content for each users’ Private Page.

    But when I add the PHP code snippets for the custom fields to my template, their output is not hidden for non-logged-in users visiting the private page url (e.g. https://www.domain.com/private-page/user-name/)

    I understand that this is because those ACF PHP snippets are located outside of the (WP the_content) <?php the_content(); ?> in my template.

    MY QUESTION (and clue?)

    I have encountered a similar situation in the past, where I wanted to use the built-in WordPress Password Protect feature on custom post type posts.

    In that case, the same thing happened — the Password Protect only acted on content located inside of the (WP the_content) <?php the_content(); ?>.

    As such, any HTML or PHP located in the template outside of (WP the_content) <?php the_content(); ?> was not hidden by the Password Protect action.

    However, the successful solution in that case, was to place a PHP IF/ENDIF statement around the additional ACF PHP code snippets which were added in the template file.

    Example:

    <!– HIDES ACF FIELDS with WP Password Protect –>
    <?php if( !post_password_required( $post )): ?>

    “My Custom Content Here”

    <!– ENDS HIDE ACF FIELDS with WP Password Protect –>
    <?php endif; ?>

    <?php the_content(); ?>

    I’m not a programmer, but it looks like this is saying: IF this post is Password Protected, then ALSO protect this area of the template outside of the <?php the_content(); ?>.

    AND SO…

    Is there a similar IF/ENDIF statement I could use outside of the <?php the_content(); ?> — which would also hide post content if the specific user is not logged in to their Private Page area?

    Something that says?: IF this post is a Client Portal Private Page, then please hide this additional info which resides outside of the regular <?php the_content(); ?> portion of this template (until this user logs in).

    Thank you so much in advance, and I hope this all makes sense.

    • This topic was modified 10 months ago by  Kenneth Feldman. Reason: clarificfation
Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Contributor Cristian Antohe

    (@sareiodata)

    Hi Kenneth,

    You are right, Client Portal only protects the_content area. However, you can easily protect extra information like the one found in ACF custom fields. For example:

    
    if( is_user_logged_in() ){
                    if( ( get_current_user_id() == $post->post_author ) || current_user_can('delete_user') ){
                        // list your ACF fields here! 
                    }
    }
    

    It’s expecting the $post global variable to be available in the template, however that should be the norm with most theme templates. If it’s not, you’ll have to define it as global.

    Let me know if this help with your issue!

    Kenneth Feldman

    (@kenneth-feldman)

    Hi Cristian,

    Thanks! It’s great to know this is possible.

    However, can I ask for one more bit of guidance?

    In my Theme, the template is in two parts; single.php (the outer portion), and content.php (the inner portion).

    See https://pastebin.com/Dgtfifh8 for the inner part, content-private-page.php

    (Scroll down 3/4 of the way to see where I want to add the ACF fields.)

    I plugged in your code and it didn’t quite work, getting syntax error.

    I think it’s either missing the ($post global variable like you mentioned) or maybe missing some <?php beginnings or endings <?php endif; ?> ?

    Can you take a quick look and advise?

    Thanks!

    Plugin Contributor Cristian Antohe

    (@sareiodata)

    Yes, you would need opening and closing PHP tags there. So it’s

    
    <?php 
    if( is_user_logged_in() ){
                    if( ( get_current_user_id() == $post->post_author ) || current_user_can('delete_user') ){
                        // list your ACF fields here! 
                    }
    }
    ?>
    
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Hide Custom Content on Private Pages Template?’ is closed to new replies.