WP_Styles::print_inline_style │ public │ WP 3.3.0

Prints extra CSS styles of a registered stylesheet.

Метод класса: WP_Styles{}

Хуков нет.

Возвращает

string|bool. False if no data exists, inline styles if $display is true, true otherwise.

Использование

global $wp_styles;
$wp_styles->print_inline_style( $handle, $display );
$handle(строка) (обязательный)
The style's registered handle.
$display(true|false)
Whether to print the inline style instead of just returning it.
По умолчанию: true

Список изменений

С версии 3.3.0 Введена.

Код WP_Styles::print_inline_style() WP 7.1.2

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;
}