WP_Customize_Custom_CSS_Setting::validate( string $value ): true|WP_Error

Validate a received value for being valid CSS.

Description

Checks for imbalanced braces, brackets, and comments.
Notifications are rendered when the customizer state is saved.

Parameters

$valuestringrequired
CSS to validate.

Return

true|WP_Error True if the input was validated, otherwise WP_Error.

Source

public function validate( $value ) {
	// Restores the more descriptive, specific name for use within this method.
	$css = $value;

	$validity = new WP_Error();

	if ( preg_match( '#</?\w+#', $css ) ) {
		$validity->add( 'illegal_markup', __( 'Markup is not allowed in CSS.' ) );
	}

	if ( ! $validity->has_errors() ) {
		$validity = parent::validate( $css );
	}
	return $validity;
}

Changelog

VersionDescription
5.9.0Renamed $css to $value for PHP 8 named parameter support.
4.9.0Checking for balanced characters has been moved client-side via linting in code editor.
4.7.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.