diff --git a/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php b/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php index 97ee830261..dbab4c933e 100644 --- a/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php +++ b/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php @@ -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 ) ); } diff --git a/wp-includes/version.php b/wp-includes/version.php index 4ad3ea0e8c..1b483a2320 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -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.