WP_Customize_Custom_CSS_Setting::validate() WordPress Method

The WP_Customize_Custom_CSS_Setting::validate() method is used to validate the value of a Custom CSS setting. This setting is used to store CSS code that will be used to customize the appearance of a WordPress site. The validate() method ensures that the value of the Custom CSS setting is a valid CSS code.

WP_Customize_Custom_CSS_Setting::validate( string $value ) #

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.


Top ↑

Parameters

$value

(string)(Required)CSS to validate.


Top ↑

Return

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


Top ↑

Source

File: wp-includes/customize/class-wp-customize-custom-css-setting.php

	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;
	}


Top ↑

Changelog

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.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.