I’ve implemented media uploader to my custom category image plugin and was wondering can I somehow force it use my custom image size I’ve set only for categories.
… So in screen shot above, I’d like Size column only contain “Category Image (80 x 80)” and automatically be selected.
The way I’ve added that ‘Category Image’ to the list is shown below
add_filter( 'image_size_names_choose', 'custom_image_sizes_choose' );
function custom_image_sizes_choose( $sizes ) {
$custom_sizes = array(
'category-image' => 'Category Image'
);
return array_merge( $sizes, $custom_sizes );
}
If in that function I only return $custom_sizes
it will affect every media uploader context, eg. Posts->Add Media, and not only when setting up my category image.
Here’s how I’ve implemented Media Uploader in my plugin
add_action( 'admin_init', 'cat_image_options_setup' );
//------------------------------------------------
// Setup category image media picker
//------------------------------------------------
function cat_image_options_setup() {
global $pagenow;
if ( 'media-upload.php' == $pagenow || 'async-upload.php' == $pagenow ) {
// Now we'll replace the 'Insert into Post Button inside Thickbox'
add_filter( 'gettext', 'replace_thickbox_text' , 1, 2 );
}
}
//------------------------------------------------
// Replace the media picker button text
//------------------------------------------------
function replace_thickbox_text( $translated_text, $text ) {
if ( 'Insert into Post' == $text ) {
$referer = strpos( wp_get_referer(), 'cat_image_settings' );
if ( $referer != '' ) {
return __( 'Add as a category image', 'ddr' );
}
}
return $translated_text;
}
Any way to achieve that? Thanks!
PS. If someone knows better way to implement that media uploader, please let me know. Now it somehow uses the old media uploader window, and not the same as in Posts->Add Media.