Automattic\WooCommerce\Internal\BatchProcessing
BatchProcessingController::sanitize_processor_list
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.
Method of the class: BatchProcessingController{}
No Hooks.
Returns
Array. Sanitized list of unique class-name strings.
Usage
// private - for code of main (parent) class only $result = $this->sanitize_processor_list( $processors ): array;
- $processors(array) (required)
- Raw processor list as read from the option.
Changelog
| Since 11.0.0 | Introduced. |
BatchProcessingController::sanitize_processor_list() BatchProcessingController::sanitize processor list code WC 11.0.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;
}