WP_Customize_Custom_CSS_Setting::validate()publicWP 4.7.0

Validate a received value for being valid CSS.

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

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

Хуков нет.


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


$WP_Customize_Custom_CSS_Setting = new WP_Customize_Custom_CSS_Setting();
$WP_Customize_Custom_CSS_Setting->validate( $value );
$value(строка) (обязательный)
CSS to validate.

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

С версии 4.7.0 Введена.
С версии 4.9.0 Checking for balanced characters has been moved client-side via linting in code editor.
С версии 5.9.0 Renamed $css to $value for PHP 8 named parameter support.

Код WP_Customize_Custom_CSS_Setting::validate() WP 6.3.1

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;