twentytwenty_get_customizer_css( string $type = 'front-end' ): string
- Since
- Twenty Twenty 1.0
- Source
wp-content/themes/twentytwenty/inc/custom-css.php:60
Description
Builds CSS reflecting colors, fonts and other options set in the Customizer, and returns them for output.
Compatibility
- WordPress
- since Twenty Twenty 1.0
- PHP
- 7.4–8.6-dev
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.
Parameters
$typestringoptional- Whether to return CSS for the "front-end", "block-editor", or "classic-editor".Default:
'front-end'
Return value
string- CSS styles built from Customizer options.
Performance profile
How much work a call to twentytwenty_get_customizer_css() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.
- Cost class
- Light
- Scaling
- Scales with input
- Instructions
- 66–136
- Plugin surface
- None
- Called by
- 3
Touches nothing outside its own arguments.
The body loops, so the work grows with what you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 239.
Nothing here hands control to plugin code.
3 places in core call this, so the cost is paid more often than your own code shows.
What it touches
- hookthird-party callbacks
apply_filters()one call below twentytwenty_get_customizer_css()
Further down the call graph this can also reach option, cache, serialize, transient and query. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.
What one call costs · 13 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost twentytwenty_get_customizer_css() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
$type !== "front-end" | 66–82 | twentytwenty_get_color_for_area(), sanitize_hex_color(), twentytwenty_get_color_for_area(), sanitize_hex_color(), twentytwenty_get_color_for_area(), sanitize_hex_color(), twentytwenty_get_color_for_area(), sanitize_hex_color(), twentytwenty_get_color_for_area(), sanitize_hex_color(), get_theme_mod(), sanitize_hex_color(), get_theme_mod(), sanitize_hex_color_no_hash(), ob_start(), ob_get_clean() |
$type === "front-end" | 68–71 | twentytwenty_get_color_for_area(), sanitize_hex_color(), twentytwenty_get_color_for_area(), sanitize_hex_color(), twentytwenty_get_color_for_area(), sanitize_hex_color(), twentytwenty_get_color_for_area(), sanitize_hex_color(), twentytwenty_get_color_for_area(), sanitize_hex_color(), get_theme_mod(), sanitize_hex_color(), get_theme_mod(), sanitize_hex_color_no_hash(), ob_start(), twentytwenty_get_elements_array(), ob_get_clean() |
$type !== "front-end" | 77–88 | twentytwenty_get_color_for_area(), sanitize_hex_color(), twentytwenty_get_color_for_area(), sanitize_hex_color(), twentytwenty_get_color_for_area(), sanitize_hex_color(), twentytwenty_get_color_for_area(), sanitize_hex_color(), twentytwenty_get_color_for_area(), sanitize_hex_color(), get_theme_mod(), sanitize_hex_color(), get_theme_mod(), sanitize_hex_color_no_hash(), ob_start(), twentytwenty_generate_css(), ob_get_clean() |
$type === "front-end" && $cover !== "#ffffff" | 81–82 | twentytwenty_get_color_for_area(), sanitize_hex_color(), twentytwenty_get_color_for_area(), sanitize_hex_color(), twentytwenty_get_color_for_area(), sanitize_hex_color(), twentytwenty_get_color_for_area(), sanitize_hex_color(), twentytwenty_get_color_for_area(), sanitize_hex_color(), get_theme_mod(), sanitize_hex_color(), get_theme_mod(), sanitize_hex_color_no_hash(), ob_start(), twentytwenty_get_elements_array(), twentytwenty_generate_css(), twentytwenty_generate_css(), ob_get_clean() |
$type !== "front-end" | 82–94 | twentytwenty_get_color_for_area(), sanitize_hex_color(), twentytwenty_get_color_for_area(), sanitize_hex_color(), twentytwenty_get_color_for_area(), sanitize_hex_color(), twentytwenty_get_color_for_area(), sanitize_hex_color(), twentytwenty_get_color_for_area(), sanitize_hex_color(), get_theme_mod(), sanitize_hex_color(), get_theme_mod(), sanitize_hex_color_no_hash(), ob_start(), twentytwenty_generate_css(), twentytwenty_generate_css(), ob_get_clean() |
$type !== "front-end" | 88–100 | twentytwenty_get_color_for_area(), sanitize_hex_color(), twentytwenty_get_color_for_area(), sanitize_hex_color(), twentytwenty_get_color_for_area(), sanitize_hex_color(), twentytwenty_get_color_for_area(), sanitize_hex_color(), twentytwenty_get_color_for_area(), sanitize_hex_color(), get_theme_mod(), sanitize_hex_color(), get_theme_mod(), sanitize_hex_color_no_hash(), ob_start(), twentytwenty_generate_css(), twentytwenty_generate_css(), twentytwenty_generate_css(), ob_get_clean() |
$type !== "front-end" | 95–105 | twentytwenty_get_color_for_area(), sanitize_hex_color(), twentytwenty_get_color_for_area(), sanitize_hex_color(), twentytwenty_get_color_for_area(), sanitize_hex_color(), twentytwenty_get_color_for_area(), sanitize_hex_color(), twentytwenty_get_color_for_area(), sanitize_hex_color(), get_theme_mod(), sanitize_hex_color(), get_theme_mod(), sanitize_hex_color_no_hash(), ob_start(), twentytwenty_generate_css(), twentytwenty_generate_css(), twentytwenty_generate_css(), twentytwenty_generate_css(), ob_get_clean() |
$type !== "front-end" | 100–110 | twentytwenty_get_color_for_area(), sanitize_hex_color(), twentytwenty_get_color_for_area(), sanitize_hex_color(), twentytwenty_get_color_for_area(), sanitize_hex_color(), twentytwenty_get_color_for_area(), sanitize_hex_color(), twentytwenty_get_color_for_area(), sanitize_hex_color(), get_theme_mod(), sanitize_hex_color(), get_theme_mod(), sanitize_hex_color_no_hash(), ob_start(), twentytwenty_generate_css(), twentytwenty_generate_css(), twentytwenty_generate_css(), twentytwenty_generate_css(), twentytwenty_generate_css(), ob_get_clean() |
$type !== "front-end" | 107–116 | twentytwenty_get_color_for_area(), sanitize_hex_color(), twentytwenty_get_color_for_area(), sanitize_hex_color(), twentytwenty_get_color_for_area(), sanitize_hex_color(), twentytwenty_get_color_for_area(), sanitize_hex_color(), twentytwenty_get_color_for_area(), sanitize_hex_color(), get_theme_mod(), sanitize_hex_color(), get_theme_mod(), sanitize_hex_color_no_hash(), ob_start(), twentytwenty_generate_css(), twentytwenty_generate_css(), twentytwenty_generate_css(), twentytwenty_generate_css(), twentytwenty_generate_css(), twentytwenty_generate_css(), ob_get_clean() |
$type !== "front-end" | 114–121 | twentytwenty_get_color_for_area(), sanitize_hex_color(), twentytwenty_get_color_for_area(), sanitize_hex_color(), twentytwenty_get_color_for_area(), sanitize_hex_color(), twentytwenty_get_color_for_area(), sanitize_hex_color(), twentytwenty_get_color_for_area(), sanitize_hex_color(), get_theme_mod(), sanitize_hex_color(), get_theme_mod(), sanitize_hex_color_no_hash(), ob_start(), twentytwenty_generate_css(), twentytwenty_generate_css(), twentytwenty_generate_css(), twentytwenty_generate_css(), twentytwenty_generate_css(), twentytwenty_generate_css(), twentytwenty_generate_css(), ob_get_clean() |
$type !== "front-end" && $type === "block-editor" && $accent !== "#cd2653" | 121–126 | twentytwenty_get_color_for_area(), sanitize_hex_color(), twentytwenty_get_color_for_area(), sanitize_hex_color(), twentytwenty_get_color_for_area(), sanitize_hex_color(), twentytwenty_get_color_for_area(), sanitize_hex_color(), twentytwenty_get_color_for_area(), sanitize_hex_color(), get_theme_mod(), sanitize_hex_color(), get_theme_mod(), sanitize_hex_color_no_hash(), ob_start(), twentytwenty_generate_css(), twentytwenty_generate_css(), twentytwenty_generate_css(), twentytwenty_generate_css(), twentytwenty_generate_css(), twentytwenty_generate_css(), twentytwenty_generate_css(), twentytwenty_generate_css(), ob_get_clean() |
$type !== "front-end" && $type === "block-editor" && $accent !== "#cd2653" && $background !== "f5efe0" && $borders !== "#dcd7ca" | 128–131 | twentytwenty_get_color_for_area(), sanitize_hex_color(), twentytwenty_get_color_for_area(), sanitize_hex_color(), twentytwenty_get_color_for_area(), sanitize_hex_color(), twentytwenty_get_color_for_area(), sanitize_hex_color(), twentytwenty_get_color_for_area(), sanitize_hex_color(), get_theme_mod(), sanitize_hex_color(), get_theme_mod(), sanitize_hex_color_no_hash(), ob_start(), twentytwenty_generate_css(), twentytwenty_generate_css(), twentytwenty_generate_css(), twentytwenty_generate_css(), twentytwenty_generate_css(), twentytwenty_generate_css(), twentytwenty_generate_css(), twentytwenty_generate_css(), twentytwenty_generate_css(), ob_get_clean() |
1 further outcome, up to 136 instructions
$type !== "front-end" && $type === "block-editor" && $accent !== "#cd2653" && $background !== "f5efe0" && $borders !== "#dcd7ca" && $body !== "#000000" && $secondary !== "#6d6d6d" && $header_footer_background !== "#ffffff" | 136 | twentytwenty_get_color_for_area(), sanitize_hex_color(), twentytwenty_get_color_for_area(), sanitize_hex_color(), twentytwenty_get_color_for_area(), sanitize_hex_color(), twentytwenty_get_color_for_area(), sanitize_hex_color(), twentytwenty_get_color_for_area(), sanitize_hex_color(), get_theme_mod(), sanitize_hex_color(), get_theme_mod(), sanitize_hex_color_no_hash(), ob_start(), twentytwenty_generate_css(), twentytwenty_generate_css(), twentytwenty_generate_css(), twentytwenty_generate_css(), twentytwenty_generate_css(), twentytwenty_generate_css(), twentytwenty_generate_css(), twentytwenty_generate_css(), twentytwenty_generate_css(), twentytwenty_generate_css(), ob_get_clean() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 239 | 66–136 | 36 | |
| 8.5 | 239 | 66–136 | 36 | |
| 8.4 | 239 | 66–136 | 36 | 3 fewer instructions than PHP 8.3 |
| 8.3 | 242 | 66–136 | 36 | |
| 8.2 | 242 | 66–136 | 36 | |
| 8.1 | 242 | 66–136 | 36 | |
| 7.4 | 242 | 66–136 | 36 |
An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.
Uses · 6
- sanitize_hex_color()Sanitizes a hex color.
- twentytwenty_get_color_for_area()Gets accessible color for an area.
- get_theme_mod()Retrieves theme modification value for the active theme.
- sanitize_hex_color_no_hash()Sanitizes a hex color without a hash. Use sanitize_hex_color() when possible.
- twentytwenty_get_elements_array()Gets an array of elements.
- twentytwenty_generate_css()Generates CSS.
Used by · 3
- twentytwenty_add_classic_editor_customizer_styles()Output Customizer settings in the classic editor.
- twentytwenty_block_editor_styles()Enqueues supplemental block editor styles.
- twentytwenty_register_styles()Registers and Enqueues Styles.
Source code
function twentytwenty_get_customizer_css( $type = 'front-end' ) { // Get variables. $body = sanitize_hex_color( twentytwenty_get_color_for_area( 'content', 'text' ) ); $body_default = '#000000'; $secondary = sanitize_hex_color( twentytwenty_get_color_for_area( 'content', 'secondary' ) ); $secondary_default = '#6d6d6d'; $borders = sanitize_hex_color( twentytwenty_get_color_for_area( 'content', 'borders' ) ); $borders_default = '#dcd7ca'; $accent = sanitize_hex_color( twentytwenty_get_color_for_area( 'content', 'accent' ) ); $accent_default = '#cd2653'; // Header. $header_footer_background = sanitize_hex_color( twentytwenty_get_color_for_area( 'header-footer', 'background' ) ); $header_footer_background_default = '#ffffff'; // Cover. $cover = sanitize_hex_color( get_theme_mod( 'cover_template_overlay_text_color' ) ); $cover_default = '#ffffff'; // Background. $background = sanitize_hex_color_no_hash( get_theme_mod( 'background_color' ) ); $background_default = 'f5efe0'; ob_start(); /* * Note – Styles are applied in this order: * 1. Element specific * 2. Helper classes * * This enables all helper classes to overwrite base element styles, * meaning that any color classes applied in the block editor will * have a higher priority than the base element styles. */ // Front-End Styles. if ( 'front-end' === $type ) { // Auto-calculated colors. $elements_definitions = twentytwenty_get_elements_array(); foreach ( $elements_definitions as $context => $props ) { foreach ( $props as $key => $definitions ) { foreach ( $definitions as $property => $elements ) { /* * If we don't have an elements array or it is empty * then skip this iteration early; */ if ( ! is_array( $elements ) || empty( $elements ) ) { continue; } $val = twentytwenty_get_color_for_area( $context, $key ); if ( $val ) { twentytwenty_generate_css( implode( ',', $elements ), $property, $val ); } } } } if ( $cover && $cover !== $cover_default ) { twentytwenty_generate_css( '.overlay-header .header-inner', 'color', $cover ); twentytwenty_generate_css( '.cover-header .entry-header *', 'color', $cover ); } // Block Editor Styles. } elseif ( 'block-editor' === $type ) { // Colors. // Accent color. if ( $accent && $accent !== $accent_default ) { twentytwenty_generate_css( ':root .has-accent-color, .editor-styles-wrapper a, .editor-styles-wrapper .has-drop-cap:not(:focus)::first-letter, .editor-styles-wrapper .wp-block-button.is-style-outline .wp-block-button__link, .editor-styles-wrapper .wp-block-pullquote::before, .editor-styles-wrapper .wp-block-file .wp-block-file__textlink', 'color', $accent ); twentytwenty_generate_css( '.editor-styles-wrapper .wp-block-quote', 'border-color', $accent, '' ); twentytwenty_generate_css( '.has-accent-background-color, .editor-styles-wrapper .wp-block-button__link, .editor-styles-wrapper .wp-block-file__button', 'background-color', $accent ); } // Background color. if ( $background && $background !== $background_default ) { twentytwenty_generate_css( '.editor-styles-wrapper', 'background-color', '#' . $background ); twentytwenty_generate_css( '.has-background.has-primary-background-color:not(.has-text-color),.has-background.has-primary-background-color *:not(.has-text-color),.has-background.has-accent-background-color:not(.has-text-color),.has-background.has-accent-background-color *:not(.has-text-color)', 'color', '#' . $background ); }Changelog
Introduced in Twenty Twenty 1.0. One change between 6.7.7 and 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
none to string.verified against sourceAbout this page
- Parsed data
- Generated from the wordpress-develop 7.1.0 tag, from
src/wp-content/themes/twentytwenty/inc/custom-css.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.