WP_Customize_Custom_CSS_Setting::update() WordPress Method

The WP_Customize_Custom_CSS_Setting::update() method is used to update the value of a Custom CSS setting. This method does not validate or sanitize the setting's value before updating it.

WP_Customize_Custom_CSS_Setting::update( string $value ) #

Store the CSS setting value in the custom_css custom post type for the stylesheet.


Parameters

$value

(string)(Required)CSS to update.


Top ↑

Return

(int|false) The post ID or false if the value could not be saved.


Top ↑

Source

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

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

		if ( empty( $css ) ) {
			$css = '';
		}

		$r = wp_update_custom_css_post(
			$css,
			array(
				'stylesheet' => $this->stylesheet,
			)
		);

		if ( $r instanceof WP_Error ) {
			return false;
		}
		$post_id = $r->ID;

		// Cache post ID in theme mod for performance to avoid additional DB query.
		if ( $this->manager->get_stylesheet() === $this->stylesheet ) {
			set_theme_mod( 'custom_css_post_id', $post_id );
		}

		return $post_id;
	}


Top ↑

Changelog

Changelog
VersionDescription
5.9.0Renamed $css to $value for PHP 8 named parameter support.
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.