WP_Customize_Custom_CSS_Setting::update
Store the CSS setting value in the custom_css custom post type for the stylesheet.
Method of the class: WP_Customize_Custom_CSS_Setting{}
No Hooks.
Returns
Int|false. The post ID or false if the value could not be saved.
Usage
$WP_Customize_Custom_CSS_Setting = new WP_Customize_Custom_CSS_Setting(); $WP_Customize_Custom_CSS_Setting->update( $value );
- $value(string) (required)
- CSS to update.
Changelog
| Since 4.7.0 | Introduced. |
| Since 5.9.0 | Renamed $css to $value for PHP 8 named parameter support. |
WP_Customize_Custom_CSS_Setting::update() WP Customize Custom CSS Setting::update code WP 7.0.1
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 ( is_wp_error( $r ) ) {
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;
}