WP_Styles::print_inline_style( string $handle, bool $display = true ): string|bool
- Since
- 3.3.0
- Source
wp-includes/class-wp-styles.php:323
Compatibility
- WordPress
- since 3.3.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
$handlestring- The style's registered handle.
$displaybooloptional- Whether to print the inline style instead of just returning it. Default true.Default:
true
Return value
string|bool- False if no data exists, inline styles if
$displayis true, true otherwise.
Performance profile
How much work a call to WP_Styles::print_inline_style() 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
- Scaling
- Constant
- Instructions
- 10–50
- Plugin surface
- None
- Called by
- 1
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.5, depending on the branch taken. The body compiles to 57.
Nothing here hands control to plugin code.
1 place 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 WP_Styles::print_inline_style()
Further down the call graph this can also reach option, cache, serialize, query 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 · 6 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost WP_Styles::print_inline_style() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 10–17 | ->get_data() |
!empty($output) && is_array($output) | 27 | ->get_data(), esc_attr(), printf() |
!empty($output) && is_array($output) | 35–40 | ->get_data(), ->get_data(), rawurlencode() |
!empty($output) && is_array($output) && is_string($inlined_src) | 40 | ->get_data(), ->get_data(), esc_url_raw() |
!empty($output) && is_array($output) | 45–50 | ->get_data(), ->get_data(), rawurlencode(), esc_attr(), printf() |
!empty($output) && is_array($output) && is_string($inlined_src) | 50 | ->get_data(), ->get_data(), esc_url_raw(), esc_attr(), printf() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 59 | 10–52 | 7 | 2 more instructions than PHP 8.5 |
| 8.5 | 57 | 10–50 | 7 | |
| 8.4 | 57 | 10–50 | 7 | 4 fewer instructions than PHP 8.3 |
| 8.3 | 61 | 10–54 | 7 | |
| 8.2 | 61 | 10–54 | 7 | |
| 8.1 | 61 | 10–54 | 7 | |
| 7.4 | 61 | 10–54 | 7 |
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 · 3
- esc_url_raw()Sanitizes a URL for database or redirect usage.
- esc_attr()Escaping for HTML attributes.
- WP_Styles::get_data()
Used by · 1
- WP_Styles::do_item()Processes a style dependency.
Source code
public function print_inline_style( $handle, $display = true ) { $output = $this->get_data( $handle, 'after' ); if ( empty( $output ) || ! is_array( $output ) ) { return false; } if ( ! $this->do_concat ) { // Obtain the original `src` for a stylesheet possibly inlined by wp_maybe_inline_styles(). $inlined_src = $this->get_data( $handle, 'inlined_src' ); // If there's only one `after` inline style, and that inline style had been inlined, then use the $inlined_src // as the sourceURL. Otherwise, if there is more than one inline `after` style associated with the handle, // then resort to using the handle to construct the sourceURL since there isn't a single source. if ( count( $output ) === 1 && is_string( $inlined_src ) && strlen( $inlined_src ) > 0 ) { $source_url = esc_url_raw( $inlined_src ); } else { $source_url = rawurlencode( "{$handle}-inline-css" ); } $output[] = sprintf( '/*# sourceURL=%s */', $source_url ); } $output = implode( "\n", $output ); if ( ! $display ) { return $output; } printf( "<style id='%s-inline-css'%s>\n%s\n</style>\n", esc_attr( $handle ), $this->type_attr, $output ); return true; }Changelog
Introduced in 3.3.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/class-wp-styles.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.