The effects of alcohol on sustanon 250 leucine for – real weight loss & bodybuilding benefits?
Share:
Notifications
Clear all

Hiding Comments

17 Posts
2 Users
1 Reactions
1,624 Views
Posts: 47
Topic starter
(@aaronmckeon)
Trusted Member
Joined: 3 years ago

I need to programmatically hide and disable comments on certain posts depending on a user's role.  However, the typical code for hiding comments is not working.  With wpDiscuz deactivated, the comments disappear.  With wpDiscuz, the code has no effect.  Can you suggest a better code that would eliminate comments entirely from a page?  This was run during the template_redirect action.

 

    $comments = array();
    return $comments;
16 Replies
Asti
Posts: 7617
 Asti
Support
(@asti)
Illustrious Member
Joined: 7 years ago

@aaronmckeon,

You can do it using the wpDiscuz options. 

First of all, you should create a new comment form and enable it for certain post IDs. The option calls Display comment form for post IDs. More info here: https://wpdiscuz.com/docs/wpdiscuz-7/getting-started/manage-comment-forms/comment-form-settings/#comment_form_for_post_id

In the next step, you should find the "Hide comment section for roles" section on the form add/edit section and select certain user roles. 

image
Reply
15 Replies
(@aaronmckeon)
Joined: 3 years ago

Trusted Member
Posts: 47

@asti Thanks for the quick reply, although unfortunately it's not quite that simple.  Some of our posts are categorized as premium (requiring a particular role) and some are not.  This is set by a custom taxonomy called "access-control".  I have a code snippet in place that contains all the logic, but the one piece I can't figure out is how to get rid of comments.

For example, one post may be set to "public" and another may be set to "tier-2" (requiring a tier-2 membership to the site).  If a user is logged in with an unpaid account and the post is set to require tier-2, the comments need to be hidden.  So, I'm hoping there is a line of code that would allow me to stop wpDiscuz for rendering on the page that I can then insert into my code snippet.

-- Aaron

Reply
Asti
 Asti
Support
(@asti)
Joined: 7 years ago

Illustrious Member
Posts: 7617

@aaronmckeon,

Please provide us with the following information:

  1. Please send us the admin login details
  2. Provide some testing user's (User A) login details that should be restricted to see the content of some pages
  3. Provide us some example URL where the testing user (User A) should not see the content

Please send all those information to info[at]gvectors.com email address. I'll ask the developers to check the issue and provide some solutions for you if it's possible. 

Otherwise, they'll add a new hook in the next version of the wpDiscuz plugin. 

Reply
(@aaronmckeon)
Joined: 3 years ago

Trusted Member
Posts: 47

@asti Thanks - just sent the e-mail with all requested information.

Reply
Asti
 Asti
Support
(@asti)
Joined: 7 years ago

Illustrious Member
Posts: 7617

ok, thank you. 

We'll check and back to you ASAP.  

Reply
Asti
 Asti
Support
(@asti)
Joined: 7 years ago

Illustrious Member
Posts: 7617

We'll add a new hook in the next version, so you'll be able to get it to work as you like. 

Reply
(@aaronmckeon)
Joined: 3 years ago

Trusted Member
Posts: 47

@asti Excellent, thanks.  Can you tell me about how soon that would be?  I'm just trying to gauge if it'll be before my site is scheduled to go live.

 

- Aaron

Reply
Asti
 Asti
Support
(@asti)
Joined: 7 years ago

Illustrious Member
Posts: 7617

@aaronmckeon,

We do all our best to release it ASAP. I'll update this topic once it's ready.  

Reply
(@aaronmckeon)
Joined: 3 years ago

Trusted Member
Posts: 47

@asti Just checking in on this.  I noticed an update get released and wasn't sure if this were included.  We are planning on going live this Friday and if this fix isn't in place we'll need to come up with a workaround.  Thanks for any updates.

Reply
Asti
 Asti
Support
(@asti)
Joined: 7 years ago

Illustrious Member
Posts: 7617

@aaronmckeon,

The hook isn't added yet. It'll be available in the next version (no ETA yet).  

Reply
Asti
 Asti
Support
(@asti)
Joined: 7 years ago

Illustrious Member
Posts: 7617

@aaronmckeon,

Here we also need the admin login details. Please send it to us again to info[at]gvectors.com email address. 

Reply
(@aaronmckeon)
Joined: 3 years ago

Trusted Member
Posts: 47

@asti Sent, thanks!

Reply
Asti
 Asti
Support
(@asti)
Joined: 7 years ago

Illustrious Member
Posts: 7617

@aaronmckeon,

The new hook is already added. It's called wpdiscuz_load_template. More info here:  https://wpdiscuz.com/docs/codex/filters/wpdiscuz_load_template/

Reply
(@aaronmckeon)
Joined: 3 years ago

Trusted Member
Posts: 47

@asti Great news, thanks.  I'm trying to call this as part of another function, which currently runs inside the 'template_redirect' action, but it doesn't seem to be working.  Can you confirm if this is possible?  Below please find a shortened version of my code so you understand what I'm doing:

 

add_action( 'template_redirect', 'pp_disable_access' );

function pp_disable_access($post_object) {

	some code here to determine if comments should be hidden...

	if ($pp_disable_view_comments == true) {
		add_filter("wpdiscuz_load_form_and_comments", '__return_false', 10 ,3);
	}

}
Reply
(@aaronmckeon)
Joined: 3 years ago

Trusted Member
Posts: 47

@asti PS - I also tried running it by copying and pasting it exactly as you have it in your documentation and it does not hide comments if you are not logged in.  Let me know if you think I'm doing something wrong.  Thanks.

Reply
Asti
 Asti
Support
(@asti)
Joined: 7 years ago

Illustrious Member
Posts: 7617

@aaronmckeon,

You've added the hook name incorrectly

image

It should be wpdiscuz_load_template. 

 

Reply
Share: