Make WordPress Core

Changeset 39719


Ignore:
Timestamp:
01/05/2017 04:25:43 PM (8 years ago)
Author:
joemcgill
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 [38615] to the 3.7 branch.

Fixes #37989.

Location:
branches/3.7
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/3.7

  • branches/3.7/src

  • branches/3.7/src/wp-admin/includes/media.php

    r38548 r39719  
    222222    $type = $file['type'];
    223223    $file = $file['file'];
    224     $title = sanitize_title( $name );
     224    $title = sanitize_text_field( $name );
    225225    $content = '';
    226226
  • branches/3.7/tests/phpunit/tests/media.php

    r33525 r39719  
    349349   
    350350    /**
     351     * @ticket 37989
     352     */
     353    public function test_media_handle_upload_expected_titles() {
     354        $test_file = DIR_TESTDATA . '/images/test-image.jpg';
     355
     356        // Make a copy of this file as it gets moved during the file upload
     357        $tmp_name = wp_tempnam( $test_file );
     358
     359        copy( $test_file, $tmp_name );
     360
     361        $_FILES['upload'] = array(
     362            'tmp_name' => $tmp_name,
     363            'name'     => 'This is a test.jpg',
     364            'type'     => 'image/jpeg',
     365            'error'    => 0,
     366            'size'     => filesize( $test_file ),
     367        );
     368
     369        $post_id = media_handle_upload( 'upload', 0, array(), array( 'action' => 'test_upload_titles', 'test_form' => false ) );
     370
     371        unset( $_FILES['upload'] );
     372
     373        $post = get_post( $post_id );
     374
     375        // Clean up.
     376        wp_delete_attachment( $post_id );
     377
     378        $this->assertEquals( 'This is a test', $post->post_title );
     379    }
     380
     381    /**
    351382     * @ticket 33016
    352383     */
Note: See TracChangeset for help on using the changeset viewer.