W3cubDocs

/WordPress

WP_REST_Global_Styles_Controller::validate_custom_css( string $css ): true|WP_Error

Validate style.css as valid CSS.

Description

Currently just checks for invalid markup.

Parameters

$cssstringrequired
CSS to validate.

Return

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

Source

protected function validate_custom_css( $css ) {
	if ( preg_match( '#</?\w+#', $css ) ) {
		return new WP_Error(
			'rest_custom_css_illegal_markup',
			__( 'Markup is not allowed in CSS.' ),
			array( 'status' => 400 )
		);
	}
	return true;
}

Changelog

Version Description
6.4.0 Changed method visibility to protected.
6.2.0 Introduced.

© 2003–2024 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/classes/wp_rest_global_styles_controller/validate_custom_css