Skip to content

Commit d055158

Browse files
committed
fix: scheduled post sometimes not being published
1 parent e031a01 commit d055158

2 files changed

Lines changed: 18 additions & 1 deletion

File tree

includes/admin/class-rop-admin.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -878,6 +878,22 @@ public function publish_now_attributes( $default ) {
878878
return $default;
879879
}
880880

881+
/**
882+
* Handles the transition of post status from 'future' to 'publish'.
883+
* Triggers the "publish now" functionality when a scheduled post is published.
884+
*
885+
* @param string $new_status The new status of the post.
886+
* @param string $old_status The previous status of the post.
887+
* @param WP_Post $post The post object.
888+
*/
889+
public function transition_post_status( $new_status, $old_status, $post ) {
890+
if ( $old_status !== 'future' || $new_status !== 'publish' ) {
891+
return;
892+
}
893+
894+
$this->maybe_publish_now( $post->ID, true );
895+
}
896+
881897
/**
882898
* Publish now, if enabled.
883899
*
@@ -905,7 +921,7 @@ public function maybe_publish_now( $post_id, $force = false ) {
905921
return;
906922
}
907923

908-
if ( ! current_user_can( 'edit_post', $post_id ) ) {
924+
if ( ! wp_doing_cron() && ! current_user_can( 'edit_post', $post_id ) ) {
909925
return;
910926
}
911927

includes/class-rop.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ function ( $message ) {
165165

166166
$this->loader->add_action( 'add_meta_boxes', $plugin_admin, 'rop_publish_now_metabox' );
167167
$this->loader->add_action( 'wp_after_insert_post', $plugin_admin, 'maybe_publish_now' );
168+
$this->loader->add_action( 'transition_post_status', $plugin_admin, 'transition_post_status', 10, 3 );
168169
$this->loader->add_action( 'rop_publish_now_instant_share', $plugin_admin, 'maybe_publish_now', 10, 2 );
169170
$this->loader->add_filter( 'rop_publish_now_attributes', $plugin_admin, 'publish_now_attributes' );
170171

0 commit comments

Comments
 (0)