_get_random_header_data(): object
- Since
- 3.4.0
- Source
wp-includes/theme.php:1398
Return
object
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
- Heavy
- Scaling
- Constant
- Instructions
- 5–55
- Plugin surface
- None
- Called by
- 2
Reaches the database via get_posts().
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 64.
Nothing here hands control to plugin code.
2 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 _get_random_header_data() - querycontent query
get_posts()one call below _get_random_header_data() - optionoption read or write
get_option()one call below _get_random_header_data()
Further down the call graph this can also reach cache, serialize and transient — those are the worst case, several calls deep and usually down an error path, not what a normal call pays.
What one call costs · 7 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost _get_random_header_data() can have, taken from its control-flow graph on PHP 8.4.
| When | Instructions | Calls it makes |
|---|---|---|
!empty($_wp_random_header) | 5 | none |
empty($_wp_random_header) && $header_image_mod !== "random-uploaded-image" && empty($headers) | 19–23 | get_theme_mod() |
empty($_wp_random_header) && $header_image_mod === "random-uploaded-image" && empty($headers) | 21 | get_theme_mod()get_uploaded_header_images() |
empty($_wp_random_header) && $header_image_mod !== "random-uploaded-image" && !empty($_wp_default_headers) && $header_image_mod !== "random-default-image" && empty($headers) | 26–27 | get_theme_mod()current_theme_supports() |
empty($_wp_random_header) && $header_image_mod !== "random-uploaded-image" && !empty($headers) | 47–51 | get_theme_mod()array_rand()get_template_directory_uri()get_stylesheet_directory_uri()sprintf()get_template_directory_uri()get_stylesheet_directory_uri()sprintf() |
empty($_wp_random_header) && $header_image_mod === "random-uploaded-image" && !empty($headers) | 49 | get_theme_mod()get_uploaded_header_images()array_rand()get_template_directory_uri()get_stylesheet_directory_uri()sprintf()get_template_directory_uri()get_stylesheet_directory_uri()sprintf() |
empty($_wp_random_header) && $header_image_mod !== "random-uploaded-image" && !empty($_wp_default_headers) && $header_image_mod !== "random-default-image" && !empty($headers) | 54–55 | get_theme_mod()current_theme_supports()array_rand()get_template_directory_uri()get_stylesheet_directory_uri()sprintf()get_template_directory_uri()get_stylesheet_directory_uri()sprintf() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
7.4 | 64 | 5–55 | 6 | Compiles to the same instructions |
8.1 | 64 | 5–55 | 6 | Compiles to the same instructions |
8.2 | 64 | 5–55 | 6 | Compiles to the same instructions |
8.3 | 64 | 5–55 | 6 | Compiles to the same instructions |
8.4 | 64 | 5–55 | 6 | 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 · 6
- get_theme_mod()Retrieves theme modification value for the active theme.
- get_uploaded_header_images()Gets the header images uploaded for the active theme.
- current_theme_supports()Checks a theme's support for a given feature.
- get_template_directory_uri()Retrieves template directory URI for the active theme.
- get_stylesheet_directory_uri()Retrieves stylesheet directory URI for the active theme.
- stdClass::__construct()
Used by · 2
- get_custom_header()Gets the header image data.
- get_random_header_image()Gets random header image URL from registered images in theme.
Source
function _get_random_header_data() { global $_wp_default_headers; static $_wp_random_header = null; if ( empty( $_wp_random_header ) ) { $header_image_mod = get_theme_mod( 'header_image', '' ); $headers = array(); if ( 'random-uploaded-image' === $header_image_mod ) { $headers = get_uploaded_header_images(); } elseif ( ! empty( $_wp_default_headers ) ) { if ( 'random-default-image' === $header_image_mod ) { $headers = $_wp_default_headers; } else { if ( current_theme_supports( 'custom-header', 'random-default' ) ) { $headers = $_wp_default_headers; } } } if ( empty( $headers ) ) { return new stdClass(); } $_wp_random_header = (object) $headers[ array_rand( $headers ) ]; $_wp_random_header->url = sprintf( $_wp_random_header->url, get_template_directory_uri(), get_stylesheet_directory_uri() ); $_wp_random_header->thumbnail_url = sprintf( $_wp_random_header->thumbnail_url, get_template_directory_uri(), get_stylesheet_directory_uri() ); } return $_wp_random_header;}History
Introduced in 3.4.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 6.9.7 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.