Make WordPress Core

Changeset 27129


Ignore:
Timestamp:
02/08/2014 12:40:15 AM (10 years ago)
Author:
nacin
Message:

Add remove_image_size() and tests for it and has_image_size(), added in [27128].

props mordauk, markoheijnen.
fixes #26768. see #26951.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/media.php

    r27128 r27129  
    182182
    183183/**
    184  * Registers a new image size
     184 * Register a new image size.
    185185 *
    186186 * @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.
    187192 */
    188193function add_image_size( $name, $width = 0, $height = 0, $crop = false ) {
    189194    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.
    195204 *
    196205 * @since 3.9.0
    197206 *
    198  * @param string $name The image size name.
     207 * @param string $name The image size to check.
    199208 * @return bool True if it exists, false if not.
    200209 */
     
    202211    global $_wp_additional_image_sizes;
    203212
    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 */
     224function 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;
    205233}
    206234
  • trunk/tests/phpunit/tests/media.php

    r27100 r27129  
    407407        $this->assertEquals( $expected, $content );
    408408    }
     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
    409440}
Note: See TracChangeset for help on using the changeset viewer.