WordPress.org

Make WordPress Core

Changeset 39712


Ignore:
Timestamp:
01/05/2017 04:14:39 PM (3 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.4 branch.

Fixes #37989.

Location:
branches/4.4
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/4.4

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

    r38541 r39712  
    287287    $type = $file['type'];
    288288    $file = $file['file'];
    289     $title = sanitize_title( $name );
     289    $title = sanitize_text_field( $name );
    290290    $content = '';
    291291    $excerpt = '';
  • branches/4.4/tests/phpunit/tests/media.php

    r36152 r39712  
    590590
    591591        $this->assertEquals( 'This is a comment. / Это комментарий. / Βλέπετε ένα σχόλιο.', $post->post_excerpt );
     592    }
     593
     594    /**
     595     * @ticket 37989
     596     */
     597    public function test_media_handle_upload_expected_titles() {
     598        $test_file = DIR_TESTDATA . '/images/test-image.jpg';
     599
     600        // Make a copy of this file as it gets moved during the file upload
     601        $tmp_name = wp_tempnam( $test_file );
     602
     603        copy( $test_file, $tmp_name );
     604
     605        $_FILES['upload'] = array(
     606            'tmp_name' => $tmp_name,
     607            'name'     => 'This is a test.jpg',
     608            'type'     => 'image/jpeg',
     609            'error'    => 0,
     610            'size'     => filesize( $test_file ),
     611        );
     612
     613        $post_id = media_handle_upload( 'upload', 0, array(), array( 'action' => 'test_upload_titles', 'test_form' => false ) );
     614
     615        unset( $_FILES['upload'] );
     616
     617        $post = get_post( $post_id );
     618
     619        // Clean up.
     620        wp_delete_attachment( $post_id );
     621
     622        $this->assertEquals( 'This is a test', $post->post_title );
    592623    }
    593624
Note: See TracChangeset for help on using the changeset viewer.