Created
October 9, 2011 14:13
-
-
Save studiograsshopper/1273733 to your computer and use it in GitHub Desktop.
WP Add image sizes to media uploader
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Tested WP 3.3 pre-beta 2011/10/06