Media: add a new image size, medium_large
. Bumps db version to add new options.
Adds unit tests. Props DH-Shredder, joemcgill, azaozz. Fixes #34196. git-svn-id: https://develop.svn.wordpress.org/trunk@35479 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
d944108b13
commit
bd7bf83886
@ -506,6 +506,10 @@ function populate_options() {
|
||||
// 4.3.0
|
||||
'finished_splitting_shared_terms' => 1,
|
||||
'site_icon' => 0,
|
||||
|
||||
// 4.4.0
|
||||
'medium_large_size_w' => 768,
|
||||
'medium_large_size_h' => 0,
|
||||
);
|
||||
|
||||
// 3.3
|
||||
|
@ -84,7 +84,7 @@ if ( is_multisite() && ! is_super_admin() && 'update' != $action ) {
|
||||
$whitelist_options = array(
|
||||
'general' => array( 'blogname', 'blogdescription', 'gmt_offset', 'date_format', 'time_format', 'timezone_string', 'WPLANG' ),
|
||||
'discussion' => array( 'default_pingback_flag', 'default_ping_status', 'default_comment_status', 'comments_notify', 'moderation_notify', 'comment_moderation', 'require_name_email', 'comment_whitelist', 'comment_max_links', 'moderation_keys', 'blacklist_keys', 'show_avatars', 'avatar_rating', 'avatar_default', 'close_comments_for_old_posts', 'close_comments_days_old', 'thread_comments', 'thread_comments_depth', 'page_comments', 'comments_per_page', 'default_comments_page', 'comment_order', 'comment_registration' ),
|
||||
'media' => array( 'thumbnail_size_w', 'thumbnail_size_h', 'thumbnail_crop', 'medium_size_w', 'medium_size_h', 'large_size_w', 'large_size_h', 'image_default_size', 'image_default_align', 'image_default_link_type' ),
|
||||
'media' => array( 'thumbnail_size_w', 'thumbnail_size_h', 'thumbnail_crop', 'medium_size_w', 'medium_size_h', 'medium_large_size_w', 'medium_large_size_h', 'large_size_w', 'large_size_h', 'image_default_size', 'image_default_align', 'image_default_link_type' ),
|
||||
'reading' => array( 'posts_per_page', 'posts_per_rss', 'rss_use_excerpt', 'show_on_front', 'page_on_front', 'page_for_posts', 'blog_public' ),
|
||||
'writing' => array( 'default_category', 'default_email_category', 'default_link_category', 'default_post_format' )
|
||||
);
|
||||
|
@ -212,7 +212,7 @@ class WP_Image_Editor_GD extends WP_Image_Editor {
|
||||
* @access public
|
||||
*
|
||||
* @param array $sizes {
|
||||
* An array of image size arrays. Default sizes are 'small', 'medium', 'large'.
|
||||
* An array of image size arrays. Default sizes are 'small', 'medium', 'medium_large', 'large'.
|
||||
*
|
||||
* Either a height or width must be provided.
|
||||
* If one of the two is set to null, the resize will
|
||||
|
@ -270,7 +270,7 @@ class WP_Image_Editor_Imagick extends WP_Image_Editor {
|
||||
* @access public
|
||||
*
|
||||
* @param array $sizes {
|
||||
* An array of image size arrays. Default sizes are 'small', 'medium', 'large'.
|
||||
* An array of image size arrays. Default sizes are 'small', 'medium', 'medium_large', 'large'.
|
||||
*
|
||||
* Either a height or width must be provided.
|
||||
* If one of the two is set to null, the resize will
|
||||
|
@ -513,6 +513,16 @@ class wp_xmlrpc_server extends IXR_Server {
|
||||
'readonly' => false,
|
||||
'option' => 'medium_size_h'
|
||||
),
|
||||
'medium_large_size_w' => array(
|
||||
'desc' => __( 'Medium-Large size image width' ),
|
||||
'readonly' => false,
|
||||
'option' => 'medium_large_size_w'
|
||||
),
|
||||
'medium_large_size_h' => array(
|
||||
'desc' => __( 'Medium-Large size image height' ),
|
||||
'readonly' => false,
|
||||
'option' => 'medium_large_size_h'
|
||||
),
|
||||
'large_size_w' => array(
|
||||
'desc' => __( 'Large size image width' ),
|
||||
'readonly' => false,
|
||||
|
@ -3662,6 +3662,8 @@ function sanitize_option( $option, $value ) {
|
||||
case 'thumbnail_size_h':
|
||||
case 'medium_size_w':
|
||||
case 'medium_size_h':
|
||||
case 'medium_large_size_w':
|
||||
case 'medium_large_size_h':
|
||||
case 'large_size_w':
|
||||
case 'large_size_h':
|
||||
case 'mailserver_port':
|
||||
|
@ -14,7 +14,7 @@
|
||||
* The `$size` parameter accepts either an array or a string. The supported string
|
||||
* values are 'thumb' or 'thumbnail' for the given thumbnail size or defaults at
|
||||
* 128 width and 96 height in pixels. Also supported for the string value is
|
||||
* 'medium' and 'full'. The 'full' isn't actually supported, but any value other
|
||||
* 'medium', 'medium_large' and 'full'. The 'full' isn't actually supported, but any value other
|
||||
* than the supported will result in the content_width size or 500 if that is
|
||||
* not set.
|
||||
*
|
||||
@ -60,7 +60,15 @@ function image_constrain_size_for_editor( $width, $height, $size = 'medium', $co
|
||||
elseif ( $size == 'medium' ) {
|
||||
$max_width = intval(get_option('medium_size_w'));
|
||||
$max_height = intval(get_option('medium_size_h'));
|
||||
// if no width is set, default to the theme content width if available
|
||||
|
||||
}
|
||||
elseif ( $size == 'medium_large' ) {
|
||||
$max_width = intval( get_option( 'medium_large_size_w' ) );
|
||||
$max_height = intval( get_option( 'medium_large_size_h' ) );
|
||||
|
||||
if ( intval( $content_width ) > 0 ) {
|
||||
$max_width = min( intval( $content_width ), $max_width );
|
||||
}
|
||||
}
|
||||
elseif ( $size == 'large' ) {
|
||||
/*
|
||||
@ -71,8 +79,9 @@ function image_constrain_size_for_editor( $width, $height, $size = 'medium', $co
|
||||
*/
|
||||
$max_width = intval(get_option('large_size_w'));
|
||||
$max_height = intval(get_option('large_size_h'));
|
||||
if ( intval($content_width) > 0 )
|
||||
if ( intval($content_width) > 0 ) {
|
||||
$max_width = min( intval($content_width), $max_width );
|
||||
}
|
||||
} elseif ( isset( $_wp_additional_image_sizes ) && count( $_wp_additional_image_sizes ) && in_array( $size, array_keys( $_wp_additional_image_sizes ) ) ) {
|
||||
$max_width = intval( $_wp_additional_image_sizes[$size]['width'] );
|
||||
$max_height = intval( $_wp_additional_image_sizes[$size]['height'] );
|
||||
@ -706,7 +715,7 @@ function image_get_intermediate_size( $post_id, $size = 'thumbnail' ) {
|
||||
*/
|
||||
function get_intermediate_image_sizes() {
|
||||
global $_wp_additional_image_sizes;
|
||||
$image_sizes = array('thumbnail', 'medium', 'large'); // Standard sizes
|
||||
$image_sizes = array('thumbnail', 'medium', 'medium_large', 'large'); // Standard sizes
|
||||
if ( isset( $_wp_additional_image_sizes ) && count( $_wp_additional_image_sizes ) )
|
||||
$image_sizes = array_merge( $image_sizes, array_keys( $_wp_additional_image_sizes ) );
|
||||
|
||||
@ -716,7 +725,7 @@ function get_intermediate_image_sizes() {
|
||||
* @since 2.5.0
|
||||
*
|
||||
* @param array $image_sizes An array of intermediate image sizes. Defaults
|
||||
* are 'thumbnail', 'medium', 'large'.
|
||||
* are 'thumbnail', 'medium', 'medium_large', 'large'.
|
||||
*/
|
||||
return apply_filters( 'intermediate_image_sizes', $image_sizes );
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ $wp_version = '4.4-beta2-35424-src';
|
||||
*
|
||||
* @global int $wp_db_version
|
||||
*/
|
||||
$wp_db_version = 35329;
|
||||
$wp_db_version = 35465;
|
||||
|
||||
/**
|
||||
* Holds the TinyMCE version
|
||||
|
@ -724,6 +724,8 @@ EOF;
|
||||
return array( 150, 150 );
|
||||
case 'medium':
|
||||
return array( 300, 225 );
|
||||
case 'medium_large':
|
||||
return array( 768, 576 );
|
||||
case 'large':
|
||||
return array( 1024, 768 );
|
||||
case 'full':
|
||||
@ -742,11 +744,12 @@ EOF;
|
||||
$uploads_dir_url = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/';
|
||||
|
||||
$expected = $uploads_dir_url . $year_month . '/' . $image_meta['sizes']['medium']['file'] . ' ' . $image_meta['sizes']['medium']['width'] . 'w, ' .
|
||||
$uploads_dir_url . $year_month . '/' . $image_meta['sizes']['medium_large']['file'] . ' ' . $image_meta['sizes']['medium_large']['width'] . 'w, ' .
|
||||
$uploads_dir_url . $year_month . '/' . $image_meta['sizes']['large']['file'] . ' ' . $image_meta['sizes']['large']['width'] . 'w, ' .
|
||||
$uploads_dir_url . $image_meta['file'] . ' ' . $image_meta['width'] . 'w';
|
||||
|
||||
// Set up test cases for all expected size names and a random one.
|
||||
$sizes = array( 'medium', 'large', 'full', 'yoav' );
|
||||
$sizes = array( 'medium', 'medium_large', 'large', 'full', 'yoav' );
|
||||
|
||||
foreach ( $sizes as $size ) {
|
||||
$image_url = wp_get_attachment_image_url( self::$large_id, $size );
|
||||
@ -773,11 +776,12 @@ EOF;
|
||||
$uploads_dir_url = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/';
|
||||
|
||||
$expected = $uploads_dir_url . $image_meta['sizes']['medium']['file'] . ' ' . $image_meta['sizes']['medium']['width'] . 'w, ' .
|
||||
$uploads_dir_url . $image_meta['sizes']['medium_large']['file'] . ' ' . $image_meta['sizes']['medium_large']['width'] . 'w, ' .
|
||||
$uploads_dir_url . $image_meta['sizes']['large']['file'] . ' ' . $image_meta['sizes']['large']['width'] . 'w, ' .
|
||||
$uploads_dir_url . $image_meta['file'] . ' ' . $image_meta['width'] . 'w';
|
||||
|
||||
// Set up test cases for all expected size names and a random one.
|
||||
$sizes = array( 'medium', 'large', 'full', 'yoav' );
|
||||
$sizes = array( 'medium', 'medium_large', 'large', 'full', 'yoav' );
|
||||
|
||||
foreach ( $sizes as $size ) {
|
||||
$size_array = $this->_get_image_size_array_from_name( $size );
|
||||
@ -806,6 +810,7 @@ EOF;
|
||||
$filename_base = basename( $image_meta['file'], '.png' );
|
||||
$image_meta['file'] = str_replace( $filename_base, $filename_base . '-' . $hash, $image_meta['file'] );
|
||||
$image_meta['sizes']['medium']['file'] = str_replace( $filename_base, $filename_base . '-' . $hash, $image_meta['sizes']['medium']['file'] );
|
||||
$image_meta['sizes']['medium_large']['file'] = str_replace( $filename_base, $filename_base . '-' . $hash, $image_meta['sizes']['medium_large']['file'] );
|
||||
$image_meta['sizes']['large']['file'] = str_replace( $filename_base, $filename_base . '-' . $hash, $image_meta['sizes']['large']['file'] );
|
||||
|
||||
// Calculate a srcset array.
|
||||
@ -856,6 +861,8 @@ EOF;
|
||||
|
||||
$expected = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/' . $year_month = date('Y/m') . '/'
|
||||
. $image_meta['sizes']['medium']['file'] . ' ' . $image_meta['sizes']['medium']['width'] . 'w, ';
|
||||
$expected .= 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/' . $year_month = date('Y/m') . '/'
|
||||
. $image_meta['sizes']['medium_large']['file'] . ' ' . $image_meta['sizes']['medium_large']['width'] . 'w, ';
|
||||
$expected .= 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/' . $year_month = date('Y/m') . '/'
|
||||
. $image_meta['sizes']['large']['file'] . ' ' . $image_meta['sizes']['large']['width'] . 'w, ';
|
||||
$expected .= 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/' . $image_meta['file'] . ' ' . $image_meta['width'] .'w';
|
||||
@ -883,7 +890,7 @@ EOF;
|
||||
*/
|
||||
function test_wp_get_attachment_image_sizes() {
|
||||
// Test sizes against the default WP sizes.
|
||||
$intermediates = array( 'thumbnail', 'medium', 'large' );
|
||||
$intermediates = array('thumbnail', 'medium', 'medium_large', 'large');
|
||||
$image_meta = wp_get_attachment_metadata( self::$large_id );
|
||||
|
||||
foreach( $intermediates as $int_size ) {
|
||||
|
@ -35,13 +35,19 @@ class Tests_Post_Attachments extends WP_UnitTestCase {
|
||||
// intermediate copies should not exist
|
||||
$this->assertFalse( image_get_intermediate_size($id, 'thumbnail') );
|
||||
$this->assertFalse( image_get_intermediate_size($id, 'medium') );
|
||||
$this->assertFalse( image_get_intermediate_size($id, 'medium_large') );
|
||||
|
||||
// medium and full size will both point to the original
|
||||
// medium, medium_large, and full size will both point to the original
|
||||
$downsize = image_downsize($id, 'medium');
|
||||
$this->assertEquals( basename( $upload['file'] ), basename($downsize[0]) );
|
||||
$this->assertEquals( 50, $downsize[1] );
|
||||
$this->assertEquals( 50, $downsize[2] );
|
||||
|
||||
$downsize = image_downsize($id, 'medium_large');
|
||||
$this->assertEquals( basename( $upload['file'] ), basename($downsize[0]) );
|
||||
$this->assertEquals( 50, $downsize[1] );
|
||||
$this->assertEquals( 50, $downsize[2] );
|
||||
|
||||
$downsize = image_downsize($id, 'full');
|
||||
$this->assertEquals( basename( $upload['file'] ), basename($downsize[0]) );
|
||||
$this->assertEquals( 50, $downsize[1] );
|
||||
@ -72,6 +78,7 @@ class Tests_Post_Attachments extends WP_UnitTestCase {
|
||||
$this->assertTrue( is_file($uploads['basedir'] . DIRECTORY_SEPARATOR . $thumb['path']) );
|
||||
|
||||
$this->assertFalse( image_get_intermediate_size($id, 'medium') );
|
||||
$this->assertFalse( image_get_intermediate_size($id, 'medium_large') );
|
||||
|
||||
// the thumb url should point to the thumbnail intermediate
|
||||
$this->assertEquals( $thumb['url'], wp_get_attachment_thumb_url($id) );
|
||||
@ -82,12 +89,17 @@ class Tests_Post_Attachments extends WP_UnitTestCase {
|
||||
$this->assertEquals( 150, $downsize[1] );
|
||||
$this->assertEquals( 150, $downsize[2] );
|
||||
|
||||
// medium and full will both point to the original
|
||||
// medium, medium_large, and full will both point to the original
|
||||
$downsize = image_downsize($id, 'medium');
|
||||
$this->assertEquals( 'a2-small.jpg', basename($downsize[0]) );
|
||||
$this->assertEquals( 400, $downsize[1] );
|
||||
$this->assertEquals( 300, $downsize[2] );
|
||||
|
||||
$downsize = image_downsize($id, 'medium_large');
|
||||
$this->assertEquals( 'a2-small.jpg', basename($downsize[0]) );
|
||||
$this->assertEquals( 400, $downsize[1] );
|
||||
$this->assertEquals( 300, $downsize[2] );
|
||||
|
||||
$downsize = image_downsize($id, 'full');
|
||||
$this->assertEquals( 'a2-small.jpg', basename($downsize[0]) );
|
||||
$this->assertEquals( 400, $downsize[1] );
|
||||
@ -95,13 +107,16 @@ class Tests_Post_Attachments extends WP_UnitTestCase {
|
||||
|
||||
}
|
||||
|
||||
function test_insert_image_medium() {
|
||||
function test_insert_image_medium_sizes() {
|
||||
if ( !function_exists( 'imagejpeg' ) )
|
||||
$this->markTestSkipped( 'jpeg support unavailable' );
|
||||
|
||||
update_option('medium_size_w', 400);
|
||||
update_option('medium_size_h', 0);
|
||||
|
||||
update_option('medium_large_size_w', 600);
|
||||
update_option('medium_large_size_h', 0);
|
||||
|
||||
$filename = ( DIR_TESTDATA.'/images/2007-06-17DSC_4173.JPG' );
|
||||
$contents = file_get_contents($filename);
|
||||
|
||||
@ -120,6 +135,10 @@ class Tests_Post_Attachments extends WP_UnitTestCase {
|
||||
$this->assertEquals( '2007-06-17DSC_4173-400x602.jpg', $medium['file'] );
|
||||
$this->assertTrue( is_file($uploads['basedir'] . DIRECTORY_SEPARATOR . $medium['path']) );
|
||||
|
||||
$medium_large = image_get_intermediate_size($id, 'medium_large');
|
||||
$this->assertEquals( '2007-06-17DSC_4173-600x904.jpg', $medium_large['file'] );
|
||||
$this->assertTrue( is_file($uploads['basedir'] . DIRECTORY_SEPARATOR . $medium_large['path']) );
|
||||
|
||||
// the thumb url should point to the thumbnail intermediate
|
||||
$this->assertEquals( $thumb['url'], wp_get_attachment_thumb_url($id) );
|
||||
|
||||
@ -134,6 +153,11 @@ class Tests_Post_Attachments extends WP_UnitTestCase {
|
||||
$this->assertEquals( 400, $downsize[1] );
|
||||
$this->assertEquals( 602, $downsize[2] );
|
||||
|
||||
$downsize = image_downsize($id, 'medium_large');
|
||||
$this->assertEquals( '2007-06-17DSC_4173-600x904.jpg', basename($downsize[0]) );
|
||||
$this->assertEquals( 600, $downsize[1] );
|
||||
$this->assertEquals( 904, $downsize[2] );
|
||||
|
||||
$downsize = image_downsize($id, 'full');
|
||||
$this->assertEquals( '2007-06-17DSC_4173.jpg', basename($downsize[0]) );
|
||||
$this->assertEquals( 680, $downsize[1] );
|
||||
@ -148,6 +172,9 @@ class Tests_Post_Attachments extends WP_UnitTestCase {
|
||||
update_option('medium_size_w', 400);
|
||||
update_option('medium_size_h', 0);
|
||||
|
||||
update_option('medium_large_size_w', 600);
|
||||
update_option('medium_large_size_h', 0);
|
||||
|
||||
$filename = ( DIR_TESTDATA.'/images/2007-06-17DSC_4173.JPG' );
|
||||
$contents = file_get_contents($filename);
|
||||
|
||||
@ -166,6 +193,10 @@ class Tests_Post_Attachments extends WP_UnitTestCase {
|
||||
$this->assertEquals( '2007-06-17DSC_4173-400x602.jpg', $medium['file'] );
|
||||
$this->assertTrue( is_file($uploads['basedir'] . DIRECTORY_SEPARATOR . $medium['path']) );
|
||||
|
||||
$medium_large = image_get_intermediate_size($id, 'medium_large');
|
||||
$this->assertEquals( '2007-06-17DSC_4173-600x904.jpg', $medium_large['file'] );
|
||||
$this->assertTrue( is_file($uploads['basedir'] . DIRECTORY_SEPARATOR . $medium_large['path']) );
|
||||
|
||||
$meta = wp_get_attachment_metadata($id);
|
||||
$original = $meta['file'];
|
||||
$this->assertTrue( is_file($uploads['basedir'] . DIRECTORY_SEPARATOR . $original) );
|
||||
@ -175,6 +206,7 @@ class Tests_Post_Attachments extends WP_UnitTestCase {
|
||||
|
||||
$this->assertFalse( is_file($thumb['path']) );
|
||||
$this->assertFalse( is_file($medium['path']) );
|
||||
$this->assertFalse( is_file($medium_large['path']) );
|
||||
$this->assertFalse( is_file($original) );
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user