Version 1.5.1 of the plugin is now available in the WordPress plugin repository.
The biggest change will affect sites that have previously enabled the Create Discourse User on Login option. This option no longer logs users into Discourse when they log into WordPress. If it is selected, after logging into WordPress it runs a check to see if the user exists on Discourse. If the user doesn’t exist, a user is created through the API. If you would like to add a link to your WordPress site to allow users to login directly to Discourse, you need to create an SSO login link. Have a look at the Creating an SSO Login Link section of the WP Discourse Tips and Tricks topic to see how to do that.
If you have the Create Discourse User on Login option enabled, you should see a one-time notice telling you about this change.
Other changes include:
- adding a warning to the SSO provider tab if the WordPress admin email doesn’t match an admin user on Discourse
- adding some functions that can be used in themes or plugins for hooking into Discourse
get_discourse_user( $user_id, $match_by_email = false )
get_discourse_user_by_email( $email )
create_discourse_user( $user, $require_activation = true )
add_user_to_discourse_group( $user_id, $group_name, $force_update = false ) // force update fetches fresh groups data from Discourse
remove_user_from_discourse_group( $user_id, $group_name, $force_update = false )
These are all static functions. To call them you need to include the
WPDiscourse\Utilities\Utilities namespace. For example, to get a Discourse user who has a WordPress id of 12, either by id, or by email you would call:
WPDiscourse\Utilities\Utilities::get_discourse_user( 12, true );
Later this week I will create a separate topic to document these functions and give some ideas about how they can be used with WordPress membership plugins.
Changes to the Discourse metabox
Version 1.5.6 adds an option to link existing Discourse topics to WordPress posts. It also lets you unlink posts from Discourse. What this does is remove all the Discourse metadata that is associated with a post.
The Discourse meta-box on the post edit screen defaults to this:
After publishing a post it gives you the option to Update the topic (republish the content to Discourse) or to unlink the post from Discourse:
To link to an existing Discourse topic, copy and paste the topic’s URL into the URL input. Linking to a Discourse topic will cause that topic’s comments to be displayed beneath the post. It does not overwrite the Discourse topic’s content.
After a post has been linked to an existing topic it is in the same state as it would be if you had published it from Discourse in the first place. If you then select the Update Discourse topic checkbox, the Discourse topic content will be overwritten with the content of the WordPress post. Selecting Unlink Post from Discourse will remove all Discourse meta-data. After unlinking the post, it is possible to relink it with a different topic.
(todo: remove the question mark from the Unlink Post label.)
Changes to the Force Publish option
The Force Publish option causes all posts published on WordPress, and all post’s updated on WordPress, to be published to Discourse. What has changed for this option is that it now automatically publishes to the default Discourse category that has been set on the Publishing Options tab.
wpdc_comment_body filter has been added that gives access to the html of each Discourse comment before it is added to the comments template. This can be used to parse the comment html.
The code where the filter is added is here: wp-discourse/discourse-comment-formatter.php at master · discourse/wp-discourse · GitHub
Please let me know if you run into any issues with the latest update. As always, previous versions of the plugin are available at the bottom of this page.