WordPress at Your Fingertips
function is not described

ActionScheduler_DBStore::bulk_cancel_actions() protected WC 3.0.0

Bulk cancel actions.

{} It's a method of the class: ActionScheduler_DBStore{}

Hooks from the method

Return

null. Nothing.

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.

Code of ActionScheduler_DBStore::bulk_cancel_actions() WC 6.1.1

protected function bulk_cancel_actions( $query_args ) {
	/** @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'  => 'action_id',
		)
	);

	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 );
	}
}