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.

5 Likes