_custom_background_cb()
- Since
- 3.0.0
- Source
wp-includes/theme.php:1877
Cost profile
Measured from the compiled opcodes, not from a stopwatch. Every number here is identical on any machine that runs the same PHP version, and every function in core is ranked by these figures.
- Cost class
- Trivial
- Scaling
- Constant
- Instructions
- 21–133
- Plugin surface
- None
- Called by
- 0
Touches nothing outside its own arguments.
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.4, depending on the branch taken. The body compiles to 140.
Nothing here hands control to plugin code.
Nothing in core calls this; the cost is only what you spend yourself.
What it touches
- hookthird-party callbacks
apply_filters()one call below _custom_background_cb()
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 · 5 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost _custom_background_cb() can have, taken from its control-flow graph on PHP 8.4.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 21–23 | get_background_image()set_url_scheme()get_background_color()get_theme_support()is_customize_preview() |
| always | 40–41 | get_background_image()set_url_scheme()get_background_color()get_theme_support()->next_tag()->set_modifiable_text()->get_updated_html() |
| always | 45–46 | get_background_image()set_url_scheme()get_background_color()get_theme_support()maybe_hash_hex_color()->next_tag()->set_modifiable_text()->get_updated_html() |
| always | 122–128 | get_background_image()set_url_scheme()get_background_color()get_theme_support()sanitize_url()get_theme_support()get_theme_mod()get_theme_support()get_theme_mod()get_theme_support()get_theme_mod()get_theme_support()get_theme_mod()get_theme_support()get_theme_mod()->next_tag()->set_modifiable_text()->get_updated_html() |
| always | 127–133 | get_background_image()set_url_scheme()get_background_color()get_theme_support()maybe_hash_hex_color()sanitize_url()get_theme_support()get_theme_mod()get_theme_support()get_theme_mod()get_theme_support()get_theme_mod()get_theme_support()get_theme_mod()get_theme_support()get_theme_mod()->next_tag()->set_modifiable_text()->get_updated_html() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
7.4 | 143 | 21–136 | 11 | More instructions than PHP 8.4 |
8.1 | 142 | 21–135 | 11 | More instructions than PHP 8.4 |
8.2 | 142 | 21–135 | 11 | More instructions than PHP 8.4 |
8.3 | 142 | 21–135 | 11 | More instructions than PHP 8.4 |
8.4 | 140 | 21–133 | 11 | Compiles to the same instructions |
Oldest PHP that compiles this body: 7.4. An instruction is not a fixed amount of time, so a version with the same count is not necessarily the same speed; what the count rules out is a difference in the work itself.
Uses · 9
- set_url_scheme()Sets the scheme for a URL.
- get_background_image()Retrieves background image for custom background.
- get_background_color()Retrieves value for custom background color.
- get_theme_support()Gets the theme support arguments passed when registering that support.
- is_customize_preview()Whether the site is being previewed in the Customizer.
- maybe_hash_hex_color()Ensures that any hex color is properly hashed.
- sanitize_url()Sanitizes a URL for database or redirect usage.
- get_theme_mod()Retrieves theme modification value for the active theme.
- WP_HTML_Tag_Processor::__construct()Constructor.
Source
function _custom_background_cb() { // $background is the saved custom image, or the default image. $background = set_url_scheme( get_background_image() ); /* * $color is the saved custom color. * A default has to be specified in style.css. It will not be printed here. */ $color = get_background_color(); if ( get_theme_support( 'custom-background', 'default-color' ) === $color ) { $color = false; } if ( ! $background && ! $color ) { if ( is_customize_preview() ) { echo '<style id="custom-background-css"></style>'; } return; } $style = $color ? 'background-color: ' . maybe_hash_hex_color( $color ) . ';' : ''; if ( $background ) { $image = ' background-image: url("' . sanitize_url( $background ) . '");'; // Background Position. $position_x = get_theme_mod( 'background_position_x', get_theme_support( 'custom-background', 'default-position-x' ) ); $position_y = get_theme_mod( 'background_position_y', get_theme_support( 'custom-background', 'default-position-y' ) ); if ( ! in_array( $position_x, array( 'left', 'center', 'right' ), true ) ) { $position_x = 'left'; } if ( ! in_array( $position_y, array( 'top', 'center', 'bottom' ), true ) ) { $position_y = 'top'; } $position = " background-position: $position_x $position_y;"; // Background Size. $size = get_theme_mod( 'background_size', get_theme_support( 'custom-background', 'default-size' ) ); if ( ! in_array( $size, array( 'auto', 'contain', 'cover' ), true ) ) { $size = 'auto'; } $size = " background-size: $size;"; // Background Repeat. $repeat = get_theme_mod( 'background_repeat', get_theme_support( 'custom-background', 'default-repeat' ) ); if ( ! in_array( $repeat, array( 'repeat-x', 'repeat-y', 'repeat', 'no-repeat' ), true ) ) { $repeat = 'repeat'; } $repeat = " background-repeat: $repeat;"; // Background Scroll. $attachment = get_theme_mod( 'background_attachment', get_theme_support( 'custom-background', 'default-attachment' ) ); if ( 'fixed' !== $attachment ) { $attachment = 'scroll'; } $attachment = " background-attachment: $attachment;"; $style .= $image . $position . $size . $repeat . $attachment; } $processor = new WP_HTML_Tag_Processor( '<style id="custom-background-css"></style>' ); $processor->next_tag(); $style_tag_content = 'body.custom-background { ' . trim( $style ) . ' }'; $processor->set_modifiable_text( "\n{$style_tag_content}\n" ); echo "{$processor->get_updated_html()}\n";}History
Introduced in 3.0.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 7.0.4 tag, from
src/wp-includes/theme.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.