image_size_input_fields

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

Description

(array) image_size_input_fields( (WP_Post) $post, (string) $check = '' ); 

Returns (array)

Parameters (2)

0. $post (WP_Post)
The post.
1. $check — Optional. (string) => ''
The check.

Usage

  1. if ( !function_exists( 'image_size_input_fields' ) ) { 
  2. require_once ABSPATH . '/wp-admin/includes/media.php'; 
  3.  
  4. // The post. 
  5. $post = null; 
  6.  
  7. // The check. 
  8. $check = ''; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = image_size_input_fields($post, $check); 
  12.  

Defined (1)

The function is defined in the following location(s).

/wp-admin/includes/media.php  
  1. function image_size_input_fields( $post, $check = '' ) { 
  2. /** 
  3. * Filters the names and labels of the default image sizes. 
  4. * @since 3.3.0 
  5. * @param array $size_names Array of image sizes and their names. Default values 
  6. * include 'Thumbnail', 'Medium', 'Large', 'Full Size'. 
  7. */ 
  8. $size_names = apply_filters( 'image_size_names_choose', array( 
  9. 'thumbnail' => __( 'Thumbnail' ),  
  10. 'medium' => __( 'Medium' ),  
  11. 'large' => __( 'Large' ),  
  12. 'full' => __( 'Full Size' ) 
  13. ) ); 
  14.  
  15. if ( empty( $check ) ) { 
  16. $check = get_user_setting('imgsize', 'medium'); 
  17. $out = array(); 
  18.  
  19. foreach ( $size_names as $size => $label ) { 
  20. $downsize = image_downsize( $post->ID, $size ); 
  21. $checked = ''; 
  22.  
  23. // Is this size selectable? 
  24. $enabled = ( $downsize[3] || 'full' == $size ); 
  25. $css_id = "image-size-{$size}-{$post->ID}"; 
  26.  
  27. // If this size is the default but that's not available, don't select it. 
  28. if ( $size == $check ) { 
  29. if ( $enabled ) { 
  30. $checked = " checked='checked'"; 
  31. } else { 
  32. $check = ''; 
  33. } elseif ( ! $check && $enabled && 'thumbnail' != $size ) { 
  34. /** 
  35. * If $check is not enabled, default to the first available size 
  36. * that's bigger than a thumbnail. 
  37. */ 
  38. $check = $size; 
  39. $checked = " checked='checked'"; 
  40.  
  41. $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 />"; 
  42.  
  43. $html .= "<label for='{$css_id}'>$label</label>"; 
  44.  
  45. // Only show the dimensions if that choice is available. 
  46. if ( $enabled ) { 
  47. $html .= " <label for='{$css_id}' class='help'>" . sprintf( "(%d × %d)", $downsize[1], $downsize[2] ). "</label>"; 
  48. $html .= '</div>'; 
  49.  
  50. $out[] = $html; 
  51.  
  52. return array( 
  53. 'label' => __( 'Size' ),  
  54. 'input' => 'html',  
  55. 'html' => join( "\n", $out ),  
  56. );