Make WordPress Core

Changeset 31239


Ignore:
Timestamp:
01/18/2015 08:32:50 PM (9 years ago)
Author:
SergeyBiryukov
Message:

attachment_url_to_postid() should always return an integer.

props nathan_dawson, ashfame.
fixes #31044.

Location:
trunk
Files:
2 edited

Legend:

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

    r31168 r31239  
    32963296 *
    32973297 * @param string $url The URL to resolve.
    3298  * @return int The found post ID.
     3298 * @return int The found post ID, or 0 on failure.
    32993299 */
    33003300function attachment_url_to_postid( $url ) {
     
    33133313    );
    33143314    $post_id = $wpdb->get_var( $sql );
    3315     if ( ! empty( $post_id ) ) {
    3316         return (int) $post_id;
    3317     }
     3315
     3316    return (int) $post_id;
    33183317}
    33193318
  • trunk/tests/phpunit/tests/media.php

    r31066 r31239  
    502502    }
    503503
     504    /**
     505     * @ticket 31044
     506     */
     507    function test_attachment_url_to_postid_with_empty_url() {
     508        $post_id = attachment_url_to_postid( '' );
     509        $this->assertInternalType( 'int', $post_id );
     510        $this->assertEquals( 0, $post_id );
     511    }
     512
    504513    function test_wp_check_filetype() {
    505514        $url = 'http://example.com/testFile.mp4?autoplay=true&otherstuff=false';
Note: See TracChangeset for help on using the changeset viewer.