Telanjang dengan saya. Saya ingin memiliki ukuran gambar khusus dipilih secara default di halaman popup Upload media. Di Wordpress v3.4.2 dan sebelumnya, kode elegan ini berfungsi dengan baik:
function my_insert_custom_image_sizes( $sizes ) {
// get the custom image sizes
global $_wp_additional_image_sizes;
// if there are none, just return the built-in sizes
if ( empty( $_wp_additional_image_sizes ) )
return $sizes;
// add all the custom sizes to the built-in sizes
foreach ( $_wp_additional_image_sizes as $id => $data ) {
// take the size ID (e.g., 'my-name'), replace hyphens with spaces,
// and capitalise the first letter of each word
if ( !isset($sizes[$id]) )
$sizes[$id] = ucfirst( str_replace( '-', ' ', $id ) );
}
return $sizes;
}
// Which custom image size selected by default
function my_set_default_image_size () {
return 'custom-image-size-2';
}
function custom_image_setup () {
add_theme_support( 'post-thumbnails' );
add_image_size( 'custom-image-size-1', 160, 9999 ); // columned
add_image_size( 'custom-image-size-2', 300, 9999 ); // medium
add_image_size( 'custom-image-size-3', 578, 190, true ); // cropped
add_filter( 'image_size_names_choose', 'my_insert_custom_image_sizes' );
add_filter( 'pre_option_image_default_size', 'my_set_default_image_size' );
}
add_action( 'after_setup_theme', 'custom_image_setup' );
Jadi, my_insert_custom_image_sizes
tambahkan gambar khusus ke halaman media dan my_set_default_image_size
harus memilih custom-image-size-2
ukuran. Kode ini berhenti bekerja dengan versi Wordpress 3.5. Apakah Anda tahu bagaimana saya bisa menyelesaikan ini di v3.5?