diff --git a/includes/class-delete-all.php b/includes/class-delete-all.php index 2f1da5efef33b27f64d6f32507e44afda89ca784..b9721201a039caae3c685d6746e06a3fb3efcdf5 100644 --- a/includes/class-delete-all.php +++ b/includes/class-delete-all.php @@ -43,7 +43,7 @@ class Delete_All { // Special keys are used to trigger this request, and we need to remove them on redirect. $extra_keys = array( self::ACTION, self::ACTION . '2' ); - $action_scheduled = self::action_next_scheduled( $vars->post_type ); + $action_scheduled = Main::get_action_next_scheduled( self::ACTION, $vars->post_type ); if ( empty( $action_scheduled ) ) { Main::schedule_processing( $vars ); @@ -126,7 +126,7 @@ class Delete_All { $message = __( 'A request to empty the trash is already pending for this post type.', 'bulk-edit-cron-offload' ); } } elseif ( 'edit' === $screen->base && isset( $_REQUEST['post_status'] ) && 'trash' === $_REQUEST['post_status'] ) { - if ( self::action_next_scheduled( $screen->post_type ) ) { + if ( Main::get_action_next_scheduled( self::ACTION, $screen->post_type ) ) { $type = 'warning'; $message = __( 'A pending request to empty the trash will be processed soon.', 'bulk-edit-cron-offload' ); } @@ -155,7 +155,7 @@ class Delete_All { return $where; } - if ( self::action_next_scheduled( $q->get( 'post_type' ) ) ) { + if ( Main::get_action_next_scheduled( self::ACTION, $q->get( 'post_type' ) ) ) { $where .= ' AND 0=1'; } @@ -189,7 +189,7 @@ class Delete_All { } // There isn't a pending purge, so one should be permitted. - if ( ! self::action_next_scheduled( $screen->post_type ) ) { + if ( ! Main::get_action_next_scheduled( self::ACTION, $screen->post_type ) ) { return $caps; } @@ -198,47 +198,6 @@ class Delete_All { return $caps; } - - /** - * Find the next scheduled instance of a given action, regardless of arguments - * - * @param string $post_type Post type hook is scheduled for. - * @return array - */ - private static function action_next_scheduled( $post_type ) { - $events = get_option( 'cron' ); - - if ( ! is_array( $events ) ) { - return array(); - } - - foreach ( $events as $timestamp => $timestamp_events ) { - // Skip non-event data that Core includes in the option. - if ( ! is_numeric( $timestamp ) ) { - continue; - } - - foreach ( $timestamp_events as $action => $action_instances ) { - if ( Main::CRON_EVENT !== $action ) { - continue; - } - - foreach ( $action_instances as $instance => $instance_args ) { - $vars = array_shift( $instance_args['args'] ); - - if ( self::ACTION === $vars->action && $post_type === $vars->post_type ) { - return array( - 'timestamp' => $timestamp, - 'args' => $vars, - ); - } - } - } - } - - // No matching event found. - return array(); - } } Delete_All::register_hooks(); diff --git a/includes/class-main.php b/includes/class-main.php index e6a0d31e6170a2e80f450772f6625db0f7e2ced9..00b958f26d64ec7b0dcb5739d2ef3ea4849c5507 100644 --- a/includes/class-main.php +++ b/includes/class-main.php @@ -254,6 +254,48 @@ class Main { <?php } + /** + * Find the next scheduled instance of a given action, regardless of arguments + * + * @param string $bulk_action Bulk action to filter by. + * @param string $post_type Post type hook is scheduled for. + * @return array + */ + public static function get_action_next_scheduled( $bulk_action, $post_type ) { + $events = get_option( 'cron' ); + + if ( ! is_array( $events ) ) { + return array(); + } + + foreach ( $events as $timestamp => $timestamp_events ) { + // Skip non-event data that Core includes in the option. + if ( ! is_numeric( $timestamp ) ) { + continue; + } + + foreach ( $timestamp_events as $action => $action_instances ) { + if ( self::CRON_EVENT !== $action ) { + continue; + } + + foreach ( $action_instances as $instance => $instance_args ) { + $vars = array_shift( $instance_args['args'] ); + + if ( $bulk_action === $vars->action && $post_type === $vars->post_type ) { + return array( + 'timestamp' => $timestamp, + 'args' => $vars, + ); + } + } + } + } + + // No matching event found. + return array(); + } + /** * Gather pending events for given conditions *