函数文档

wp_style_engine_get_stylesheet_from_context()

💡 云策文档标注

概述

wp_style_engine_get_stylesheet_from_context() 函数用于从指定的存储中检索并返回编译后的 CSS 字符串。它接受一个上下文名称和可选选项数组作为参数,通过 WP_Style_Engine 类的方法处理 CSS 规则。

关键要点

  • 函数返回编译后的 CSS 字符串,前提是找到对应的存储。
  • 参数 $context 是必需的字符串,对应现有存储键名。
  • 参数 $options 是可选的数组,包含 optimize 和 prettify 等选项以控制 CSS 输出。
  • 内部调用 WP_Style_Engine::compile_stylesheet_from_css_rules() 和 WP_Style_Engine::get_store() 方法。
  • 自 WordPress 6.1.0 版本引入。

代码示例

function wp_style_engine_get_stylesheet_from_context( $context, $options = array() ) {
    return WP_Style_Engine::compile_stylesheet_from_css_rules( WP_Style_Engine::get_store( $context )->get_all_rules(), $options );
}

📄 原文内容

Returns compiled CSS from a store, if found.

Parameters

$contextstringrequired
A valid context name, corresponding to an existing store key.
$optionsarrayoptional
An array of options.

  • optimize bool
    Whether to optimize the CSS output, e.g. combine rules.
    Default false.
  • prettify bool
    Whether to add new lines and indents to output.
    Defaults to whether the SCRIPT_DEBUG constant is defined.

Default:array()

Return

string A compiled CSS string.

Source

function wp_style_engine_get_stylesheet_from_context( $context, $options = array() ) {
	return WP_Style_Engine::compile_stylesheet_from_css_rules( WP_Style_Engine::get_store( $context )->get_all_rules(), $options );
}

Changelog

Version Description
6.1.0 Introduced.