wppaste
WordPress

twentytwenty_get_customizer_css( string $type = 'front-end' ): string

Since
Twenty Twenty 1.0
Source
wp-content/themes/twentytwenty/inc/custom-css.php:60
Gets CSS Built from Customizer Options.

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

Touches nothing outside its own arguments.

Scaling
Scales with input

The body loops, so the work grows with what you pass in.

Instructions
66–136

Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 239.

Plugin surface
None

Nothing here hands control to plugin code.

Called by
3

3 places in core call this, so the cost is paid more often than your own code shows.

What it touches

  • hookthird-party callbacksapply_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.

WhenInstructionsCalls it makes
$type !== "front-end"66–82twentytwenty_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–71twentytwenty_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–88twentytwenty_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–82twentytwenty_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–94twentytwenty_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–100twentytwenty_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–105twentytwenty_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–110twentytwenty_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–116twentytwenty_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–121twentytwenty_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–126twentytwenty_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–131twentytwenty_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"136twentytwenty_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

PHPCompiledExecutedBranchesNotes
8.6-dev23966–13636
8.523966–13636
8.423966–136363 fewer instructions than PHP 8.3
8.324266–13636
8.224266–13636
8.124266–13636
7.424266–13636

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

Used by · 3

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.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

7.0.4
Return type changed from none to string.verified against source
Twenty Twenty 1.0
Twenty Twenty 1.0from the docblock

About 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.