Make WordPress Core

Changeset 39713


Ignore:
Timestamp:
01/05/2017 04:15:58 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.3 branch.

Fixes #37989.

Location:
branches/4.3
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/4.3

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

    r38542 r39713  
    281281    $type = $file['type'];
    282282    $file = $file['file'];
    283     $title = sanitize_title( $name );
     283    $title = sanitize_text_field( $name );
    284284    $content = '';
    285285    $excerpt = '';
  • branches/4.3/tests/phpunit/tests/media.php

    r33506 r39713  
    587587
    588588    /**
     589     * @ticket 37989
     590     */
     591    public function test_media_handle_upload_expected_titles() {
     592        $test_file = DIR_TESTDATA . '/images/test-image.jpg';
     593
     594        // Make a copy of this file as it gets moved during the file upload
     595        $tmp_name = wp_tempnam( $test_file );
     596
     597        copy( $test_file, $tmp_name );
     598
     599        $_FILES['upload'] = array(
     600            'tmp_name' => $tmp_name,
     601            'name'     => 'This is a test.jpg',
     602            'type'     => 'image/jpeg',
     603            'error'    => 0,
     604            'size'     => filesize( $test_file ),
     605        );
     606
     607        $post_id = media_handle_upload( 'upload', 0, array(), array( 'action' => 'test_upload_titles', 'test_form' => false ) );
     608
     609        unset( $_FILES['upload'] );
     610
     611        $post = get_post( $post_id );
     612
     613        // Clean up.
     614        wp_delete_attachment( $post_id );
     615
     616        $this->assertEquals( 'This is a test', $post->post_title );
     617    }
     618
     619    /**
    589620     * @ticket 33016
    590621     */
Note: See TracChangeset for help on using the changeset viewer.