Connect WP Discourse to Discourse

After you’ve installed the WP Discourse Plugin you need to connect it to your Discourse. When you’re ready to go, watch this short video, or follow the instructions below.

Next Step

Once the plugin is connected, head over to the topic describing the feature you want to set up:


Instructions

Steps

When you’re looking at the Connection tab of the WP Discourse plugin settings, there will always be a notice at the top of the page which will tell you whether it is connected to your Discourse. To establish a connection, enter:

  1. Enter the URL of your forum in the Discourse URL settings field

  2. Review the Publishing Username setting. Unless you have a specific reason to change this, keep it as “system”. If you change this it has to be a username of an admin user on your Discourse. You can find the username of a user under their name when you click on their avatar.

  3. Create a Discourse API key for Wordpress:

    1. Go to your Discourse Admin Panel (in your discourse forum), and click on “API”.

    2. Create a new key with the following:

      • Description: enter a label that makes it clear what this key is for
      • User Level: select “All Users”
      • Scope: select “Global”
    3. Copy the key that appears on the screen and click “Continue”.

  4. Paste the API key into the API Key setting in WP Discourse.

When you’ve filled out these settings make sure you click the ‘Save Options’ button. If everything is correctly configured, you should see a notice that “You are connected to Discourse” at the top of the page.

Multisite

The WP Discourse plugin has a Multisite Configuration option for the case where one Discourse forum is connected to a network of multiple WordPress. This option is available on the Connection settings tab of the main site of a network.

Selecting it allows some of the plugin’s settings to be used over the entire network (all the connection options, the Webhook options, the DiscourseConnect Secret Key, and Enable DiscourseConnect setting) Enabling this setting will create an extra database table that’s used for associating Discourse topic_ids with WordPress blog_ids when posts are published from WordPress to Discourse.

Features not supported in Multisite

Using WordPress as a DiscourseConnect Client is not supported on Wordpress Multisite.

Granular API Key (new :sparkles:)

You can now create a granular API key for the WP Discourse plugin. Granular API keys will become the standard way to connect WP Discourse to Discourse in the near future.

How to use a Granular key

Here’s how you can use a Granular key:

  1. First, make sure you’re on version 2.4.3 of the plugin, and the latest version of Discourse on the tests-passed branch. WP Discourse granular API keys are not yet supported on Discourse stable.

  2. Go to the API panel in the Discourse admin dashboard and create a new “All Users” key, but with a “Granular” Scope.

  3. At the bottom of the Scopes list you’ll find the Wordpress scopes. Select the “Publishing” scope (required at the moment), and scopes for any other features you’re using in the WP Discourse plugin, and click “Save”.

  4. Now replace your old key in the API Key setting in WP Discourse with your new Granular key and save your settings.

When you save your WP Discourse settings, you should see the normal “You are connected to Discourse!” message.

If you see “You are not connected to Discourse…” it may be because your scopes are incorrect. The plugin compares the scopes of your API key to the features you have currently enabled. If you have insufficient scopes, it will consider you to not be connected. You can see which scopes are missing by enabling the connection logs and looking at the error messages in the Logs viewer.

The WP Discourse Scopes

There are four scopes for the WP Discourse plugin:

  1. Publishing. This scope allows you to publish posts from Wordpress to Discourse. This scope is required, even if you’re not publishing posts (e.g. only using DiscourseConnect) as it includes functionality that all features use. This will be decoupled in the future, making all scopes optional.

  2. Commenting. This scope allows to show replies to posts published to Discourse in Wordpress as comments.

  3. DiscourseConnect. This scope allows to use DiscourseConnect (in any configuration).

  4. Utilities. This scope is needed for certain utility functions available in the plugin. If you have any custom code that interacts with the plugin you should enable this scope, unless you’re sure you don’t need it.

Why use a Granular key?

The primary reason to use a granular key is security. A Global API key allows anyone who has the key to act like an administrator on your Discourse. This means the security of your Discourse is dependent on the security of your Wordpress. A granular key is much less powerful, being limited to the scopes you enable for it.

7 Likes

We are seeing an issue, while updating Posts on Wordpress is not updating related post on Discourse. We are getting following error in logs.

ERROR:
publish.ERROR: update_post.post_error {“wp_title”:"title … ",“wp_author_id”:“2205402”,“wp_post_id”:3179224,“response_message”:“You are not permitted to view the requested resource. The API username or key is invalid.”,“http_code”:403}

We are using Granular key to connect WP Discourse to Discourse with “Wordpress Pubblishing” & “Wordpress Commenting” scopes. Can someone please help me with this?

Hello @deepak_dhamde I’m sorry you’re having an issue. I’m travelling today but will try to recreate your issue and get back to you first thing tomorrow.

Hey @deepak_dhamde I’ve recorded a video of myself setting up a granular key with the scopes you’re using. If you could review and let me know if you’re doing anything differently.

Hi @angus, Sorry for late response.
We are following exact same procedure to generate Granular Key but still seeing same 403 error in logs. When we update wordpress posts, the related topic on discourse is not getting updated.

ERROR:

[2024-09-16 06:51:28] publish.ERROR: update_post.post_error {“wp_title”:“Testing update post feature on staging site”,“wp_author_id”:“2168699”,“wp_post_id”:3175772,“response_message”:“You are not permitted to view the requested resource. The API username or key is invalid.”,“http_code”:403}

Hey @deepak_dhamde.

There will likely be some small difference in the way you’re setting it up, or your environment. It’s hard for me to find that difference without more information. Here’s some ways we can move forward:

  1. you could give me access to your environment (happy to sign an NDA) so I can take a look; or
  2. you could record your own video of you doing the same thing I just did (send it to me privately); or
  3. you can take another look and consider these factors:
    • Is your Discourse and Wordpress up to date?
    • Are you able to create a working “Global” key?
    • Have you tried getting different members of your team to do the same set of steps (sometimes a fresh set of eyes will see something new)
    • share the “meta” file in your WP Discourse log viewer with me (i.e. your Wordpress environment) and I’ll see if anything stands out.

Hey @angus ,
We created a new Granular key, followed the procedure you mentioned in the video and enabled edit in post scope and it started working, Thank you very much for being so patient & supportive.

1 Like