# How does Discourse replace WP comments exactly?

**URL:** https://meta.discourse.org/t/how-does-discourse-replace-wp-comments-exactly/157969
**Category:** WordPress
**Created:** [July 16, 2020, 7:41pm UTC](https://meta.discourse.org/t/how-does-discourse-replace-wp-comments-exactly/157969 "2020-07-16T19:41:18Z")
**Posts on this page:** 15
**Page:** 1

<div class="post-metadata">

### Author: ![Kayla](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/kayla/32/128523_2.png) [@Kayla](https://meta.discourse.org/u/Kayla)
#### Post date: [July 16, 2020, 7:41pm UTC](https://meta.discourse.org/t/how-does-discourse-replace-wp-comments-exactly/157969/1 "2020-07-16T19:41:18Z")

</div>

We are using Discourse instead of WP comments (“Remove WordPress Comments Template” is checked, as well as Ajax). I have Toolset Access control on a custom post type that is posting to Discourse (to a private category that aligns with the access control). Normally this type of control would also affect visibility of the post comments, but it’s not affecting the display of the Discourse comments. Any ideas?

---

<div class="post-metadata">

### Author: ![madrush](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/madrush/32/119502_2.png) [@madrush](https://meta.discourse.org/u/madrush)
#### Post date: [July 17, 2020, 12:28am UTC](https://meta.discourse.org/t/how-does-discourse-replace-wp-comments-exactly/157969/2 "2020-07-17T00:28:25Z")

</div>

Perhaps I can add some further context here:

We have a private custom post type on our Wordpress site, whose posts should be connected with topics in a private Discourse category. The same users who have access to the Discourse category have access to the post on Wordpress. We are handling this by assigning these users to the Editor _role_ in Wordpress, while in Discourse they belong to a _group_ which gives them access to the private category.

In no case should unauthenticated users see either the posts in Wordpress or the topic threads in Discourse. This is working as intended through role and group access controls, respectively. On the Wordpress side, as noted above, we are using Toolset Access to restrict access to all posts of this custom post type.

However, private discussion threads from Discourse are displaying to the public via embedding in Wordpress, even though the post content itself is hidden. In other words, the embedded Discourse comments are not being hidden by access control. We are trying to figure out what might be placing this output outside the control loop, and how to rectify.

---

<div class="post-metadata">

### Author: ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)
#### Post date: [July 20, 2020, 4:24pm UTC](https://meta.discourse.org/t/how-does-discourse-replace-wp-comments-exactly/157969/3 "2020-07-20T16:24:54Z")

</div>

> [@Kayla](#):
>
> I have Toolset Access control on a custom post type that is posting to Discourse (to a private category that aligns with the access control). Normally this type of control would also affect visibility of the post comments, but it’s not affecting the display of the Discourse comments.

The [WP Discourse](https://github.com/discourse/wp-discourse) plugin displays comments by loading a custom comments template. It uses the WordPress `comments_template` filter to load the custom template. I’m not sure why the comments are still loading when you have Toolset Access control configured for a post type. I’ll look into what is going on with that.

I think the plugin should add an option to not load comments for posts that have been published to a private Discourse category. When enabled, just a link to the Discourse topic would be displayed. I’m not sure that would solve the issue you’re dealing with though.

---

<div class="post-metadata">

### Author: ![madrush](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/madrush/32/119502_2.png) [@madrush](https://meta.discourse.org/u/madrush)
#### Post date: [July 20, 2020, 8:33pm UTC](https://meta.discourse.org/t/how-does-discourse-replace-wp-comments-exactly/157969/4 "2020-07-20T20:33:58Z")

</div>

Hi Simon, I’m working with@Kayla on this. What you describe here would solve our issue.

> [@simon](#):
>
> I think the plugin should add an option to not load comments for posts that have been published to a private Discourse category. When enabled, just a link to the Discourse topic would be displayed.

It still would be good to know, too, how to include the Discourse comments template within our more granular access control. Thanks!

---

<div class="post-metadata">

### Author: ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)
#### Post date: [July 20, 2020, 8:40pm UTC](https://meta.discourse.org/t/how-does-discourse-replace-wp-comments-exactly/157969/5 "2020-07-20T20:40:25Z")

</div>

> [@madrush](#):
>
> What you describe here would solve our issue.

Great! I don’t think there will be a problem to get that into the next update of the plugin. I’ll try to have that done by the end of the week. I’ll keep you posted about progress on that.

> [@madrush](#):
>
> It still would be good to know, too, how to include the Discourse comments template within our more granular access control.

I think the issue that you’re running into is related to the priority that [WP Discourse](https://github.com/discourse/wp-discourse) is hooking into the WordPress `comments_template` filter hook. The [WP Discourse](https://github.com/discourse/wp-discourse) plugin is using a priority of `20` for calling the function that hooks into this filter. The Toolset plugin is probably hooking into that filter with a lower priority to prevent the comment template from being loaded for protected pages.

---

<div class="post-metadata">

### Author: ![Kayla](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/kayla/32/128523_2.png) [@Kayla](https://meta.discourse.org/u/Kayla)
#### Post date: [July 24, 2020, 4:32am UTC](https://meta.discourse.org/t/how-does-discourse-replace-wp-comments-exactly/157969/6 "2020-07-24T04:32:37Z")

</div>

> [@simon](#):
>
> The Toolset plugin is probably hooking into that filter with a lower priority to prevent the comment template from being loaded for protected pages.

I got in touch with Toolset about this and I was mistaken about the expected behavior. The Toolset Access plugin doesn’t hook into the comments template _at all._ Hiding comments on restricted content requires custom code to hook into their toolset\_access\_api\_get\_post\_permissions filter to suppress/allow the rendering of the comments template at the theme level. I apologize that I did not realize their content restriction is quite literally about the content template itself. 🤦‍♀️

---

<div class="post-metadata">

### Author: ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)
#### Post date: [August 8, 2020, 10:01pm UTC](https://meta.discourse.org/t/how-does-discourse-replace-wp-comments-exactly/157969/7 "2020-08-08T22:01:28Z")

</div>

> [@simon](#):
>
> I think the plugin should add an option to not load comments for posts that have been published to a private Discourse category. When enabled, just a link to the Discourse topic would be displayed.

This option has been added to the plugin in version 2.0.7. It is available in the [WordPress repo](https://wordpress.org/plugins/wp-discourse/) now.

When you select the plugin’s Enable Discourse Comments option, you will now see three options for comment types:

 ![image](https://global.discourse-cdn.com/meta/original/3X/c/1/c1cf0bbb1669e561dce3fad5f331297a73f5c485.png)

Select the “Display comments for public topics” option to only have comments displayed for topics that are in public Discourse categories. If a topic is published to a private category, a link to the topic and its comment _count_ will be displayed.

If a topic that has been published from WordPress to Discourse is moved from a public to a private category on Discourse, comments will be removed from WordPress and replaced with a link. This change will take up to 10 minutes to occur because the [WP Discourse](https://github.com/discourse/wp-discourse) plugin caches comment data that’s returned from Discourse. You can break the category cache immediately by selecting the Force Category Update option from the plugin’s Publishing Settings page and saving that settings page.

To allow the plugin to access category permissions for Discourse subcategories, you need to select the Display Subcategories option from the plugin’s Publishing Settings tab. If that option is not enabled and the “Display comments for public topics” option has been enabled, subcategories on Discourse will all be considered to be private and a link will be displayed instead of comments.

**Note:** having the plugin recognize category changes that are made directly on Discourse only available if your site is on a recent version of Discourse.

To programmatically control which users have Discourse comments displayed for them, you can completely bypass loading the [WP Discourse](https://github.com/discourse/wp-discourse) comments for a user with the [`wpdc_load_comments_template_for_user`](https://github.com/discourse/wp-discourse/blob/master/lib/discourse-comment.php#L315) filter hook. That hook is passed three arguments: `$load_template` (defaults to `true`), `$current_user`, and `$post_id`. Return `false` from a function that hooks into the filter to prevent comments from being loaded for a particular user.

---

<div class="post-metadata">

### Author: ![Kayla](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/kayla/32/128523_2.png) [@Kayla](https://meta.discourse.org/u/Kayla)
#### Post date: [August 9, 2020, 4:32pm UTC](https://meta.discourse.org/t/how-does-discourse-replace-wp-comments-exactly/157969/8 "2020-08-09T16:32:36Z")

</div>

Changes I’m seeing with this update are that while `discourse_replies_html` loads and looks as expected, it seems to be failing to load `discourse_no_replies_html` (seeing  
“Join Discussion Link: no Comments” text link, but not our template). Also, if the post has not been published to Discourse, there’s a new message is appearing: “Comments are not currently available for this post.” These are all public posts to public Discourse categories.

For posts published to private Discourse category, it seems to be loading the default WP comments form. No link to Discourse topic.

“Display comments for public topics” is set, as well as “Display Subcategories.” I updated Clear Cached Comment HTML + Force Category Update. Am I overlooking anything?

---

<div class="post-metadata">

### Author: ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)
#### Post date: [August 9, 2020, 6:14pm UTC](https://meta.discourse.org/t/how-does-discourse-replace-wp-comments-exactly/157969/9 "2020-08-09T18:14:08Z")

</div>

> [@Kayla](#):
>
> if the post has not been published to Discourse, there’s a new message is appearing: “Comments are not currently available for this post.” These are all public posts to public Discourse categories.

Thanks for reporting that! The issue should be fixed in [WP Discourse version 2.0.8](https://wordpress.org/plugins/wp-discourse/).

I’m going to be making a few changes to the plugin later today or tomorrow that should take care of the other issues you are reporting. Failing to load the WordPress comments template for posts that have not been published to Discourse had to get fixed right away.

---

<div class="post-metadata">

### Author: ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)
#### Post date: [August 10, 2020, 9:37pm UTC](https://meta.discourse.org/t/how-does-discourse-replace-wp-comments-exactly/157969/10 "2020-08-10T21:37:23Z")

</div>

> [@Kayla](#):
>
> For posts published to private Discourse category, it seems to be loading the default WP comments form. No link to Discourse topic.

Here’s what I’m seeing when I select the " Display comments for public topics" option and the “Show Existing WP Comments” option, then publish a post with existing WordPress:

 ![image](https://global.discourse-cdn.com/meta/original/3X/7/2/72a38090ea36a6a1ff6c53fdaa79eaefa8a77d63.png)

From a user’s point of view, this doesn’t seem very clear (that could be fixed with some WordPress customization), but the link to the Discourse comments exists.

> [@Kayla](#):
>
> I updated Clear Cached Comment HTML + Force Category Update. Am I overlooking anything?

If you have enabled the “Cache Comment HTML” site setting, try disabling it. That setting shouldn’t cause an issue, but unchecking it will simplify debugging this.

Send me any more details that you have about the issue. I’ll be pushing a small update to the WordPress repo later today fo fix an issue with the “Unlink Topic” button that’s happening with the WordPress 5.5 release.

---

<div class="post-metadata">

### Author: ![Kayla](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/kayla/32/128523_2.png) [@Kayla](https://meta.discourse.org/u/Kayla)
#### Post date: [August 18, 2020, 11:51pm UTC](https://meta.discourse.org/t/how-does-discourse-replace-wp-comments-exactly/157969/11 "2020-08-18T23:51:49Z")

</div>

We’re at version 2.1.1 with WP 5.5. We don’t have comment caching turned on, and we are not using WP comments (but now no longer seeing the default form load, so that is good).

However, sometimes the custom templates load and sometimes they do not. We reverted to show comments for all posts regardless of whether the Discourse topic is private or not, but that didn’t help. I can’t figure out the why, but it seems persistent for the individual posts. Examples for public posts in public topics:

**no commments, not loading `discourse_no_replies_html`:**

> **[Ending Writings](https://metapsychosis.com/podcast/ending-writings/)**
>
> Hosts Mary Thaler and Geoffrey Edwards finish up the episode on Endings by switching from talking about how to write endings, to how to end writings – often itself a tricky step.

> **[An introduction to Jodo’s movies: “Who Is Alejandro Jodorowsky?”](https://metapsychosis.com/who-is-alejandro-jodorowsky/)**
>
> How to decipher Alejandro Jodorowsky’s symbolic film world? Here’s an introduction.

**no comments, is loading `discourse_no_replies_html`:**

> **[Sutra of the Computer Body: Questions for Karina Bush](https://metapsychosis.com/sutra-of-the-computer-body-questions-for-karina-bush/)**
>
> “I’ve found a techno relationship cuts right into the core, the soul, brings out an almost more real version of yourself, makes you see yourself differently, your own potential to be better.

> **[Writing in a Second Language](https://metapsychosis.com/podcast/writing-off-the-deep-end-episode-9-writing-in-a-second-language/)**
>
> Hosts Mary Thaler and Geoffrey Edwards discuss some of the issues around writing when one lives in a city that speaks a different language than one’s native tongue.

**has comments, not loading `discourse_replies_html`**

> **[Dissecting the video-essay: “Perreo as a spatio-temporal re-configurator”](https://metapsychosis.com/dissecting-the-video-essay-perreo-as-a-spatio-temporal-re-configurator/)**
>
> Reggaeton took over the planet. Latin music had never been so popular, so present in the global arena, so influential. But, is the world ready for a formal, scholastic study of the phenomenon?

> **[Writing Endings](https://metapsychosis.com/podcast/writing-endings/)**
>
> Hosts Mary Thaler and Geoffrey Edwards talk about Endings across two related episodes. This first deals with Writing Endings. We talk about several contexts, single book endings or endings of series…

**has comments, is loading `discourse_replies_html`**

> **[Writing as Scientists, Part 2](https://metapsychosis.com/podcast/writing-off-the-deep-end-episode-5b-writing-as-scientists-part-2/)**
>
> Geoffrey Edwards and Mary Thaler talk about how their careers as scientists—working in fields like astrophysics, geomatics, microbiology, and ocean science—influenced the way they write fiction…

> **[A rare David Lynch interview about meditation, creativity and the absence of...](https://metapsychosis.com/a-rare-david-lynch-interview-about-meditation-creativity-and-the-absence-of-anger/)**
>
> A never-before-heard interview with David Lynch by Mitch Horowitz, mostly about meditation and creativity.

---

<div class="post-metadata">

### Author: ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)
#### Post date: [August 19, 2020, 12:06am UTC](https://meta.discourse.org/t/how-does-discourse-replace-wp-comments-exactly/157969/12 "2020-08-19T00:06:40Z")

</div>

It’s possible that the issue is related to the custom templates, but there’s [another report](https://meta.discourse.org/t/wp-discourse-comments-only-being-linked-to/160989) of an issue with the comment template not loading and the comment link being displayed instead. I can’t reproduce the issue on my development site, but I’m going to make a small change to the plugin that should fix the problem. I’ll have that ready by early tomorrow. Thanks for your patience with this!

---

<div class="post-metadata">

### Author: ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)
#### Post date: [August 19, 2020, 8:18pm UTC](https://meta.discourse.org/t/how-does-discourse-replace-wp-comments-exactly/157969/13 "2020-08-19T20:18:28Z")

</div>

> [@Kayla](#):
>
> We’re at version 2.1.1 with WP 5.5

Can you try updating the plugin to [version 2.1.2](https://wordpress.org/plugins/wp-discourse/) and let me know if that fixes the issue?

---

<div class="post-metadata">

### Author: ![madrush](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/madrush/32/119502_2.png) [@madrush](https://meta.discourse.org/u/madrush)
#### Post date: [August 20, 2020, 6:45pm UTC](https://meta.discourse.org/t/how-does-discourse-replace-wp-comments-exactly/157969/14 "2020-08-20T18:45:03Z")

</div>

I can confirm that updating to 2.1.2 fixed the template-loading issue for us. Thank you!

---

<div class="post-metadata">

### Author: ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)
#### Post date: [September 19, 2020, 6:45pm UTC](https://meta.discourse.org/t/how-does-discourse-replace-wp-comments-exactly/157969/15 "2020-09-19T18:45:29Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
