Skip to content

Commit 692a5b1

Browse files
committed
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. git-svn-id: https://develop.svn.wordpress.org/trunk@60916 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 2de7ed3 commit 692a5b1

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

src/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1022,7 +1022,7 @@ protected function prepare_links( $post ) {
10221022
$post = get_post( $post->post_parent );
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,
10281028
'post_type' => $post->post_type,

tests/phpunit/tests/rest-api/rest-attachments-controller.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1887,13 +1887,13 @@ public function test_links_contain_parent() {
18871887

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

18991899
public function test_publish_action_ldo_not_registered() {

0 commit comments

Comments
 (0)