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;
}