Automattic\WooCommerce\Internal\ProductDownloads\ApprovedDirectories\Admin

UI::process_bulk_actions()privateWC 1.0

Processes actions that can be applied in bulk (requests to delete, enable or disable).

Method of the class: UI{}

No Hooks.

Return

null. Nothing.

Usage

// private - for code of main (parent) class only
$result = $this->process_bulk_actions( $ids, $action );
$ids(int[]) (required)
The ID(s) to be updates.
$action(string) (required)
The action to be applied.

UI::process_bulk_actions() code WC 7.1.0

private function process_bulk_actions( array $ids, string $action ) {
	$deletes  = 0;
	$enabled  = 0;
	$disabled = 0;
	$register = wc_get_container()->get( Register::class );

	foreach ( $ids as $id ) {
		if ( 'delete' === $action && $register->delete_by_id( $id ) ) {
			$deletes++;
		} elseif ( 'enable' === $action && $register->enable_by_id( $id ) ) {
			$enabled++;
		} elseif ( 'disable' === $action && $register->disable_by_id( $id ) ) {
			$disabled ++;
		}
	}

	$fails    = count( $ids ) - $deletes - $enabled - $disabled;
	$redirect = $this->table->get_base_url();

	if ( $deletes ) {
		$redirect = add_query_arg( 'deleted-ids', $deletes, $redirect );
	} elseif ( $enabled ) {
		$redirect = add_query_arg( 'enabled-ids', $enabled, $redirect );
	} elseif ( $disabled ) {
		$redirect = add_query_arg( 'disabled-ids', $disabled, $redirect );
	}

	if ( $fails ) {
		$redirect = add_query_arg( 'bulk-fails', $fails, $redirect );
	}

	wp_safe_redirect( $redirect );
	exit;
}