返回介绍

wp_get_custom_css_post()

发布于 2017-09-11 12:03:37 字数 2945 浏览 1044 评论 0 收藏 0

wp_get_custom_css_post( string $stylesheet = '' )

Fetch the custom_css post for a given theme.


description


参数

$stylesheet

(string) (Optional) A theme object stylesheet name. Defaults to the current theme.

Default value: ''


返回值

(WP_Post|null) The custom_css post or null if none exists.


源代码

File: wp-includes/theme.php

function wp_get_custom_css_post( $stylesheet = '' ) {
	if ( empty( $stylesheet ) ) {
		$stylesheet = get_stylesheet();
	}

	$custom_css_query_vars = array(
		'post_type'              => 'custom_css',
		'post_status'            => get_post_stati(),
		'name'                   => sanitize_title( $stylesheet ),
		'posts_per_page'         => 1,
		'no_found_rows'          => true,
		'cache_results'          => true,
		'update_post_meta_cache' => false,
		'update_post_term_cache' => false,
		'lazy_load_term_meta'    => false,
	);

	$post = null;
	if ( get_stylesheet() === $stylesheet ) {
		$post_id = get_theme_mod( 'custom_css_post_id' );

		if ( $post_id > 0 && get_post( $post_id ) ) {
			$post = get_post( $post_id );
		}

		// `-1` indicates no post exists; no query necessary.
		if ( ! $post && -1 !== $post_id ) {
			$query = new WP_Query( $custom_css_query_vars );
			$post = $query->post;
			/*
			 * Cache the lookup. See wp_update_custom_css_post().
			 * @todo This should get cleared if a custom_css post is added/removed.
			 */
			set_theme_mod( 'custom_css_post_id', $post ? $post->ID : -1 );
		}
	} else {
		$query = new WP_Query( $custom_css_query_vars );
		$post = $query->post;
	}

	return $post;
}

更新日志

Versiondescription
4.7.0Introduced.

相关函数

Uses

  • wp-includes/theme.php: set_theme_mod()
  • wp-includes/theme.php: get_theme_mod()
  • wp-includes/theme.php: get_stylesheet()
  • wp-includes/formatting.php: sanitize_title()
  • wp-includes/class-wp-query.php: WP_Query::__construct()
  • wp-includes/post.php: get_post_stati()
  • wp-includes/post.php: get_post()
  • Show 2 more uses Hide more uses

Used By

  • wp-includes/theme.php: wp_update_custom_css_post()
  • wp-includes/theme.php: wp_get_custom_css()
  • wp-includes/customize/class-wp-customize-custom-css-setting.php: WP_Customize_Custom_CSS_Setting::value()

User Contributed Notes

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

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

发布评论

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