wppaste
WordPress

WP_Styles::print_inline_style( string $handle, bool $display = true ): string|bool

Since
3.3.0
Source
wp-includes/class-wp-styles.php:302
Prints extra CSS styles of a registered stylesheet.

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 $display is 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

Touches nothing outside its own arguments.

Scaling
Constant

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

Instructions
10–61

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

Plugin surface
None

Nothing here hands control to plugin code.

Called by
1

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

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.

WhenInstructionsCalls it makes
always10–17->get_data()
!empty($output) && is_array($output)35–40->get_data(), ->get_data(), rawurlencode()
!empty($output) && is_array($output)38->get_data(), ->next_tag(), ->set_attribute(), ->set_modifiable_text(), ->get_updated_html()
!empty($output) && is_array($output) && is_string($inlined_src)40->get_data(), ->get_data(), esc_url_raw()
!empty($output) && is_array($output)56–61->get_data(), ->get_data(), rawurlencode(), ->next_tag(), ->set_attribute(), ->set_modifiable_text(), ->get_updated_html()
!empty($output) && is_array($output) && is_string($inlined_src)61->get_data(), ->get_data(), esc_url_raw(), ->next_tag(), ->set_attribute(), ->set_modifiable_text(), ->get_updated_html()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev6810–617
8.56810–617
8.46810–6174 fewer instructions than PHP 8.3
8.37210–657
8.27210–657
8.17210–657
7.47210–657

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

Used by · 1

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;		} 		$processor = new WP_HTML_Tag_Processor( '<style></style>' );		$processor->next_tag();		$processor->set_attribute( 'id', "{$handle}-inline-css" );		$processor->set_modifiable_text( "\n{$output}\n" );		echo "{$processor->get_updated_html()}\n"; 		return true;	}

Changelog

Introduced in 3.3.0. 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-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.