Fix for your plugin (not sending at publish)
-
Hi there,
after you added the function to stop sending to discord if a post is updated, this plugin didn’t send any post to discord anymore.
So I have checked your code and in the file class-wp-discord-post-post.php I have changed this:On line 84:
// if ( $post_date < current_time( 'timestamp' ) ) {
This didn’t worked because after saving the post, the post_date is always older than the current time stamp.
I added this (line 85):
if ( $this->is_publish === false ) {
So this variable has to be declared (line 17):
private $is_publish = false;
Alwas false. And now how to check if its published or updated (line 21 to 29):
public function __construct() { add_action( 'publish_post', array( $this, 'send_post' ), 10, 2 ); add_action( 'transition_post_status', function ( $new_status, $old_status, $post ) { if ('publish' === $new_status && 'publish' !== $old_status && 'post' === $post->post_type){ $this->is_publish = true; } }, 10, 3 ); }
With the hook ‘transition_post_status’ you can check for status.
Now the plugin is working again. I am not sure if this is the best way but its working. ??
- The topic ‘Fix for your plugin (not sending at publish)’ is closed to new replies.