Writing custom CSS to a theme in code appears to work. The setter runs, caches clear, save() reports success — and the column is never touched.
The cause
ActiveRecord::save() writes only fields recorded as changed:
$data = $this->_new ? $this->_data : $this->changed;
But Theme::set_custom_css() assigns straight into _data and never marks the field:
public function set_custom_css( string $value ) : void
{
$value = str_replace( '</style>', '', $value );
$this->_data['custom_css'] = $value; // NOT $this->changed
// ... clears an editor store key
}
The fix
Write the column directly and reproduce the side effects:
Db::i()->update( 'core_themes', array(
'set_custom_css' => $value,
'set_css_updated' => time(), // cache-buster on the served CSS URL
), array( 'set_id=?', $themeId ) );
$key = $themeId . '_theme_editor_custom_css';
unset( Store::i()->$key );
Theme::deleteCompiledTemplate( 'core', 'front', 'global', $themeId );
Theme::deleteCompiledCss( 'core', 'front', 'custom', 'custom.css', $themeId );
Store::i()->clearAll();
Two related notes
- Custom CSS lives in
core_themes.set_custom_css, not incore_theme_css— that table holds application stylesheets. - It is served inside a
<style id="themeCustomCSS">block and is minified, so comments are stripped. Searching the served page for a marker comment will not find it; search for a selector instead.
Recommended Comments