WordPress.org

Make WordPress Core


Ignore:
Timestamp:
09/06/2013 02:09:07 PM (5 years ago)
Author:
SergeyBiryukov
Message:

Use correct array key for filling the attachment title in image_attachment_fields_to_save(). props pross.
Use wp_basename() to avoid issues with UTF-8 characters.
fixes #25236.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/media.php

    r25083 r25277  
    915915 * @return array
    916916 */
    917 function image_attachment_fields_to_save($post, $attachment) {
    918     if ( substr($post['post_mime_type'], 0, 5) == 'image' ) {
    919         if ( strlen(trim($post['post_title'])) == 0 ) {
    920             $post['post_title'] = preg_replace('/\.\w+$/', '', basename($post['guid']));
    921             $post['errors']['post_title']['errors'][] = __('Empty Title filled from filename.');
     917function image_attachment_fields_to_save( $post, $attachment ) {
     918    if ( substr( $post['post_mime_type'], 0, 5 ) == 'image' ) {
     919        if ( strlen( trim( $post['post_title'] ) ) == 0 ) {
     920            $attachment_url = ( isset( $post['attachment_url'] ) ) ? $post['attachment_url'] : $post['guid'];
     921            $post['post_title'] = preg_replace( '/\.\w+$/', '', wp_basename( $attachment_url ) );
     922            $post['errors']['post_title']['errors'][] = __( 'Empty Title filled from filename.' );
    922923        }
    923924    }
     
    926927}
    927928
    928 add_filter('attachment_fields_to_save', 'image_attachment_fields_to_save', 10, 2);
     929add_filter( 'attachment_fields_to_save', 'image_attachment_fields_to_save', 10, 2 );
    929930
    930931/**
Note: See TracChangeset for help on using the changeset viewer.