Make WordPress Core

Changeset 39714


Ignore:
Timestamp:
01/05/2017 04:16:55 PM (10 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.2 branch.

Fixes #37989.

Location:
branches/4.2
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/4.2

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

    r38543 r39714  
    279279        $type = $file['type'];
    280280        $file = $file['file'];
    281         $title = sanitize_title( $name );
     281        $title = sanitize_text_field( $name );
    282282        $content = '';
    283283        $excerpt = '';
  • branches/4.2/tests/phpunit/tests/media.php

    r33518 r39714  
    561561
    562562        /**
     563         * @ticket 37989
     564         */
     565        public function test_media_handle_upload_expected_titles() {
     566                $test_file = DIR_TESTDATA . '/images/test-image.jpg';
     567
     568                // Make a copy of this file as it gets moved during the file upload
     569                $tmp_name = wp_tempnam( $test_file );
     570
     571                copy( $test_file, $tmp_name );
     572
     573                $_FILES['upload'] = array(
     574                        'tmp_name' => $tmp_name,
     575                        'name'     => 'This is a test.jpg',
     576                        'type'     => 'image/jpeg',
     577                        'error'    => 0,
     578                        'size'     => filesize( $test_file ),
     579                );
     580
     581                $post_id = media_handle_upload( 'upload', 0, array(), array( 'action' => 'test_upload_titles', 'test_form' => false ) );
     582
     583                unset( $_FILES['upload'] );
     584
     585                $post = get_post( $post_id );
     586
     587                // Clean up.
     588                wp_delete_attachment( $post_id );
     589
     590                $this->assertEquals( 'This is a test', $post->post_title );
     591        }
     592
     593        /**
    563594         * @ticket 33016
    564595         */
Note: See TracChangeset for help on using the changeset viewer.