Make WordPress Core

Changeset 39716


Ignore:
Timestamp:
01/05/2017 04:19: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 4.0 branch.

Fixes #37989.

Location:
branches/4.0
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/4.0

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

    r38545 r39716  
    264264    $type = $file['type'];
    265265    $file = $file['file'];
    266     $title = sanitize_title( $name );
     266    $title = sanitize_text_field( $name );
    267267    $content = '';
    268268
  • branches/4.0/tests/phpunit/tests/media.php

    r33522 r39716  
    440440
    441441    /**
     442     * @ticket 37989
     443     */
     444    public function test_media_handle_upload_expected_titles() {
     445        $test_file = DIR_TESTDATA . '/images/test-image.jpg';
     446
     447        // Make a copy of this file as it gets moved during the file upload
     448        $tmp_name = wp_tempnam( $test_file );
     449
     450        copy( $test_file, $tmp_name );
     451
     452        $_FILES['upload'] = array(
     453            'tmp_name' => $tmp_name,
     454            'name'     => 'This is a test.jpg',
     455            'type'     => 'image/jpeg',
     456            'error'    => 0,
     457            'size'     => filesize( $test_file ),
     458        );
     459
     460        $post_id = media_handle_upload( 'upload', 0, array(), array( 'action' => 'test_upload_titles', 'test_form' => false ) );
     461
     462        unset( $_FILES['upload'] );
     463
     464        $post = get_post( $post_id );
     465
     466        // Clean up.
     467        wp_delete_attachment( $post_id );
     468
     469        $this->assertEquals( 'This is a test', $post->post_title );
     470    }
     471
     472    /**
    442473     * @ticket 33016
    443474     */
Note: See TracChangeset for help on using the changeset viewer.