Make WordPress Core

Changeset 60916

Timestamp:
10/08/2025 10:49:22 PM (3 days ago)
Author:
andrewserong
Message:

REST API: Rename post link relation in media endpoint to wp:attached-to

By adding the https://api.w.org/ prefix and using a more descriptive name for the link relation, this change creates greater clarity for this part of the API. Note that the renaming of this property is safe, as the API change has not yet made it into a final release.

Follow-up to [60893].

Props andrewserong, mukesh27, ramonopoly, timothyblynjacobs.
Fixes #64034.

Location:
trunk
Files:
2 edited

Legend:

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

    r60908 r60916  
    10231023
    10241024            if ( ! empty( $post ) ) {
    1025                 $links['post'] = array(
     1025                $links['https://api.w.org/attached-to'] = array(
    10261026                    'href'       => rest_url( rest_get_route_for_post( $post ) ),
    10271027                    'embeddable' => true,
  • trunk/tests/phpunit/tests/rest-api/rest-attachments-controller.php

    r60908 r60916  
    18881888        $this->assertArrayHasKey( 'self', $links );
    18891889        $this->assertArrayHasKey( 'author', $links );
    1890         $this->assertArrayHasKey( 'post', $links );
     1890        $this->assertArrayHasKey( 'https://api.w.org/attached-to', $links );
    18911891
    18921892        $this->assertCount( 1, $links['author'] );
    1893         $this->assertSame( rest_url( '/wp/v2/posts/' . $post ), $links['post'][0]['href'] );
    1894         $this->assertSame( 'post', $links['post'][0]['attributes']['post_type'] );
    1895         $this->assertSame( $post, $links['post'][0]['attributes']['id'] );
    1896         $this->assertTrue( $links['post'][0]['attributes']['embeddable'] );
     1893        $this->assertSame( rest_url( '/wp/v2/posts/' . $post ), $links['https://api.w.org/attached-to'][0]['href'] );
     1894        $this->assertSame( 'post', $links['https://api.w.org/attached-to'][0]['attributes']['post_type'] );
     1895        $this->assertSame( $post, $links['https://api.w.org/attached-to'][0]['attributes']['id'] );
     1896        $this->assertTrue( $links['https://api.w.org/attached-to'][0]['attributes']['embeddable'] );
    18971897    }
    18981898
Note: See TracChangeset for help on using the changeset viewer.