Automattic\WooCommerce\Internal\Utilities

HtmlSanitizer::apply_string_callbacks()privateWC 1.0

Applies callbacks used to process the string before and after wp_kses().

If a callback is invalid we will short-circuit and return an empty string, on the grounds that it is better to output nothing than risky HTML. We also call the problem out via _doing_it_wrong() to highlight the problem (and increase the chances of this being caught during development).

Method of the class: HtmlSanitizer{}

No Hooks.

Return

String.

Usage

// private - for code of main (parent) class only
$result = $this->apply_string_callbacks( $callbacks, $string ): string;
$callbacks(callable[]) (required)
The callbacks used to mutate the string.
$string(string) (required)
The string being processed.

HtmlSanitizer::apply_string_callbacks() code WC 8.7.0

private function apply_string_callbacks( array $callbacks, string $string ): string {
	foreach ( $callbacks as $callback ) {
		if ( ! is_callable( $callback ) ) {
			_doing_it_wrong( __CLASS__ . '::apply', esc_html__( 'String processors must be an array of valid callbacks.', 'woocommerce' ), esc_html( WC()->version ) );
			return '';
		}

		$string = (string) $callback( $string );
	}

	return $string;
}