Make WordPress Core

Changeset 39711


Ignore:
Timestamp:
01/05/2017 04:12:50 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.5 branch.

Fixes #37989.

Location:
branches/4.5
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/4.5

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

    r38540 r39711  
    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.5/tests/phpunit/tests/media.php

    r37035 r39711  
    703703
    704704    /**
     705     * @ticket 37989
     706     */
     707    public function test_media_handle_upload_expected_titles() {
     708        $test_file = DIR_TESTDATA . '/images/test-image.jpg';
     709
     710        // Make a copy of this file as it gets moved during the file upload
     711        $tmp_name = wp_tempnam( $test_file );
     712
     713        copy( $test_file, $tmp_name );
     714
     715        $_FILES['upload'] = array(
     716            'tmp_name' => $tmp_name,
     717            'name'     => 'This is a test.jpg',
     718            'type'     => 'image/jpeg',
     719            'error'    => 0,
     720            'size'     => filesize( $test_file ),
     721        );
     722
     723        $post_id = media_handle_upload( 'upload', 0, array(), array( 'action' => 'test_upload_titles', 'test_form' => false ) );
     724
     725        unset( $_FILES['upload'] );
     726
     727        $post = get_post( $post_id );
     728
     729        // Clean up.
     730        wp_delete_attachment( $post_id );
     731
     732        $this->assertEquals( 'This is a test', $post->post_title );
     733    }
     734
     735    /**
    705736     * @ticket 33016
    706737     */
Note: See TracChangeset for help on using the changeset viewer.