WORDPRESS: Retrieve image size radio buttons with the specified one checked


// function to retrieve image size radio buttons with the specified one checked

//used to retrieve the image size
$check = get_user_setting(‘imgsize’, ‘medium’);
//end

function image_size_input_fields( $post, $check = ” ) {

// get a list of the actual pixel dimensions of each possible intermediate version of this image
$size_names = apply_filters( ‘image_size_names_choose’, array(‘thumbnail’ => __(‘Thumbnail’), ‘medium’ => __(‘Medium’), ‘large’ => __(‘Large’), ‘full’ => __(‘Full Size’), ‘medium22′ => __(‘Medium22′)) );

if ( empty($check) )
$check = get_user_setting(‘imgsize’, ‘medium’);

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 = ”

ID][image-size]‘ id=’{$css_id}’ value=’{$size}’$checked />”;

$html .= “$label”;
// only show the dimensions if that choice is available
if ( $enabled )
$html .= ” ” . sprintf( “(%d × %d)”, $downsize[1], $downsize[2] ). “”;

$html .= ‘

‘;

$out[] = $html;
}

return array(
‘label’ => __(‘Size’),
‘input’ => ‘html’,
‘html’ => join(“\n”, $out),
);
}

About these ads

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s