Advertisement
miriamdepaula

WordPress: Adicionando "custom image sizes" no Midia Upload

Sep 20th, 2011
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.05 KB | None | 0 0
  1. add_filter('attachment_fields_to_edit', 'my_attachment_fields_to_edit_filter', 100, 2);
  2. function my_attachment_fields_to_edit_filter($form_fields, $post) {
  3.   if (!array_key_exists('image-size', $form_fields)) return $form_fields;
  4.  
  5.   global $_wp_additional_image_sizes;
  6.   foreach($_wp_additional_image_sizes as $size => $properties) {
  7.     if ($size == 'post-thumbnail') continue;
  8.  
  9.     $label = ucwords(str_replace('-', ' ', $size));
  10.     $cssID = "image-size-{$size}-{$post->ID}";
  11.  
  12.     $downsize = image_downsize($post->ID, $size);
  13.     $enabled = $downsize[3];
  14.  
  15.     $html = '<input type="radio" ' . disabled($enabled, false, false) . 'name="attachments[' . $post->ID. '][image-size]" id="' . $cssID . '" value="' . $size .'">';
  16.     $html .= '<label for="'. $cssID . '">' . $label . '</label>';
  17.     if ($enabled) $html .= ' <label for="' . $cssID . '" class="help">(' . $downsize[1] . '&nbsp;×&nbsp;' . $downsize[2] . ')</label>';
  18.     $form_fields['image-size']['html'] .= '<div class="image-size-item">' . $html . '</div>';
  19.   }
  20.  
  21.   return $form_fields;
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement