WP-Discourse > 'Publish all new posts to Discourse.' > not working

I have set up WP-Discourse according to the instructions, with WP and Discourse on separate hosts.

Issue

I have activated the ‘Publish all new posts to Discourse’ setting, but when I visit posts, the ‘Publish post to Discourse’ checkbox is unchecked, and no discourse topic has been created. On the front-end, there is no comment-related message, it’s empty.
###Workaround
In order to get a single post to work, I need to manually check ‘Publish post to Discourse’ and check ‘Allow comments’ on the post. Once I check those two and update the page, then the topic is created on discourse (see my connection is fine) and the message “Discuss this post at forum.mysite.com” appears on the bottom of the post.
This is the desired behavior, but I want it to happen for all posts at the time of publishing.
###Questions

  • What settings should be set in Settings > Discussion ? Current settings:
  • If I have ‘Publish all new posts to Discourse’ checked and it’s not working, how can I debug this feature? Should I be looking for anything in particular in WP or Discourse logs?
  • Can’t it just work? Why does life have to be so hard? Is it because I am a sinner?

###Possibly related topic
https://meta.discourse.org/t/wp-discourse-dysfunctional-shows-only-start-the-discussion-at/36016

What version of the wp-discourse plugin do you have installed? Are you publishing posts through XMLRPC - for example, through the WordPress.com app? If so, they won’t be published automatically to Discourse, but it is possible to add that functionality by adding a line of code to your functions.php file.

3 Likes

It is version 1.2.5, which should be the most current version.

I’m not sure. I do have Jetpack installed. And I am using a syndication plugin to create posts from RSS feeds. So that might be using XMLRPC. I’ll try to check.

What would I add to functions.php? I can test it out to see if it fixes it.

This appears to be a relevant example:

https://github.com/discourse/wp-discourse/issues/133

When you’re creating a post, does it look something like this? (wp-admin)

or like this? (wordpress.com app)

If it’s the latter, you will need to add some code to get it to work.

It’s the first one, regular wordpress dashboard.
But as I mentioned in an update to the above post, I am using a syndication plugin to feed RSS to make posts automatically. So maybe it skips the wp-discourse hooks for some reason?

1 Like

Yes, that sounds like the problem. When you go directly to the WordPress dashboard, is the Publish Post to Discourse checkbox checked?

What’s the syndication plugin that you’re using?

2 Likes

When I go to a post edit page, that checkbox is unchecked.
If I check it manually (and check allow comments), then everything works as expected.

This one:

It has a comprehensive support page here: http://feedwordpress.radgeek.com/

Weird. Do you have this setting enabled on the wp-discourse Publishing settings tab?

1 Like

Yes I do. Yes weird.

‘Auto Track Published Topics’ is not checked, does it need to be?

No, that shouldn’t make a difference.

I will try to insert some diagnostic code, and run tests to generate useful logs.
Once I get those I’ll post them here.
If you have any other ideas, let me know.
Thanks!

1 Like

I’ve tried it out and can confirm that it doesn’t publish automatically to Discourse. Possibly the easiest way to get it working would be if the FeedWordPress plugin has an action hook that is fired when the post is published.

1 Like

It’s actually fairly simple to get this working. I’ve added a wpdc_publish_after_save filter to the wp-discourse publish_post_after_save function that you can hook into. It’s passed the variables $force_publish, $post_id, and $post. It’s not yet merged into the main code, but you can get it here: https://github.com/scossar/wp-discourse/tree/beta-after-save-filter.

Something like this added to your theme’s functions.php file will auto publish all posts from an array of feeds. There are some issues with the way images are being lightboxed on Discourse if they are passed a srcset attribute, and something should probably be done to get the author’s name to the top of the post.

add_filter( 'wpdc_publish_after_save', 'testeleven_publish_feed', 10, 3 );
// $post isn't used here, but it's available if you need it.
function testeleven_publish_feed( $force_publish, $post_id, $post ) {
    // The sources you want to publish from.
    $syndication_sources = array(
            'https://scossar.com',
    );
    $feed_uri = get_post_meta( $post_id, 'syndication_source_uri', true );

    if ( $feed_uri && in_array( $feed_uri, $syndication_sources, true) ) {
        // This isn't necessary, but it will cause the 'publish to Discourse' checkbox to be checked
        // if you edit the post later.
        add_post_meta( $post_id, 'publish_to_discourse', 1 );
        // Use for force the post to automatically publish to Discourse.
        $force_publish = true;
    }

    return $force_publish;
}
5 Likes

You are amazing!
I’m going to try this out later today.
Thanks!!!

No problem, it looks like something that could be useful.

I’m not sure what will happen if many RSS posts are synced at the same time. I’ve tried with three at once in my local development environment, and it worked fine.

To get the ‘Continue the Discussion’ link to display at the bottom of the post, you need to select the syndication setting ‘Allow comments on syndicated posts’.

If you install wp-discourse from the repo I linked to in the above post, you should rename the root folder to ‘wp-discourse’ from ‘wp-discourse-beta-after-save-filter’ to avoid confusion when the next plugin update becomes available through the WordPress plugin repo.

1 Like

Quick update.

Instead of the theme, I am modifying the syndication plugin (FeedWordpress), inserting meta at appropriate places.

Results are inconsistent. Sometimes it works, sometimes the page needs to be reloaded a couple times before it takes. But in principle it’s definitely doable.

Simon, what if I wanted to force the Discourse topic? It doesn’t seem to pickup the WP-Discourse default topic and always wants to publish to Uncategorized in Discourse. Any quick change I could make to force the topic of my choice?

Many thanks,
Mac

I’m not sure I’m understanding your question. Is it failing to publish to the category that you have set it to publish to? For example, you have the post set to publish like this, but it is being published to the uncategorized category?

Edit: I should have read the posts in this topic before answering. Are you using the ‘testeleven_publish_feed’ code from my previous post? If so, you can probably use the ‘Force Publish’ option from the plugin’s Publishing tab to accomplish the same thing. If you are using that and it’s not publishing to the correct category, please let me know.

2 Likes

Yep, I’m using the testeleven. Instead of publishing to the default category I have set on the plugins Publishing tab, it goes to uncategorized.

I changed Discourse to not allow uncategorized just to see what would happen. In this scenario the posts don’t make it to Discourse.

I poked around to see if I could figure how to hardcode the category with no success. That would be fine as well.

Regards,
Mac

To hardcode it you would add:

update_post_meta( $post_id, 'publish_post_category', $your_discourse_category_id );

WIth $your_discourse_category_id set to the Discourse category_id that you wish to publish to. But you shouldn’t have to do that. It should publish automatically to the default category that you have set on the Publishing tab. I’ll look at this some more.

Probably the easiest way to find the Discourse category_id is to go to your.forum.com/site.json and search for the categories array.

3 Likes