Make WordPress Core

Changeset 58447

Timestamp:
06/20/2024 04:02:10 PM (7 weeks ago)
Author:
adamsilverstein
Message:

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.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php

    r58130 r58447  
    305305        $attachment->guid           = $url;
    306306
     307
     308
     309
     310
     311
     312
     313
     314
     315
     316
     317
    307318        if ( empty( $attachment->post_title ) ) {
    308319            $attachment->post_title = preg_replace( '/\.[^.]+$/', '', wp_basename( $file ) );
  • trunk/tests/phpunit/tests/rest-api/rest-attachments-controller.php

    r58400 r58447  
    20162016
    20172017    /**
     2018
     2019
     2020
     2021
     2022
     2023
     2024
     2025
     2026
     2027
     2028
     2029
     2030
     2031
     2032
     2033
     2034
     2035
     2036
     2037
     2038
     2039
     2040
     2041
     2042
     2043
     2044
     2045
     2046
     2047
     2048
     2049
     2050
     2051
     2052
     2053
     2054
     2055
     2056
     2057
     2058
     2059
     2060
     2061
     2062
     2063
     2064
     2065
     2066
     2067
     2068
     2069
     2070
     2071
    20182072     * Ensure the `rest_after_insert_attachment` and `rest_insert_attachment` hooks only fire
    20192073     * once when attachments are updated.
Note: See TracChangeset for help on using the changeset viewer.