返回介绍

_media_states()

发布于 2017-09-11 13:27:44 字数 3966 浏览 923 评论 0 收藏 0

_media_states( WP_Post $post )

description


参数

$post

(WP_Post) (Required)


源代码

File: wp-admin/includes/template.php

function _media_states( $post ) {
	$media_states = array();
	$stylesheet = get_option('stylesheet');

	if ( current_theme_supports( 'custom-header') ) {
		$meta_header = get_post_meta($post->ID, '_wp_attachment_is_custom_header', true );

		if ( is_random_header_image() ) {
			$header_images = wp_list_pluck( get_uploaded_header_images(), 'attachment_id' );

			if ( $meta_header == $stylesheet && in_array( $post->ID, $header_images ) ) {
				$media_states[] = __( 'Header Image' );
			}
		} else {
			$header_image = get_header_image();

			// Display "Header Image" if the image was ever used as a header image
			if ( ! empty( $meta_header ) && $meta_header == $stylesheet && $header_image !== wp_get_attachment_url( $post->ID ) ) {
				$media_states[] = __( 'Header Image' );
			}

			// Display "Current Header Image" if the image is currently the header image
			if ( $header_image && $header_image == wp_get_attachment_url( $post->ID ) ) {
				$media_states[] = __( 'Current Header Image' );
			}
		}
	}

	if ( current_theme_supports( 'custom-background') ) {
		$meta_background = get_post_meta($post->ID, '_wp_attachment_is_custom_background', true );

		if ( ! empty( $meta_background ) && $meta_background == $stylesheet ) {
			$media_states[] = __( 'Background Image' );

			$background_image = get_background_image();
			if ( $background_image && $background_image == wp_get_attachment_url( $post->ID ) ) {
				$media_states[] = __( 'Current Background Image' );
			}
		}
	}

	if ( $post->ID == get_option( 'site_icon' ) ) {
		$media_states[] = __( 'Site Icon' );
	}

	if ( $post->ID == get_theme_mod( 'custom_logo' ) ) {
		$media_states[] = __( 'Logo' );
	}

	/**
	 * Filters the default media display states for items in the Media list table.
	 *
	 * @since 3.2.0
	 * @since 4.8.0 Added the `$post` parameter.
	 *
	 * @param array   $media_states An array of media states. Default 'Header Image',
	 *                              'Background Image', 'Site Icon', 'Logo'.
	 * @param WP_Post $post         The current attachment object.
	 */
	$media_states = apply_filters( 'display_media_states', $media_states, $post );

	if ( ! empty( $media_states ) ) {
		$state_count = count( $media_states );
		$i = 0;
		echo ' — ';
		foreach ( $media_states as $state ) {
			++$i;
			( $i == $state_count ) ? $sep = '' : $sep = ', ';
			echo "<span class='post-state'>$state$sep</span>";
		}
	}
}

Collapse full 源代码 code View on Trac


相关函数

Uses

  • wp-admin/includes/template.php: display_media_states
  • wp-includes/theme.php: current_theme_supports()
  • wp-includes/theme.php: is_random_header_image()
  • wp-includes/theme.php: get_uploaded_header_images()
  • wp-includes/theme.php: get_header_image()
  • wp-includes/theme.php: get_background_image()
  • wp-includes/theme.php: get_theme_mod()
  • wp-includes/l10n.php: __()
  • wp-includes/functions.php: wp_list_pluck()
  • wp-includes/plugin.php: apply_filters()
  • wp-includes/option.php: get_option()
  • wp-includes/post.php: wp_get_attachment_url()
  • wp-includes/post.php: get_post_meta()
  • Show 8 more uses Hide more uses

Used By

  • wp-admin/includes/class-wp-media-list-table.php: WP_Media_List_Table::column_title()

User Contributed Notes

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

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

发布评论

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