Hi,
Thank you for contacting us and I'd be happy to assist.
When a separate content template is set to show for visitors without the access permission, the Access plugin only replaces the normal content template part and not the other elements on the page.
As the "comments_template" part is loaded after the content template and not inside it, the comments template still shows and it doesn't matter if you're using WordPress or Discourse comments.
You'll need a custom shortcode, that can check whether the current visitor has the right permission to access the current post, using the "toolset_access_api_get_post_permissions" function.
( ref: https://toolset.com/documentation/programmer-reference/access-api-filters/#toolset_access_api_get_post_permissions )
Example:
add_shortcode('allowed', function () {
$userid = get_current_user_id();
global $post;
$allowed = apply_filters( 'toolset_access_api_get_post_permissions', true, $post, 'read', $userid, ICL_LANGUAGE_CODE );
$return = ( $allowed ) ? 1:0;
return $return;
});
This shortcode will return '1' for the "allowed" and '0' for the "not allowed" case.
After that, you'll be able to wrap the call to load the comments section ( i.e. comments_template() ) in your theme's file, in a conditional check using this new shortcode's output.
Example from default Twenty Twenty theme:
( you can check your active theme's template for the single posts to see how it loads the comments_template() function )
<?php
$allowed = do_shortcode('[allowed]');
if ($allowed == 1) {
?>
<div class="comments-wrapper section-inner">
<?php comments_template(); ?>
</div><!-- .comments-wrapper -->
<?php
}
?>
As a result, the comment section will only be loaded, when the visitor is allowed to view the current post.
I hope this helps and please let me know if you need any further assistance around this.
regards,
Waqar