Automattic\WooCommerce\Internal\BatchProcessing

BatchProcessingController::sanitize_processor_listprivateWC 11.0.0

Reduce a processor list to unique, non-empty class-name strings, preserving order.

The enqueued-processors option is a plain serialized array, so a corrupted option (or the historical duplicate-accumulation bug) can leave it holding duplicates, empty strings, or non-string values. Sanitizing before any comparison keeps the mutators safe and heals the stored list on the next write: in particular array_diff() string-casts its operands and would fatal on an object entry in PHP 8, so removals run on the sanitized list. Empty strings are dropped too: they are never a valid class name, and left in place would be scheduled and then fatal in get_processor_instance( '' ), with the watchdog rescheduling them indefinitely.

Метод класса: BatchProcessingController{}

Хуков нет.

Возвращает

array. Sanitized list of unique class-name strings.

Использование

// private - только в коде основоного (родительского) класса
$result = $this->sanitize_processor_list( $processors ): array;
$processors(массив) (обязательный)
Raw processor list as read from the option.

Список изменений

С версии 11.0.0 Введена.

Код BatchProcessingController::sanitize_processor_list() WC 11.1.1

private function sanitize_processor_list( array $processors ): array {
	$sanitized = array();
	$seen      = array();
	foreach ( $processors as $value ) {
		if ( is_string( $value ) && '' !== $value && ! isset( $seen[ $value ] ) ) {
			$seen[ $value ] = true;
			$sanitized[]    = $value;
		}
	}
	return $sanitized;
}