wp_style_is()
云策文档标注
概述
wp_style_is() 函数用于检查指定的 CSS 样式表是否已添加到队列中。它接受样式表句柄和状态参数,返回布尔值表示是否已排队。
关键要点
- 函数原型:wp_style_is( $handle, $status = 'enqueued' )
- 参数:$handle(必需,样式表名称),$status(可选,检查状态,默认 'enqueued',可接受 'enqueued'、'registered'、'queue'、'to_do'、'done')
- 返回值:布尔值,表示样式是否已排队
- 内部调用 wp_styles()->query() 实现检查
- 相关函数:wp_styles()、wp_hoist_late_printed_styles()、register_block_style_handle()
- 引入版本:WordPress 2.8.0
注意事项
在旧版本 WordPress(如 3.1)中,$status 参数使用 'enqueued' 值可能不被接受,并可能导致 PHP 通知和警告(严格模式下)。
原文内容
Checks whether a CSS stylesheet has been added to the queue.
Parameters
$handlestringrequired-
Name of the stylesheet.
$statusstringoptional-
Status of the stylesheet to check. Default
'enqueued'.
Accepts'enqueued','registered','queue','to_do', and'done'.
Source
function wp_style_is( $handle, $status = 'enqueued' ) {
_wp_scripts_maybe_doing_it_wrong( __FUNCTION__, $handle );
return (bool) wp_styles()->query( $handle, $status );
}
Changelog
| Version | Description |
|---|---|
| 2.8.0 | Introduced. |
Skip to note 2 content
77 Solutions
In old versions of WordPress (checked on 3.1) “enqueued” value of $list param is NOT accepted and results in PHP notices and warnings when strict mode is enabled.