wppaste
WordPress

twentynineteen_custom_colors_css()

Source
wp-content/themes/twentynineteen/inc/color-patterns.php:13
Generates the CSS for the current primary color.

Compatibility

WordPress
core
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.

Performance profile

How much work a call to twentynineteen_custom_colors_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
Trivial

Touches nothing outside its own arguments.

Scaling
Constant

No loop in the body: the same number of instructions runs whatever you pass in.

Instructions
140–152

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

Plugin surface
6 hooks

Third-party callbacks on 'twentynineteen_custom_colors_saturation', 'twentynineteen_custom_colors_saturation_selection', 'twentynineteen_custom_colors_lightness' run inside this call, and their cost is not bounded by anything here.

Called by
2

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

What it touches

  • hookthird-party callbacksapply_filters()called directly

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 · 4 distinct outcomes

One number would be a lie: the work depends on which branch runs. These are every distinct cost twentynineteen_custom_colors_css() can have, taken from its control-flow graph on PHP 8.5.

WhenInstructionsCalls it makes
!function_exists()140get_theme_mod(), apply_filters(), absint(), apply_filters(), absint(), apply_filters(), absint(), apply_filters(), absint(), apply_filters(), absint(), function_exists(), apply_filters()
function_exists()143–144get_theme_mod(), apply_filters(), absint(), apply_filters(), absint(), apply_filters(), absint(), apply_filters(), absint(), apply_filters(), absint(), function_exists(), is_admin(), apply_filters()
!function_exists()148get_theme_mod(), get_theme_mod(), absint(), apply_filters(), absint(), apply_filters(), absint(), apply_filters(), absint(), apply_filters(), absint(), apply_filters(), absint(), function_exists(), apply_filters()
function_exists()151–152get_theme_mod(), get_theme_mod(), absint(), apply_filters(), absint(), apply_filters(), absint(), apply_filters(), absint(), apply_filters(), absint(), apply_filters(), absint(), function_exists(), is_admin(), apply_filters()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev152140–1523
8.5152140–1523
8.4152140–1523
8.3152140–1523
8.2152140–1523
8.1152140–15231 more instruction than PHP 7.4
7.4151139–1513

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.

Hooks and filters fired · 6

6 hooks fire while twentynineteen_custom_colors_css() runs, in this order:

  1. apply_filters( twentynineteen_custom_colors_saturation )filterline 27 (+14 into the body)

    Filters Twenty Nineteen default saturation level.

  2. apply_filters( twentynineteen_custom_colors_saturation_selection )filterline 37 (+24 into the body)

    Filters Twenty Nineteen default selection saturation level.

  3. apply_filters( twentynineteen_custom_colors_lightness )filterline 47 (+34 into the body)

    Filters Twenty Nineteen default lightness level.

  4. apply_filters( twentynineteen_custom_colors_lightness_hover )filterline 57 (+44 into the body)

    Filters Twenty Nineteen default hover lightness level.

  5. apply_filters( twentynineteen_custom_colors_lightness_selection )filterline 67 (+54 into the body)

    Filters Twenty Nineteen default selection lightness level.

  6. apply_filters( twentynineteen_custom_colors_css )filterline 271 (+258 into the body)

    Filters Twenty Nineteen custom colors CSS.

Uses · 4

  • get_theme_mod()Retrieves theme modification value for the active theme.
  • absint()Converts a value to non-negative integer.
  • apply_filters()Calls the callback functions that have been added to a filter hook.
  • is_admin()Determines whether the current request is for an administrative interface page.

Used by · 2

Source code

<?phpfunction twentynineteen_custom_colors_css() { 	$primary_color = 199;	if ( 'default' !== get_theme_mod( 'primary_color', 'default' ) ) {		$primary_color = absint( get_theme_mod( 'primary_color_hue', 199 ) );	} 	/**	 * Filters Twenty Nineteen default saturation level.	 *	 * @since Twenty Nineteen 1.0	 *	 * @param int $saturation Color saturation level.	 */	$saturation = apply_filters( 'twentynineteen_custom_colors_saturation', 100 );	$saturation = absint( $saturation ) . '%'; 	/**	 * Filters Twenty Nineteen default selection saturation level.	 *	 * @since Twenty Nineteen 1.0	 *	 * @param int $saturation_selection Selection color saturation level.	 */	$saturation_selection = absint( apply_filters( 'twentynineteen_custom_colors_saturation_selection', 50 ) );	$saturation_selection = $saturation_selection . '%'; 	/**	 * Filters Twenty Nineteen default lightness level.	 *	 * @since Twenty Nineteen 1.0	 *	 * @param int $lightness Color lightness level.	 */	$lightness = apply_filters( 'twentynineteen_custom_colors_lightness', 33 );	$lightness = absint( $lightness ) . '%'; 	/**	 * Filters Twenty Nineteen default hover lightness level.	 *	 * @since Twenty Nineteen 1.0	 *	 * @param int $lightness_hover Hover color lightness level.	 */	$lightness_hover = apply_filters( 'twentynineteen_custom_colors_lightness_hover', 23 );	$lightness_hover = absint( $lightness_hover ) . '%'; 	/**	 * Filters Twenty Nineteen default selection lightness level.	 *	 * @since Twenty Nineteen 1.0	 *	 * @param int $lightness_selection Selection color lightness level.	 */	$lightness_selection = apply_filters( 'twentynineteen_custom_colors_lightness_selection', 90 );	$lightness_selection = absint( $lightness_selection ) . '%'; 	$theme_css = '		/*		 * Set background for:		 * - featured image :before		 * - featured image :before		 * - post thumbnail :before		 * - post thumbnail :before		 * - Submenu		 * - Sticky Post		 * - buttons		 * - WP Block Button		 * - Blocks		 */		.image-filters-enabled .site-header.featured-image .site-featured-image:before,		.image-filters-enabled .site-header.featured-image .site-featured-image:after,		.image-filters-enabled .entry .post-thumbnail:before,		.image-filters-enabled .entry .post-thumbnail:after,		.main-navigation .sub-menu,		.sticky-post,		.entry .entry-content .wp-block-button .wp-block-button__link:not(.has-background),		.entry .button, button, input[type="button"], input[type="reset"], input[type="submit"],		.entry .entry-content > .has-primary-background-color,		.entry .entry-content > *[class^="wp-block-"].has-primary-background-color,

Changelog

Unchanged from 6.7.7 through 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.

About this page

Parsed data
Generated from the wordpress-develop 7.1.0 tag, from src/wp-content/themes/twentynineteen/inc/color-patterns.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.