WP Discourse Won't Publish Private Post

I have added a wpdc_publish_private_post filter hook that you can use to publish private posts to Discourse. The filter passes up to two parameters to a function that you hook into it. The parameters are $publish (set to false) and $post_id, the WordPress post id.

If you wish to allow all private posts to be published to Discourse, you can add something like this to a plugin, or your theme’s functions.php file. You can name your hook functions however you choose, just be sure that the name is unique in your site’s codebase.

add_filter( 'wpdc_publish_private_post', 'wpdc_custom_publish_private_post', 10, 2 );
function wpdc_custom_publish_private_post( $publish, $post_id ) {
    if ( 'private' === get_post_status( $post_id ) ) {

        return true;
    }

    return false;
}

If you would only like to allow certain private posts to be published, you’ll need to do something like this:

add_filter( 'wpdc_publish_private_post', 'wpdc_custom_publish_private_post', 10, 2 );
function wpdc_custom_publish_private_post( $publish, $post_id ) {
    $post = get_post( $post_id );
    if ( /* Some condition that checks the $post object */ ) {
        
        return true;
    }
    
    return false;
}

One thing to note is that the ‘Show Full Post’ button on Discourse will not work for private WordPress posts - Discourse can’t retrieve the post’s content. You might want to disable this feature on Discourse by deselecting embed truncate in your Discourse settings.

4 Likes