Make WordPress Core

Changes between Initial Version and Version 1 of Ticket #37989, comment 11


Ignore:
Timestamp:
09/27/2016 03:17:32 AM (9 years ago)
Author:
SergeyBiryukov
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #37989, comment 11

    initial v1  
    11A workaround:
    22{{{
    3 function wp37989_fix_encoded_attachment_titles( $data, $postarr ) {
    4         $basename = pathinfo( $postarr['file'], PATHINFO_BASENAME );
     3function wp37989_fix_encoded_attachment_titles( $data ) {
     4        if ( empty( $_FILES ) ) {
     5                return $data;
     6        }
    57
    6         $data['post_title'] = sanitize_text_field( $basename );
     8        $file = current( $_FILES );
     9        $ext  = pathinfo( $file['name'], PATHINFO_EXTENSION );
     10        $name = wp_basename( $file['name'], ".$ext" );
     11
     12        $data['post_title'] = sanitize_text_field( $name );
    713
    814        return $data;
    915}
    10 add_filter( 'wp_insert_attachment_data', 'wp37989_fix_encoded_attachment_titles', 10, 2 );
     16add_filter( 'wp_insert_attachment_data', 'wp37989_fix_encoded_attachment_titles' );
    1117}}}