# Latest WP-Discourse Update is causing some unexpected behaviour

**URL:** https://meta.discourse.org/t/latest-wp-discourse-update-is-causing-some-unexpected-behaviour/218884
**Category:** WordPress
**Created:** [February 20, 2022, 4:29pm UTC](https://meta.discourse.org/t/latest-wp-discourse-update-is-causing-some-unexpected-behaviour/218884 "2022-02-20T16:29:31Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![itsbhanusharma](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/itsbhanusharma/32/180717_2.png) [@itsbhanusharma](https://meta.discourse.org/u/itsbhanusharma)
#### Post date: [February 20, 2022, 4:29pm UTC](https://meta.discourse.org/t/latest-wp-discourse-update-is-causing-some-unexpected-behaviour/218884/1 "2022-02-20T16:29:31Z")

</div>

The latest commit to the WP-Discourse plugin is causing all the custom posts (made through EventON Plugin) to be attributed to `system` user despite the user existing on both discourse and WordPress.

If we roll back to 2.3.7, it works as expected but updating to 2.3.8 causes this bug to happen.

We receive this error via emails:

```plaintext
Reason for failure:
 A 400 response code was returned from Discourse.
 param is missing or the value is empty: post
 Did you mean? post
        post[raw]
        controller
        title

```

I thought it might be helpful in identifying the probable cause.

---

<div class="post-metadata">

### Author: ![angus](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/angus/32/341715_2.png) [@angus](https://meta.discourse.org/u/angus)
#### Post date: [February 21, 2022, 7:52am UTC](https://meta.discourse.org/t/latest-wp-discourse-update-is-causing-some-unexpected-behaviour/218884/2 "2022-02-21T07:52:27Z")

</div>

Hey, could you share a link to the plugin you’re referring to? Also are you seeing anything in the [WP Discourse](https://github.com/discourse/wp-discourse) logs?

---

<div class="post-metadata">

### Author: ![itsbhanusharma](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/itsbhanusharma/32/180717_2.png) [@itsbhanusharma](https://meta.discourse.org/u/itsbhanusharma)
#### Post date: [February 21, 2022, 8:03am UTC](https://meta.discourse.org/t/latest-wp-discourse-update-is-causing-some-unexpected-behaviour/218884/3 "2022-02-21T08:03:01Z")

</div>

Hi @angus

Here is the plugin: [https://www.myeventon.com/](https://www.myeventon.com/)

Do you need logs from v2.3.7 or v2.3.8 of the plugin?

---

<div class="post-metadata">

### Author: ![angus](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/angus/32/341715_2.png) [@angus](https://meta.discourse.org/u/angus)
#### Post date: [February 21, 2022, 8:03am UTC](https://meta.discourse.org/t/latest-wp-discourse-update-is-causing-some-unexpected-behaviour/218884/4 "2022-02-21T08:03:52Z")

</div>

Both if possible. Please turn on Verbose Publication Logs.

---

<div class="post-metadata">

### Author: ![itsbhanusharma](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/itsbhanusharma/32/180717_2.png) [@itsbhanusharma](https://meta.discourse.org/u/itsbhanusharma)
#### Post date: [February 21, 2022, 8:11am UTC](https://meta.discourse.org/t/latest-wp-discourse-update-is-causing-some-unexpected-behaviour/218884/5 "2022-02-21T08:11:33Z")

</div>

v2.3.7:

```plaintext
[2022-02-21 08:07:11] publish.INFO: create_post.post_success {"wp_title":"[Please Ignore] Test Event","wp_author_id":"3958","wp_post_id":126070,"discourse_post_id":""} 
[2022-02-21 08:07:11] publish.INFO: create_post.body_valid {"wp_title":"[Please Ignore] Test Event","wp_author_id":"3958","wp_post_id":126070,"discourse_post_id":""} 

```

The post was correctly linked to my user account on both wordpress and discourse with 2.3.7

v2.3.8:

```plaintext
[2022-02-21 08:10:15] publish.INFO: create_post.post_success {"wp_title":"[Please Ignore] Another test event","wp_author_id":"3958","wp_post_id":126071,"discourse_post_id":""} 
[2022-02-21 08:10:15] publish.INFO: create_post.body_valid {"wp_title":"[Please Ignore] Another test event","wp_author_id":"3958","wp_post_id":126071,"discourse_post_id":""} 

```

The post was linked to my user on wordpress and system user on discourse on 2.3.8

---

<div class="post-metadata">

### Author: ![angus](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/angus/32/341715_2.png) [@angus](https://meta.discourse.org/u/angus)
#### Post date: [February 21, 2022, 11:44am UTC](https://meta.discourse.org/t/latest-wp-discourse-update-is-causing-some-unexpected-behaviour/218884/6 "2022-02-21T11:44:44Z")

</div>

Can you just confirm a few things for me

1. Your custom post types (i.e. the events) are being published to Discourse successfully
2. You haven’t see the 400 error before
3. What type of users (whose discourse usernames you’re expecting to be used) are publishing posts (i.e. are they admins or not)
4. What type of API key are you’re using to connect Wordpress to Discourse

---

<div class="post-metadata">

### Author: ![itsbhanusharma](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/itsbhanusharma/32/180717_2.png) [@itsbhanusharma](https://meta.discourse.org/u/itsbhanusharma)
#### Post date: [February 21, 2022, 1:10pm UTC](https://meta.discourse.org/t/latest-wp-discourse-update-is-causing-some-unexpected-behaviour/218884/7 "2022-02-21T13:10:02Z")

</div>

> [@angus](#):
>
> Your custom post types (i.e. the events) are being published to Discourse successfully

Yes, the posts are being published successfully but incorrect user (system) is being attributed with v2.3.8

> [@angus](#):
>
> You haven’t see the 400 error before

No, We haven’t see any 400 errors on any prior versions of wp-discourse plugin.

> [@angus](#):
>
> What type of users (whose discourse usernames you’re expecting to be used) are publishing posts (i.e. are they admins or not)

These users are non-admin registered users on wordpress and so far it has worked for us. any users were correctly linked on discourse.

> [@angus](#):
>
> What type of API key are you’re using to connect Wordpress to Discourse

It is a Global API key

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

---

<div class="post-metadata">

### Author: ![angus](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/angus/32/341715_2.png) [@angus](https://meta.discourse.org/u/angus)
#### Post date: [February 21, 2022, 2:24pm UTC](https://meta.discourse.org/t/latest-wp-discourse-update-is-causing-some-unexpected-behaviour/218884/8 "2022-02-21T14:24:43Z")

</div>

When this PR is merged (and the version pushed to [Wordpress.org](http://Wordpress.org)), the functionality will work as you expect it to.

[https://github.com/discourse/wp-discourse/pull/437](https://github.com/discourse/wp-discourse/pull/437)

---

<div class="post-metadata">

### Author: ![Thiago\_Mobilon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/thiago_mobilon/32/177756_2.png) [@Thiago\_Mobilon](https://meta.discourse.org/u/Thiago_Mobilon)
#### Post date: [February 21, 2022, 10:49pm UTC](https://meta.discourse.org/t/latest-wp-discourse-update-is-causing-some-unexpected-behaviour/218884/9 "2022-02-21T22:49:02Z")

</div>

I’m experiencing the same error, and can confirm that it started after upgrading [WP Discourse](https://github.com/discourse/wp-discourse) to the version 2.3.8.

With this version, topics are created, but with the default user.

To confirm, i rolled back [WP Discourse](https://github.com/discourse/wp-discourse) to 2.3.7, and it’s working again.

---

<div class="post-metadata">

### Author: ![angus](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/angus/32/341715_2.png) [@angus](https://meta.discourse.org/u/angus)
#### Post date: [February 22, 2022, 6:36am UTC](https://meta.discourse.org/t/latest-wp-discourse-update-is-causing-some-unexpected-behaviour/218884/10 "2022-02-22T06:36:44Z")

</div>

Thanks, it will be addressed when [the PR](https://github.com/discourse/wp-discourse/pull/437) is merged. Could you just confirm these two questions as well

> - What type of users (whose discourse usernames you’re expecting to be used) are publishing posts (i.e. are they admins or not)
> - What type of API key are you’re using to connect Wordpress to Discourse

---

<div class="post-metadata">

### Author: ![jtbayly](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jtbayly/32/119510_2.png) [@jtbayly](https://meta.discourse.org/u/jtbayly)
#### Post date: [February 22, 2022, 1:42pm UTC](https://meta.discourse.org/t/latest-wp-discourse-update-is-causing-some-unexpected-behaviour/218884/11 "2022-02-22T13:42:05Z")

</div>

Same problem here. Not a custom post type.

not an admin user, but a moderator  
An “all users” api key.

---

<div class="post-metadata">

### Author: ![Thiago\_Mobilon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/thiago_mobilon/32/177756_2.png) [@Thiago\_Mobilon](https://meta.discourse.org/u/Thiago_Mobilon)
#### Post date: [February 22, 2022, 4:01pm UTC](https://meta.discourse.org/t/latest-wp-discourse-update-is-causing-some-unexpected-behaviour/218884/12 "2022-02-22T16:01:52Z")

</div>

- Users are moderators and some admins
- API “All Users”

---

<div class="post-metadata">

### Author: ![angus](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/angus/32/341715_2.png) [@angus](https://meta.discourse.org/u/angus)
#### Post date: [February 22, 2022, 7:13pm UTC](https://meta.discourse.org/t/latest-wp-discourse-update-is-causing-some-unexpected-behaviour/218884/13 "2022-02-22T19:13:48Z")

</div>

Hey guys, version 2.3.9 is now live with a fix for this issue. Please update and let me know how you go.

---

<div class="post-metadata">

### Author: ![orenwolf](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/orenwolf/32/119529_2.png) [@orenwolf](https://meta.discourse.org/u/orenwolf)
#### Post date: [February 23, 2022, 4:29pm UTC](https://meta.discourse.org/t/latest-wp-discourse-update-is-causing-some-unexpected-behaviour/218884/14 "2022-02-23T16:29:45Z")

</div>

We are seeing the same issue with 2.3.9, and are rolling back to 2.3.7, and disabling auto-update of this plugin going forward.

---

<div class="post-metadata">

### Author: ![itsbhanusharma](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/itsbhanusharma/32/180717_2.png) [@itsbhanusharma](https://meta.discourse.org/u/itsbhanusharma)
#### Post date: [February 23, 2022, 4:36pm UTC](https://meta.discourse.org/t/latest-wp-discourse-update-is-causing-some-unexpected-behaviour/218884/15 "2022-02-23T16:36:02Z")

</div>

Hi @angus

Sorry for the noise, My issue seems to have been fixed on WordPress 5.9.1 & [WP Discourse](https://github.com/discourse/wp-discourse) 2.3.9

But, it seems like discourse is now doing some extra work on each published post and the ownership is being transferred from System user to the publishing user after the fact?

---

<div class="post-metadata">

### Author: ![angus](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/angus/32/341715_2.png) [@angus](https://meta.discourse.org/u/angus)
#### Post date: [February 23, 2022, 5:40pm UTC](https://meta.discourse.org/t/latest-wp-discourse-update-is-causing-some-unexpected-behaviour/218884/16 "2022-02-23T17:40:16Z")

</div>

Hey @orenwolf, I’m sorry to hear you’re still having an issue. Could you confirm that the users you’re expecting to be publishing under their own name have a `Discourse Username` in their Wordpress profile?

* * *

Generally guys, thanks for your patience on this. On my own testing on various sites (and in the plugin’s own unit tests), the `Discourse Username` feature is now functioning as expected on `2.3.9`. If you’re still having an issue please confirm you’re on the latest version of the plugin and that the user you’re expecting to be the author of the post has a `Discourse Username`.

You might be wondering why this issue arose at all. I think it’ll be helpful if I give a bit of background (which will also answer your question @itsbhanusharma). Previously, the way this feature worked is that it used different users in the `Api-Username` header ([see here](https://docs.discourse.org/)). The reason this was seen as necessary was because the relevant endpoint in Discourse does not support setting a creator of the post different from the user performing the API request.

The upshot of this was that the only way this feature would work is if you have a “All Users” API key with a “Global” scope. I’ll just note that for some time the standard instructions for creating an API key for the [WP Discourse](https://github.com/discourse/wp-discourse) plugin are as follows

> If you haven’t yet created an API key, Click ‘New API Key’, set User Level to ‘Single User’, set ‘User’ to an admin account, select ‘Global Key’ and click ‘Save’. Copy and paste the API key here.

Following these instructions would mean that this (undocumented) feature would not work, and it has caused issues for various sites.

Moreover, for various security reasons, I’ve progressively been making changes to the plugin to allow for much more specific API keys to be used. This will require a change to Discourse, and (when it gets merged) will allow plugin admins to issue themselves a new, much more limited, API key. I’ll be making an announcement about that when the time comes.

[https://github.com/discourse/discourse/pull/15366](https://github.com/discourse/discourse/pull/15366)

Yes @itsbhanusharma the way the feature now works is by making a second request to change the owner of the post after it is created (if a `Discourse Username` is present). That is actually currently the only proper way to arbitrarily set the owner of a post via the Discourse API (without needing to use the Api-Username and an All Users Global Key in the way described above). Considering the type of operation this is, this should not be a performance concern.

---

<div class="post-metadata">

### Author: ![itsbhanusharma](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/itsbhanusharma/32/180717_2.png) [@itsbhanusharma](https://meta.discourse.org/u/itsbhanusharma)
#### Post date: [February 23, 2022, 7:58pm UTC](https://meta.discourse.org/t/latest-wp-discourse-update-is-causing-some-unexpected-behaviour/218884/17 "2022-02-23T19:58:17Z")

</div>

> [@angus](#):
>
> Considering the type of operation this is, this should not be a performance concern.

It’s not a performance concern, just a nuisance to explain less savvy people that the pencil icon on top of their post is normal and that’s how It’s going to be.

It’ll take some time but eventually we’ll get used to it.

---

<div class="post-metadata">

### Author: ![jtbayly](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jtbayly/32/119510_2.png) [@jtbayly](https://meta.discourse.org/u/jtbayly)
#### Post date: [February 24, 2022, 11:34am UTC](https://meta.discourse.org/t/latest-wp-discourse-update-is-causing-some-unexpected-behaviour/218884/18 "2022-02-24T11:34:19Z")

</div>

It is somewhat offputting that posts are shown as edited, but that’s fine as long as everything works.

However, it’s a problem that notifications are wrong. They show the new post being created by the system user.

So far this just feels like a hack, not a solution. It’s certainly a big step backwards to not be able to simply post as the proper user automatically. I’m not sure I understand what caused this to break in the first place.

---

<div class="post-metadata">

### Author: ![angus](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/angus/32/341715_2.png) [@angus](https://meta.discourse.org/u/angus)
#### Post date: [February 24, 2022, 12:44pm UTC](https://meta.discourse.org/t/latest-wp-discourse-update-is-causing-some-unexpected-behaviour/218884/19 "2022-02-24T12:44:22Z")

</div>

The short version is that I’ve been slowly changing the way the plugin handles all of its requests to discourse for various reasons, particularly testing and security. The full context and rationale for the changes is too long to get into here. I appreciate that in the context of this particular feature it may feel like “if it ain’t broke don’t fix it”, however there’s a broader context here.

These changes have been going on for some time (months), however the reason they’re coming to the surface now is because I made a mistake in the `2.3.8` release. So I included the change that should have been in that release in `2.3.9`.

That said, @jtbayly @itsbhanusharma I hear your feedback on the different approach to this particular feature. I understand it may feel like a hack. It’s not. Nevertheless, given your feedback, I’m going to add the existing way back in to the plugin behind a setting you can use if you wish (it will go live in `2.4.0`). I’ll follow up with note when that’s merged in the next few days.

I hope to be able to remove this approach entirely when I’ve addressed the issues you’ve both raised, most likely with some further changes to `discourse/discourse`. As mentioned, I’m going to be making a larger announcement about changes to how the plugin handles API keys within the next month (depending on when changes get merged to `discourse/discourse`), which will cover aspects of this.

---

<div class="post-metadata">

### Author: ![jtbayly](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jtbayly/32/119510_2.png) [@jtbayly](https://meta.discourse.org/u/jtbayly)
#### Post date: [February 24, 2022, 1:15pm UTC](https://meta.discourse.org/t/latest-wp-discourse-update-is-causing-some-unexpected-behaviour/218884/20 "2022-02-24T13:15:46Z")

</div>

> [@jtbayly](#):
>
> I’m not sure I understand what caused this to break in the first place.

When I said this it was meant to acknowledge that I wasn’t sure if there _was_ any other way forward. Wasn’t meant to be a “why’d you go and break it!” comment.

Very thankful for your work keeping the WP plug-in working with an updated core Discourse. And very happy there are (likely) coming changes to core that will allow for improvement in this area.

[Next page](https://meta.discourse.org/t/latest-wp-discourse-update-is-causing-some-unexpected-behaviour/218884.md?page=2)
