返回介绍

wp_admin_css()

发布于 2017-09-11 11:22:13 字数 3838 浏览 1155 评论 0 收藏 0

wp_admin_css( string $file = 'wp-admin',  bool $force_echo = false )

Enqueues or directly prints a stylesheet link to the specified CSS file.


description

"Intelligently" decides to enqueue or to print the CSS file. If the ‘wp_print_styles’ action has not yet been called, the CSS file will be enqueued. If the ‘wp_print_styles’ action has been called, the CSS link will be printed. Printing may be forced by passing true as the $force_echo (second) parameter.

For backward compatibility with WordPress 2.3 calling method: If the $file (first) parameter does not correspond to a registered CSS file, we assume $file is a file relative to wp-admin/ without its ".css" extension. A stylesheet link to that generated URL is printed.


参数

$file

(string) (Optional) Style handle name or file name (without ".css" extension) relative to wp-admin/. Defaults to 'wp-admin'.

Default value: 'wp-admin'

$force_echo

(bool) (Optional) Force the stylesheet link to be printed rather than enqueued.

Default value: false


源代码

File: wp-includes/general-template.php

function wp_admin_css( $file = 'wp-admin', $force_echo = false ) {
	// For backward compatibility
	$handle = 0 === strpos( $file, 'css/' ) ? substr( $file, 4 ) : $file;

	if ( wp_styles()->query( $handle ) ) {
		if ( $force_echo || did_action( 'wp_print_styles' ) ) // we already printed the style queue. Print this one immediately
			wp_print_styles( $handle );
		else // Add to style queue
			wp_enqueue_style( $handle );
		return;
	}

	/**
	 * Filters the stylesheet link to the specified CSS file.
	 *
	 * If the site is set to display right-to-left, the RTL stylesheet link
	 * will be used instead.
	 *
	 * @since 2.3.0
	 * @param string $stylesheet_link HTML link element for the stylesheet.
	 * @param string $file            Style handle name or filename (without ".css" extension)
	 *                                relative to wp-admin/. Defaults to 'wp-admin'.
	 */
	echo apply_filters( 'wp_admin_css', "<link rel='stylesheet' href='" . esc_url( wp_admin_css_uri( $file ) ) . "' type='text/css' />\n", $file );

	if ( function_exists( 'is_rtl' ) && is_rtl() ) {
		/** This filter is documented in wp-includes/general-template.php */
		echo apply_filters( 'wp_admin_css', "<link rel='stylesheet' href='" . esc_url( wp_admin_css_uri( "$file-rtl" ) ) . "' type='text/css' />\n", "$file-rtl" );
	}
}

更新日志

Versiondescription
2.3.0Introduced.

相关函数

Uses

  • wp-includes/functions.wp-styles.php: wp_styles()
  • wp-includes/formatting.php: esc_url()
  • wp-includes/general-template.php: wp_admin_css_uri()
  • wp-includes/general-template.php: wp_admin_css
  • wp-includes/l10n.php: is_rtl()
  • wp-includes/functions.wp-styles.php: wp_print_styles()
  • wp-includes/functions.wp-styles.php: wp_enqueue_style()
  • wp-includes/plugin.php: did_action()
  • wp-includes/plugin.php: apply_filters()
  • Show 4 more uses Hide more uses

Used By

  • wp-admin/install.php: display_header()

User Contributed Notes

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文