Images not publishing to Discourse in WP 5.3

I’m guessing this is related to the changes to blocks in the 5.3 update. You can see the post here: In Conversation with Anna Morgan - In Layers: Conversations - Nature Photographers Network

FYI I also have this snippet for CDN images

add_filter( 'wp_discourse_excerpt', 'wpdc_custom_excerpt' );
function wpdc_custom_excerpt( $content ) {
    
    return apply_filters( 'as3cf_filter_post_local_to_s3', $content );
}
3 Likes

I am also getting this error in my dashboard which I’m fairly certain is from the Wordpress plugin.

I came across this post WP Discourse plug in being odd but I am on 1.9.7 and the publishing username is an active account.

I’ll be looking into this today. What I’m seeing on my site is that images published from WordPress are displayed correctly until Discourse attempts to download the remote image. When that is done, I’m ending up with markup like you are getting in the post:

![](upload://kw9YUV5qtquQf5xwatRof6S9RmK.jpeg)

I am not sure if this is related to changes in WordPress 5.3.

If you are getting the We detected an API request using a deprecated authentication method warning, that will not be causing the issue you are having with images. WP Discourse versions 1.9.6 and greater should not be causing that warning. All API requests from the plugin are now using header based authentication.

2 Likes

The problem seems to be that when the Discourse upload markdown is wrapped in HTML tags, the markdown isn’t getting parsed. For example, this is what I’m seeing for a WordPress post after the Discourse PullHotlinkedImages Job is run:

<small>Originally published at:			https://scossar.com/figure-tags-cause-issues/
		</small><br>
<figure class="wp-block-image">![](upload://3hPHOMnM5v5srjlz5QWGmVxY4AL.jpeg)</figure>

Editing the post to remove any html tags that are surrounding the markdown link solves the issue, but a proper solution will need to be found for this.

3 Likes

Sorry to bug, but are you working on this Simon or has someone been assigned to it?

The issue is that when posts with images are published to Discourse, the post’s HTML initially looks something like this:

<figure><img src="https://example.com/wp-content/uploads/your-image.png" /></figure>

If the download remote images to local site setting is enabled on Discourse, the image link will break when Discourse downloads the post from WordPress. The problem will happen any time an image tag with a remote URL is wrapped with HTML tags.

The easiest solutions for this issue are to either disable the download remote images to local site setting, or to not publish full post content from WordPress to Discourse.

In the future, the WP Discourse plugin may remove the option to publish full posts. There are multiple issues that can occurr when publishing full post content from WordPress to Discourse. Most of these issues should be able to be solved by publishing excerpts from WordPress to Discourse and then using the Show Full Post button to display the full post on Discourse. Does this sound like something that could work for your case?

Another possible solution would be to customize the template that is used to publish WordPress posts. Images could be extracted from the posts and then published along with a post excerpt. With a custom template, the image HTML could be structured in a way that doesn’t conflict with the Discourse markdown processor.

Thanks Simon, download remote images to local was the easy solution for now. I am discouraged to hear that publish full posts may go away. The way I currently use it is by publishing a post to wordpress, which then gets published to the Articles section on discourse, which is set to Watching First Post for everyone by default. This way everyone gets an email with the full content of the article, and the best part is they can just reply to the email to add a comment, if they have to take that extra step of visiting the site it’s likely most won’t read the article if there’s just a little snippet, especially if it doesn’t have images which is really important for our site. If publish full posts went away I may consider going away from wordpress and only publish the articles directly in discourse which is not ideal for SEO, etc. but I think the engagement is more important.

1 Like