From 897ddbd76c8ddfa4f45770ba63a61e5103848dba Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Fri, 6 Sep 2013 14:10:09 +0000 Subject: [PATCH] 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. Built from https://develop.svn.wordpress.org/trunk@25277 git-svn-id: http://core.svn.wordpress.org/trunk@25242 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/includes/media.php | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/wp-admin/includes/media.php b/wp-admin/includes/media.php index b76bac209a..7b976df54e 100644 --- a/wp-admin/includes/media.php +++ b/wp-admin/includes/media.php @@ -914,18 +914,19 @@ function media_post_single_attachment_fields_to_edit( $form_fields, $post ) { * @param array $attachment {@internal $attachment not used}} * @return array */ -function image_attachment_fields_to_save($post, $attachment) { - if ( substr($post['post_mime_type'], 0, 5) == 'image' ) { - if ( strlen(trim($post['post_title'])) == 0 ) { - $post['post_title'] = preg_replace('/\.\w+$/', '', basename($post['guid'])); - $post['errors']['post_title']['errors'][] = __('Empty Title filled from filename.'); +function image_attachment_fields_to_save( $post, $attachment ) { + if ( substr( $post['post_mime_type'], 0, 5 ) == 'image' ) { + if ( strlen( trim( $post['post_title'] ) ) == 0 ) { + $attachment_url = ( isset( $post['attachment_url'] ) ) ? $post['attachment_url'] : $post['guid']; + $post['post_title'] = preg_replace( '/\.\w+$/', '', wp_basename( $attachment_url ) ); + $post['errors']['post_title']['errors'][] = __( 'Empty Title filled from filename.' ); } } return $post; } -add_filter('attachment_fields_to_save', 'image_attachment_fields_to_save', 10, 2); +add_filter( 'attachment_fields_to_save', 'image_attachment_fields_to_save', 10, 2 ); /** * {@internal Missing Short Description}}