Request to delay post from wordpress


(David Kingham) #1

I am using the WP Offload Media plugin to send my images to s3 on wordpress, but the images take a minute to move over to s3 when the post is published. The problem is the discourse plugin is immediate so the post gets sent over to discourse with the links to images that are locally hosted, and shortly thereafter the offload plugin sends them to s3, and now the original links are broken in the discourse post. If there was a simple setting to delay the discourse post by say 5 minutes it would resolve this issue.


(Stephen) #2

Doesn’t that plugin include the option to move to S3 from the media library? If so you can get your files into S3 prior to publishing.

Edit: Yes, looks like it does, you can select the images prior to publishing and offload them:

It makes much more sense for you to use existing functionality that achieves the same result, than ask for new features to be developed.


(David Kingham) #3

Thanks Stephen, I reached out to the developers and received this response

The images are sent to S3 as soon as they are uploaded to the Media Library, whether that’s directly with “Add New” or via “Add Media” when editing a post. So while drafting a post any media should be showing S3 URLs.

If that is correct, but when you publish your post it still sends content with local URLs to Discourse, then it’s likely that whatever plugin you’re using for that is not properly processing “the_content” via WP’s filters. The following guide may be of help.
Filtering URLs in Custom Content

Can anyone confirm that the discourse plugin is using the_content?


(David Kingham) #4

Here’s another example of a post I just published, I even tried using the update post feature and it did not change. So it actually doesn’t seem to be related to the plugin or delay at all. For some reason, the discourse plugin is taking the local file url instead of cdn url which is actually in the source code.

If you view the source on this page:
https://naturephotographers.network/articles/finding-order-in-chaos-a-guide-to-photographing-forests/
The first image in post is this:

Wordpress Source

<img class="alignnone size-full wp-image-1248" src="https://npn.sfo2.cdn.digitaloceanspaces.com/wp-content/uploads/20181023131610/GlowingGroveWEB.jpg" alt="GlowingGroveWEB" width="2133" height="1200" srcset="https://npn.sfo2.cdn.digitaloceanspaces.com/wp-content/uploads/20181023131610/GlowingGroveWEB.jpg 2133w, https://npn.sfo2.cdn.digitaloceanspaces.com/wp-content/uploads/20181023131610/GlowingGroveWEB-300x169.jpg 300w, https://npn.sfo2.cdn.digitaloceanspaces.com/wp-content/uploads/20181023131610/GlowingGroveWEB-768x432.jpg 768w, https://npn.sfo2.cdn.digitaloceanspaces.com/wp-content/uploads/20181023131610/GlowingGroveWEB-1024x576.jpg 1024w, https://npn.sfo2.cdn.digitaloceanspaces.com/wp-content/uploads/20181023131610/GlowingGroveWEB-600x338.jpg 600w" sizes="(max-width: 2133px) 100vw, 2133px" />

And the html that was published to discourse was this:

Discourse
<img class="alignnone size-full wp-image-1248" src="https://naturephotographers.network/wp-content/uploads/2018/10/GlowingGroveWEB.jpg" alt="GlowingGroveWEB" width="2133" height="1200" />
 <h4>Focus On A Single Tree</h4>

`


(Stephen) #5

Have you inspected the database to check if your S3 plugin is updating post_content or post_content_filtered?


(Simon Cossar) #6

No, it isn’t. I’ll look into it some more as to whether or not it should be applying that filter. The main problem I see with it is that if shortcodes get parsed there can be a lot of display issues on Discourse.

For the moment, you can apply the filter yourself, or apply the as3cf_filter_post_local_to_s3 filter. You can do this by hooking into the wp_discourse_excerpt filter that the plugin applies to the post content that’s published from WordPress to Discourse. Only try this if you have someway of accessing the backend of your site in case something goes wrong when adding the code. Try one or the other of these code snippets to your theme’s functions.php file.

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

    return apply_filters( 'the_content', $content );
}

(Simon Cossar) #7

With version 1.7.9 of the WP Discourse plugin, if the full post content is published to Discourse, the the_content filter is applied to the content before it is published. This is being done to remove the markup that WordPress adds to posts that are published with the Block Editor.

Let me know if this causes any issues.


(David Kingham) #8

Looks good, only bit of weirdness is the image caption goes to the right of the image rather than below it now.


(Simon Cossar) #9

I can reproduce that If the image doesn’t take up the full width of the post.

Edit: if images on your forum are being lightboxed, a possible solution to this would be to add something like this to your Discourse theme’s CSS:

.lightbox-wrapper {
    display: block;
}

Discourse is displaying .lightbox-wrapper as inline-block. This is why the caption text can appear to the right of the image. I’m not sure if there will be any issues with using display: block instead. I’ll test it out and see.