Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
WP Add image sizes to media uploader
<?php
/**
* Filter callback to add image sizes to Media Uploader
*
* WP 3.3 pre-beta adds a new filter 'image_size_names_choose' to
* the list of image sizes which are displayed in the Media Uploader after an image
* has been uploaded.
*
* See image_size_input_fields() in wp-admin/includes/media.php
*
* @uses get_intermediate_image_sizes()
*
* @param $sizes, array of default image sizes (associative array)
* @return $new_sizes, array of all image sizes (associative array)
* @author Ade Walker http://www.studiograsshopper.ch
*/
function sgr_display_image_size_names_muploader($sizes) {
$new_sizes = array();
$added_sizes = get_intermediate_image_sizes();
// $added_sizes is a numeric array, therefore need to convert it
// to associative array, using value for key and value
foreach( $added_sizes as $key => $value) {
$new_sizes[$value] = $value;
}
// This preserves the labels in $sizes, and merges the two arrays
$new_sizes = array_merge( $new_sizes, $sizes );
return $new_sizes;
}
add_filter('image_size_names_choose', 'sgr_display_image_size_names_muploader', 11, 1);
@studiograsshopper

This comment has been minimized.

Copy link
Owner Author

studiograsshopper commented Oct 9, 2011

Tested WP 3.3 pre-beta 2011/10/06

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.