Automattic\WooCommerce\Internal\Admin\Settings

PaymentsRestController::sanitize_provider_idprivateWC 1.0

Sanitize a provider ID.

This method ensures that the provider ID is a safe string by removing any unwanted characters. It strips all HTML tags, removes accents, percent-encoded characters, and HTML entities, and allows only lowercase and uppercase letters, digits, underscores, and dashes.

Method of the class: PaymentsRestController{}

No Hooks.

Returns

String. The sanitized provider ID.

Usage

// private - for code of main (parent) class only
$result = $this->sanitize_provider_id( $provider_id ): string;
$provider_id(string) (required)
The provider ID to sanitize.

PaymentsRestController::sanitize_provider_id() code WC 10.7.0

private function sanitize_provider_id( string $provider_id ): string {
	$provider_id = wp_strip_all_tags( $provider_id );
	$provider_id = remove_accents( $provider_id );
	// Remove percent-encoded characters.
	$provider_id = preg_replace( '|%([a-fA-F0-9][a-fA-F0-9])|', '', $provider_id );
	// Remove HTML entities.
	$provider_id = preg_replace( '/&.+?;/', '', $provider_id );

	// Only lowercase and uppercase ASCII letters, digits, underscores, and dashes are allowed.
	$provider_id = preg_replace( '|[^a-z0-9_\-]|i', '', $provider_id );

	return $provider_id;
}