If you update to WP Discourse Version 1.8.2, you can now pass a $post_id
parameter to the publish_format_html
template. Doing this will make it possible to access the current post when the post is published with the Block Editor, or through the REST API.
Here’s a quick example of how to use it. I’ll add more detailed examples and update WP Discourse template customization very soon.
function wpdc_custom_publish_format_html( $output, $post_id ) {
ob_start();
the_permalink( $post_id );
$output = ob_get_clean();
return $output;
}
add_filter( 'discourse_publish_format_html', 'wpdc_custom_publish_format_html', 10, 2 );
To have access to the $post_id
parameter, you need to be sure to call add_filter
with the priority and accepted_args parameters from the example.
For cases where you are trying to access properties of the current post, instead of using global $post
use
$post = get_post( $post_id );