WordPress.org

Make WordPress Core

Changeset 38615


Ignore:
Timestamp:
09/17/16 06:26:36 (8 months ago)
Author:
aaroncampbell
Message:

Media: Improved media titles when created from filename.

Preserves spaces and generally creates more accurate, cleaner titles from filenames of uploaded media.

Merge of [38614] to the 4.6 branch.

Props joemcgill.
Fixes #37989.

Location:
branches/4.6
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/4.6/src/wp-admin/includes/media.php

    r38539 r38615  
    291291    $type = $file['type']; 
    292292    $file = $file['file']; 
    293     $title = sanitize_title( $name ); 
     293    $title = sanitize_text_field( $name ); 
    294294    $content = ''; 
    295295    $excerpt = ''; 
  • branches/4.6/tests/phpunit/tests/media.php

    r38052 r38615  
    774774 
    775775    /** 
     776     * @ticket 37989 
     777     */ 
     778    public function test_media_handle_upload_expected_titles() { 
     779        $test_file = DIR_TESTDATA . '/images/test-image.jpg'; 
     780 
     781        // Make a copy of this file as it gets moved during the file upload 
     782        $tmp_name = wp_tempnam( $test_file ); 
     783 
     784        copy( $test_file, $tmp_name ); 
     785 
     786        $_FILES['upload'] = array( 
     787            'tmp_name' => $tmp_name, 
     788            'name'     => 'This is a test.jpg', 
     789            'type'     => 'image/jpeg', 
     790            'error'    => 0, 
     791            'size'     => filesize( $test_file ), 
     792        ); 
     793 
     794        $post_id = media_handle_upload( 'upload', 0, array(), array( 'action' => 'test_upload_titles', 'test_form' => false ) ); 
     795 
     796        unset( $_FILES['upload'] ); 
     797 
     798        $post = get_post( $post_id ); 
     799 
     800        // Clean up. 
     801        wp_delete_attachment( $post_id ); 
     802 
     803        $this->assertEquals( 'This is a test', $post->post_title ); 
     804    } 
     805 
     806    /** 
    776807     * @ticket 33016 
    777808     */ 
Note: See TracChangeset for help on using the changeset viewer.