Skip to content

Instantly share code, notes, and snippets.

@studiograsshopper
Created October 9, 2011 14:13
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save studiograsshopper/1273733 to your computer and use it in GitHub Desktop.
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
Copy link
Author

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