Changeset 27129
- Timestamp:
- 02/08/2014 12:40:15 AM (11 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/media.php
r27128 r27129 182 182 183 183 /** 184 * Register s a new image size184 * Register a new image size. 185 185 * 186 186 * @since 2.9.0 187 * 188 * @param string $name The image size name. 189 * @param int $width The image's width. 190 * @param int $height The image's width. 191 * @param bool $width Whether to crop the image to fit the dimensions. Default false. 187 192 */ 188 193 function add_image_size( $name, $width = 0, $height = 0, $crop = false ) { 189 194 global $_wp_additional_image_sizes; 190 $_wp_additional_image_sizes[$name] = array( 'width' => absint( $width ), 'height' => absint( $height ), 'crop' => (bool) $crop ); 191 } 192 193 /** 194 * Check if an image size exists 195 $_wp_additional_image_sizes[ $name ] = array( 196 'width' => absint( $width ), 197 'height' => absint( $height ), 198 'crop' => (bool) $crop, 199 ); 200 } 201 202 /** 203 * Check if an image size exists. 195 204 * 196 205 * @since 3.9.0 197 206 * 198 * @param string $name The image size name.207 * @param string $name The image size to check. 199 208 * @return bool True if it exists, false if not. 200 209 */ … … 202 211 global $_wp_additional_image_sizes; 203 212 204 return isset( $_wp_additional_image_sizes[$name] ); 213 return isset( $_wp_additional_image_sizes[ $name ] ); 214 } 215 216 /** 217 * Remove a new image size. 218 * 219 * @since 3.9.0 220 * 221 * @param string $name The image size to remove. 222 * @return bool True on success, false on failure. 223 */ 224 function remove_image_size( $name ) { 225 global $_wp_additional_image_sizes; 226 227 if ( isset( $_wp_additional_image_sizes[ $name ] ) ) { 228 unset( $_wp_additional_image_sizes[ $name ] ); 229 return true; 230 } 231 232 return false; 205 233 } 206 234 -
trunk/tests/phpunit/tests/media.php
r27100 r27129 407 407 $this->assertEquals( $expected, $content ); 408 408 } 409 410 /** 411 * @ticket 26768 412 */ 413 function test_add_image_size() { 414 global $_wp_additional_image_sizes; 415 $this->assertArrayNotHasKey( 'test-size', $_wp_additional_image_sizes ); 416 add_image_size( 'test-size', 200, 600 ); 417 $this->assertArrayHasKey( 'test-size', $_wp_additional_image_sizes ); 418 $this->assertEquals( 200, $_wp_additional_image_sizes['test-size']['width'] ); 419 $this->assertEquals( 600, $_wp_additional_image_sizes['test-size']['height'] ); 420 } 421 422 /** 423 * @ticket 26768 424 */ 425 function test_remove_image_size() { 426 add_image_size( 'test-size', 200, 600 ); 427 $this->assertTrue( has_image_size( 'test-size' ) ); 428 remove_image_size( 'test-size' ); 429 $this->assertFalse( has_image_size( 'test-size' ) ); 430 } 431 432 /** 433 * @ticket 26951 434 */ 435 function test_has_image_size() { 436 add_image_size( 'test-size', 200, 600 ); 437 $this->assertTrue( has_image_size( 'test-size' ) ); 438 } 439 409 440 }
Note: See TracChangeset
for help on using the changeset viewer.