返回介绍

image_size_input_fields()

发布于 2017-09-11 01:02:05 字数 3538 浏览 993 评论 0 收藏 0

image_size_input_fields( WP_Post $post,  bool|string $check = '' )

Retrieve HTML for the size radio buttons with the specified one checked.


description


参数

$post

(WP_Post) (Required)

$check

(bool|string) (Optional)

Default value: ''


返回值

(array)


源代码

File: wp-admin/includes/media.php

function image_size_input_fields( $post, $check = '' ) {
	/**
	 * Filters the names and labels of the default image sizes.
	 *
	 * @since 3.3.0
	 *
	 * @param array $size_names Array of image sizes and their names. Default values
	 *                          include 'Thumbnail', 'Medium', 'Large', 'Full Size'.
	 */
	$size_names = apply_filters( 'image_size_names_choose', array(
		'thumbnail' => __( 'Thumbnail' ),
		'medium'    => __( 'Medium' ),
		'large'     => __( 'Large' ),
		'full'      => __( 'Full Size' )
	) );

	if ( empty( $check ) ) {
		$check = get_user_setting('imgsize', 'medium');
	}
	$out = array();

	foreach ( $size_names as $size => $label ) {
		$downsize = image_downsize( $post->ID, $size );
		$checked = '';

		// Is this size selectable?
		$enabled = ( $downsize[3] || 'full' == $size );
		$css_id = "image-size-{$size}-{$post->ID}";

		// If this size is the default but that's not available, don't select it.
		if ( $size == $check ) {
			if ( $enabled ) {
				$checked = " checked='checked'";
			} else {
				$check = '';
			}
		} elseif ( ! $check && $enabled && 'thumbnail' != $size ) {
			/*
			 * If $check is not enabled, default to the first available size
			 * that's bigger than a thumbnail.
			 */
			$check = $size;
			$checked = " checked='checked'";
		}

		$html = "<div class='image-size-item'><input type='radio' " . disabled( $enabled, false, false ) . "name='attachments[$post->ID][image-size]' id='{$css_id}' value='{$size}'$checked />";

		$html .= "<label for='{$css_id}'>$label</label>";

		// Only show the dimensions if that choice is available.
		if ( $enabled ) {
			$html .= " <label for='{$css_id}' class='help'>" . sprintf( "(%d&nbsp;&times;&nbsp;%d)", $downsize[1], $downsize[2] ). "</label>";
		}
		$html .= '</div>';

		$out[] = $html;
	}

	return array(
		'label' => __( 'Size' ),
		'input' => 'html',
		'html'  => join( "\n", $out ),
	);
}

更新日志

Versiondescription
2.7.0Introduced.

相关函数

Uses

  • wp-admin/includes/media.php: image_size_names_choose
  • wp-includes/l10n.php: __()
  • wp-includes/general-template.php: disabled()
  • wp-includes/plugin.php: apply_filters()
  • wp-includes/option.php: get_user_setting()
  • wp-includes/media.php: image_downsize()
  • Show 1 more use Hide more uses

Used By

  • wp-admin/includes/media.php: get_attachment_fields_to_edit()

User Contributed Notes

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

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

发布评论

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