mirror of
https://github.com/WordPress/WordPress.git
synced 2024-12-22 09:07:59 +01:00
Media: improve titles when inserting via REST API.
Match the naming behavior for uploaded media in the REST API to the way media is named when uploading in the media library. Fix an issue where dashes were replacing spaces unnecessarily. Props abitofmind, kadamwhite, spacedmonkey, adamsilverstein, audrasjb, hellofromTonya. Fixes #57957. Built from https://develop.svn.wordpress.org/trunk@58447 git-svn-id: http://core.svn.wordpress.org/trunk@57896 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
f4989bdf32
commit
ed1f32fac7
@ -304,6 +304,17 @@ class WP_REST_Attachments_Controller extends WP_REST_Posts_Controller {
|
||||
$attachment->post_mime_type = $type;
|
||||
$attachment->guid = $url;
|
||||
|
||||
// If the title was not set, use the original filename.
|
||||
if ( empty( $attachment->post_title ) && ! empty( $files['file']['name'] ) ) {
|
||||
// Remove the file extension (after the last `.`)
|
||||
$tmp_title = substr( $files['file']['name'], 0, strrpos( $files['file']['name'], '.' ) );
|
||||
|
||||
if ( ! empty( $tmp_title ) ) {
|
||||
$attachment->post_title = $tmp_title;
|
||||
}
|
||||
}
|
||||
|
||||
// Fall back to the original approach.
|
||||
if ( empty( $attachment->post_title ) ) {
|
||||
$attachment->post_title = preg_replace( '/\.[^.]+$/', '', wp_basename( $file ) );
|
||||
}
|
||||
|
@ -16,7 +16,7 @@
|
||||
*
|
||||
* @global string $wp_version
|
||||
*/
|
||||
$wp_version = '6.6-beta3-58446';
|
||||
$wp_version = '6.6-beta3-58447';
|
||||
|
||||
/**
|
||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||
|
Loading…
Reference in New Issue
Block a user