That did not work. Is 'the_post' the right action to use (line 2 in my code)?
- Aaron
Minesh
Supporter
Sprachen:
Englisch (English )
Zeitzone:
Asia/Kolkata (GMT+05:30)
Well - honestly I would like to help you but until and unless I check your setup it would be really time consuming as it will be like I'm sharing the solution without knowing anything.
Do you have any other setup where I can apply the code - is it possible for you to setup another test site on another test install where I can play it and get back to you with the solution?
Okay, I have an idea. Go to sandbox.peakprosperity.com instead. It's an older clone of the development site but I've copied over the code snippet and you should be able to trouble shoot there. I made sure the password is the same as the one previously sent (ending in 4YZm). You shouldn't need anything in your hosts file for this. Let me know if that works. Thanks.
- Aaron
Minesh
Supporter
Sprachen:
Englisch (English )
Zeitzone:
Asia/Kolkata (GMT+05:30)
It is asking me for the authorization access details when I try to load the site.
Can you please share authorization access details so that I can access the sandbox site.
Apologies for not seeing this response earlier. Here you go:
Username = peak
Password = peak!
We will be re-cloning the site in the next 24 hours so if that username stops working, try "sneak" instead.
- Aaron
Minesh
Supporter
Sprachen:
Englisch (English )
Zeitzone:
Asia/Kolkata (GMT+05:30)
We will use the WordPress hook "template_redirect" and I've adjusted the code.
I've adjusted the code as given under within the code snippet:
add_action( 'template_redirect', 'pp_disable_comments' );
function pp_disable_comments($post_object) {
// only run if single page
if (is_single()) {
$pp_disable_comments = false;
$user = wp_get_current_user();
$roles = (array) $user->roles;
// NEED TO CAHNGE ADMINISTRATOR BACK AFTER DONE TESTING
// skip if user is contributor/author/editor/administrator OR if the post is public
if ((!in_array('contributor', $roles) && !in_array('contributor', $roles) && !in_array('author', $roles) && !in_array('editor', $roles) && !in_array('xxadministrator', $roles)) || has_term('public', 'access-control')) {
// run if post is tier-0 only
if (has_term('tier-0', 'access-control')) {
// check if user not in allowed roles
if (!in_array('tier-0', $roles) && !in_array('tier-1', $roles) && !in_array('tier-2', $roles)) {
$pp_disable_comments = true;
}
}
// run if post is tier-1 only
if (has_term('tier-1', 'access-control')) {
// check if user not in allowed roles
if (!in_array('tier-1', $roles) && !in_array('tier-2')) {
$pp_disable_comments = true;
}
}
// run if post is tier-2 only
if (has_term('tier-2', 'access-control')) {
// check if user not in allowed roles
if (!in_array('tier-2', $roles)) {
$pp_disable_comments = true;
}
}
}
// disable comments if required
if ($pp_disable_comments == true) {
global $post;
$post->comment_status="closed";
}
}
}
When I visit the following page I can see the comment section is not available: versteckter Link
That means comment section is gone that is expected result.
Can you please confirm it works at your end as well.
I can confirm it appears to be working now. It is not showing comments when unauthenticated and it is showing comments when authenticated. Thanks for the help!
- Aaron