diff --git a/includes/class-main.php b/includes/class-main.php index 8a27bbcdb0ba91899a6e2fab2f4cc352e9c01626..0134ae8b72a7920e7bf66ee2f9f8f0a7e9eebe1b 100644 --- a/includes/class-main.php +++ b/includes/class-main.php @@ -220,6 +220,15 @@ class Main { public static function schedule_processing( $vars ) { return false !== wp_schedule_single_event( time(), self::CRON_EVENT, array( $vars ) ); } + + /** + * + * @param object $vars Bulk-request variables. + * @return int + */ + public static function next_scheduled( $vars ) { + return (int) wp_next_scheduled( self::CRON_EVENT, array( $vars ) ); + } } Main::load(); diff --git a/includes/class-move-to-trash.php b/includes/class-move-to-trash.php index 3b880f86e9197353e7eb7ea0a44e1bbe28f6d66b..cf65dccc9d5c835b344f974cf8b692b23517fa7a 100644 --- a/includes/class-move-to-trash.php +++ b/includes/class-move-to-trash.php @@ -32,8 +32,14 @@ class Move_To_Trash { * @param object $vars Bulk-request variables. */ public static function process( $vars ) { - Main::schedule_processing( $vars ); - Main::do_admin_redirect( self::ADMIN_NOTICE_KEY, true ); + $action_scheduled = Main::next_scheduled( $vars ); + + if ( empty( $action_scheduled ) ) { + Main::schedule_processing( $vars ); + Main::do_admin_redirect( self::ADMIN_NOTICE_KEY, true ); + } else { + Main::do_admin_redirect( self::ADMIN_NOTICE_KEY, false ); + } } /** @@ -99,11 +105,11 @@ class Move_To_Trash { $message = __( 'Success! The selected posts will be moved to the trash shortly.', 'bulk-edit-cron-offload' ); } else { $class = 'notice-error'; - $message = __( 'An unknown error occurred.', 'bulk-edit-cron-offload' ); + $message = __( 'The selected posts are already scheduled to be moved to the trash.', 'bulk-edit-cron-offload' ); } } - // TODO: show a notice if any move requests are pending for this post type ($screen->post_type). + // TODO: show a notice if _any_ move requests are pending for this post type ($screen->post_type). // Nothing to display. if ( ! isset( $class ) || ! isset( $message ) ) {