"There has been an error publishing this post to Discourse."

The publishing worked 1 time. Since then I am getting this “There has been an error publishing this post to Discourse.” in Wordpress when trying to update a post with the publish to Discourse box checked.
I have wordpress 4.9.1, Discourse plugin 1.5.5 (it didn’t work on 1.5.4 either) and latest Discourse installed.

I looked at the log as suggested in another post, i get something like that when trying to publish:
[27/Dec/2017:21:46:51 +0000] “chat.example.com” 172.131.131.131 “POST /posts HTTP/1.1” “WordPress/4.9.1; https://www.example.com” “-” 403 459 “https://chat.example.com/posts” 0.059 0.063 “-”

It seems alright to me…

What else can I do?

Have you set your Discourse username on your WordPress profile page? It needs to match the username that’s used on your Discourse account. That is the most likely cause of the 403 error you are getting. I meant to update the error message for when a 403 error is returned, but forgot to add that to the last update of the plugin.

If you enable the Send Email Notification on Publish Failure setting (found on the wp-discourse Publishing settings tab) you will be emailed a fairly detailed error message if a post fails to publish.

2 Likes

Thanks, the username was the issue. But I still have a problem that the comments are not synced even though i created the hook, verified that it is active and has post_event and that the secret key is the same.

Have you also enabled the hook on WordPress? Do you see any errors when you go to the webhook events list on Discourse? You can access that list by clicking on the Go to events button at the bottom of the webhook edit page.

If it is working properly, comments will not be synced until a new comment is added, or a comment is edited on Discourse.

I see proper events on Discourse event list. I updated a comment and immediately got a new event.
it returned answer:

Date: Wed, 27 Dec 2017 22:19:36 GMT
X-Robots-Tag: noindex
X-Content-Type-Options: nosniff
Access-Control-Expose-Headers: X-WP-Total, X-WP-TotalPages
Access-Control-Allow-Headers: Authorization, Content-Type
Allow: POST
Cache-Control: max-age=0
Expires: Wed, 27 Dec 2017 22:19:36 GMT
Vary: User-Agent,Accept-Encoding
Content-Type: application/json; charset=UTF-8
X-Varnish: 55942185
Age: 0
X-Cache: MISS
Accept-Ranges: bytes
Connection: close

Also, the meta field wpdc_sync_post_comments of the post is 0 even though there is one comment to the post

When you click on the Request tab for the event, is it Posting to the correct URL? What is the Status Code for the event?

The Request URL look ok. But the X-Discourse-Instance is not, it is http instead of https. does it matter?

Request URL: https://www.example.com/wp-json/wp-discourse/v1/update-topic-content
Request method: POST
Accept: */*
Connection: close
Content-Length: 1156
Content-Type: application/json
Host: www.example.com
User-Agent: Discourse/1.9.0.beta17
X-Discourse-Instance: http://chat.example.com
X-Discourse-Event-Id: 32
X-Discourse-Event-Type: post
X-Discourse-Event: post_edited
X-Discourse-Event-Signature: sha256=

I enabled force https in Discourse, it fixes the url in X-Discourse-Instance but does not solve the sync problem

What is the status code for the event?

all of them are with code 200

1 Like

If this is a post that you previously published to another Discourse instance, the topic’s post won’t be found on WordPress. I don’t know if that could be the problem. You could try enabling the wp-discourse Webhook setting ‘Match Old Topics.’ It attempts to match posts to topics by the post title.

No, it is new.
when i check the raw comment data on wordpress meta fields i see:

{"id":22,"posts_count":1,"filtered_posts_count":1,"posts":[],"participants":[{"id":1,"username":"gerald","avatar_template":"https://chat.example.com/user_avatar/chat.example.com/gerald/{size}/7_1.png"}]}

But the comment text itself does not appear

Maybe this will give a clue, it is the request from events and it says post number = null:

{
  "post": {
    "id": 31,
    "name": null,
    "username": "gerald",
    "avatar_template": "/user_avatar/chat.example.com/gerald/{size}/7_1.png",
    "created_at": "2017-12-27T22:42:02.696Z",
    "cooked": "<p>this is a test comment.</p>",
    "post_number": 2,
    "post_type": 1,
    "updated_at": "2017-12-27T22:42:02.696Z",
    "reply_count": 0,
    **"reply_to_post_number": null,**
    "quote_count": 0,
    "avg_time": null,
    "incoming_link_count": 0,
    "reads": 1,
    "score": 0,
    "yours": false,
    "topic_id": 22,
    "topic_slug": "myslug",
    "topic_title": "my wordpress post title",
    "display_username": null,
    "primary_group_name": null,
    "primary_group_flair_url": null,
    "primary_group_flair_bg_color": null,
    "primary_group_flair_color": null,
    "version": 1,
    "user_title": null,
    "actions_summary": [
      {
        "id": 2,
        "can_act": true
      },
      {
        "id": 5,
        "hidden": true,
        "can_act": true
      },
      {
        "id": 3,
        "can_act": true
      },
      {
        "id": 4,
        "can_act": true
      },
      {
        "id": 8,
        "can_act": true
      },
      {
        "id": 6,
        "can_act": true
      },
      {
        "id": 7,
        "can_act": true
      }
    ],
    "moderator": false,
    "admin": true,
    "staff": true,
    "user_id": 1,
    "hidden": false,
    "hidden_reason_id": null,
    "trust_level": 0,
    "deleted_at": null,
    "user_deleted": false,
    "edit_reason": null,
    "can_view_edit_history": true,
    "wiki": false
  }

From looking at your forum/website it seems that you are using a link shortening service. I’m wondering if the redirects that it is making could be causing a problem with either the webhook request or the request that WordPress makes to Discourse to fetch the comment data.

1 Like

I removed the shortening and also removed cache but comments do not appear on wordpress :frowning:
Is there anything else i can do?
*btw - when enabling “ajax” comments, it overrides the “old commend system” setting so that old comments are always hidden if using ajax

Could you try disabling the Sync Comment Data option on the Webhooks tab and see if that makes a difference? There are a couple of things that could be going wrong with updating the comments with a webhook.

When the webhook is not enabled, comments are cached for 10 minutes. For testing purposes, you can change that time period in your theme’s functions.php file with some code like this:

add_filter( 'wpdc_comment_sync_period', 'wpdc_custom_comment_sync_period' );
function wpdc_custom_comment_sync_period() {

    return 0;
}

Thanks for the feedback on that. Loading comments with javascript is an undocumented feature at this point. I’m going to make a few changes to it later this week.

4 Likes

It didn’t change anything when I turned the Sync off.
It is worth noting that looking at the wordpress meta data, at least some fields are correct:
discourse_comments_count shows the correct number of comments
discourse_permalink shows correct url
Perhaps also worth noting, that before the self hosted Discourse, i did the hosted Discourse trial and then comments synced very well both with and without ajax