[wp-trac] [WordPress Trac] #37989: Unexpected change to media title behavior in WP 4.6.1

WordPress Trac noreply at wordpress.org
Wed Oct 26 20:02:23 UTC 2016


#37989: Unexpected change to media title behavior in WP 4.6.1
--------------------------------------------------+------------------------
 Reporter:  arhenderson63                         |       Owner:  joemcgill
     Type:  defect (bug)                          |      Status:  reopened
 Priority:  normal                                |   Milestone:  4.6.2
Component:  Media                                 |     Version:  4.6.1
 Severity:  major                                 |  Resolution:
 Keywords:  has-patch has-unit-tests fixed-major  |     Focuses:
--------------------------------------------------+------------------------

Comment (by abda53):

 There was an issue I had with the proposed fixed. The fix itself worked,
 but was causing titles to become blank if updating a media item. This was
 because the fix did not account for an empty $postarr['file'] on updates.

 This was my fix

 {{{#!php
 <?php
 function wp37989_fix_encoded_attachment_titles( $data, $postarr )
 {
         if($postarr['file']!='' && $data['post_title']!=''){
                 $show_ext = TRUE;
                 $basename = pathinfo( $postarr['file'], $show_ext ?
 PATHINFO_BASENAME : PATHINFO_FILENAME);
                 $data['post_title'] = preg_replace("/-/", " ",
 sanitize_text_field( $basename ));
         }
         return $data;
 }
 add_filter( 'wp_insert_attachment_data',
 'wp37989_fix_encoded_attachment_titles', 10, 2 );
 }}}

--
Ticket URL: <https://core.trac.wordpress.org/ticket/37989#comment:61>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list