Opened 5 weeks ago
Last modified 5 days ago
#63509 new enhancement
Use proper filename for attachment post title
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Awaiting Review | Priority: | normal |
Severity: | normal | Version: | |
Component: | Media | Keywords: | has-patch |
Focuses: | Cc: |
Description
In media_handle_upload()
function, the file name (and thus, attachment title) is gotten from $_FILES[ $file_id ]['name']
. This is the raw/original file name when uploaded. However, developers can change file name after upload by filtering to sanitize_file_name
or use unique_filename_callback
parameter. This makes the file name (and title) doesn't represent the correct file name after upload.
$name = $_FILES[ $file_id ]['name']; $ext = pathinfo( $name, PATHINFO_EXTENSION ); $name = wp_basename( $name, ".$ext" ); $url = $file['url']; $type = $file['type']; $file = $file['file']; $title = sanitize_text_field( $name );
A simple patch for this is this:
$name = $file['file']; // Get the proper name $ext = pathinfo( $name, PATHINFO_EXTENSION ); $name = wp_basename( $name, ".$ext" );
I tested the patch with classic editor and it works well. However, I haven't figured out for the block editor.
Attachments (1)
Note: See
TracTickets for help on using
tickets.
Patch for use proper file name after upload