Hide content using 'Hide This' plugin

In my site i have two kinds of users, freelancers and employers.
Employers can post projects.
Any project description page contains the following:

1- project detail heading, author info, bid button, contact me button
2-project description, attachements and comments

(1) are displayed by the template project-detail.php
(2) are displayed by two templates (project-detail-info.php & project-detail-content.php), they are called from inside the project-detail.php by the following two lines:

get_template_part('template/project-detail' , 'info');
get_template_part('template/project-detail' , 'content');

What I need is the following:
non logged in users can only view (1)
logged in users can view (1) and (2)

I have installed a plugin named 'Hide me' and edited the two lined in project-detail .php:

original:

`get_template_part('template/project-detail' , 'info');
get_template_part('template/project-detail' , 'content');`

edited:

` if ( !is_user_logged_in())
{ echo do_shortcode("[hide]");
get_template_part('template/project-detail' , 'info');
get_template_part('template/project-detail' , 'content');
echo do_shortcode("[/hide]");
}
else {
get_template_part('template/project-detail' , 'info');
get_template_part('template/project-detail' , 'content');
}`

You may view the shortcodes used by this plugin in this link:
https://wordpress.org/plugins/hide-this/

But this doesn't seem to produce any difference in the site ! I mean, logged in and non logged in users can see the whole project details page with information (1) and (2)
Could you please help me figure out where the problem is ?

Many thanks in advance

  • Adam Czajczyk

    Hello Layal,

    I hope you're well today and thank you for your question!

    Since you are already editing you template files, there's no need to use any additional plugins for this, so you may safely disable it and revert your template code to original one.

    Then, in order to hide the (2) template from non-logged in users replace these two lines in "project-detail.php"

    get_template_part('template/project-detail' , 'info');
    get_template_part('template/project-detail' , 'content');

    with these:

    if (is_user_logged_in()) {
    get_template_part('template/project-detail' , 'info');
    get_template_part('template/project-detail' , 'content');
    }

    That is all that's necessary here and it should suffice. The "is_user_logged_in()" function checks if the current user of the site is a logged in user or just a visitor. In case of logged user it returns TRUE so the code inside "if ... { }" conditional statement would be executed - templates would be loaded. Otherwise the code would just be skipped.

    Give it a try please and let me know if it worked for you :slight_smile:

    Best regards,
    Adam

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.