ActionScheduler_DBStore::bulk_cancel_actions
Bulk cancel actions.
Method of the class: ActionScheduler_DBStore{}
Hooks from the method
Returns
null. Nothing (null).
Usage
// protected - for code of main (parent) or child class $result = $this->bulk_cancel_actions( $query_args );
- $query_args(array) (required)
- Query parameters.
Changelog
| Since 3.0.0 | Introduced. |
ActionScheduler_DBStore::bulk_cancel_actions() ActionScheduler DBStore::bulk cancel actions code WC 10.7.0
protected function bulk_cancel_actions( $query_args ) {
/**
* Global.
*
* @var \wpdb $wpdb
*/
global $wpdb;
if ( ! is_array( $query_args ) ) {
return;
}
// Don't cancel actions that are already canceled.
if ( isset( $query_args['status'] ) && self::STATUS_CANCELED === $query_args['status'] ) {
return;
}
$action_ids = true;
$query_args = wp_parse_args(
$query_args,
array(
'per_page' => 1000,
'status' => self::STATUS_PENDING,
'orderby' => 'none',
)
);
while ( $action_ids ) {
$action_ids = $this->query_actions( $query_args );
if ( empty( $action_ids ) ) {
break;
}
$format = array_fill( 0, count( $action_ids ), '%d' );
$query_in = '(' . implode( ',', $format ) . ')';
$parameters = $action_ids;
array_unshift( $parameters, self::STATUS_CANCELED );
$wpdb->query(
$wpdb->prepare(
"UPDATE {$wpdb->actionscheduler_actions} SET status = %s WHERE action_id IN {$query_in}", // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
$parameters
)
);
do_action( 'action_scheduler_bulk_cancel_actions', $action_ids );
}
}