REST API: Persist attributes for attachment links

In [43437], the link definition implementation caused attachment links to be unexpectedly nested under an attributes key. This changeset restores the prior behavior.

Merges [43681] to trunk.

Props TimothyBlynJacobs, danielbachhuber.
Fixes #44750.


git-svn-id: https://develop.svn.wordpress.org/trunk@43973 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Aaron Jorbin 2018-12-11 04:00:37 +00:00
parent 5d92e0c0a9
commit 891394af73
6 changed files with 15 additions and 10 deletions

2
package-lock.json generated
View File

@ -1,6 +1,6 @@
{
"name": "WordPress",
"version": "5.0.0",
"version": "5.1.0",
"lockfileVersion": 1,
"requires": true,
"dependencies": {

View File

@ -1256,7 +1256,7 @@ function do_accordion_sections( $screen, $context, $object ) {
$page = $screen->id;
$hidden = get_hidden_meta_boxes( $screen );
$hidden = get_hidden_meta_boxes( $screen );
?>
<div id="side-sortables" class="accordion-container">
<ul class="outer-border">

View File

@ -96,7 +96,7 @@ function wp_underscore_video_template() {
<# if ( w ) { #>width="{{ w }}"<# } #>
<# if ( h ) { #>height="{{ h }}"<# } #>
<?php
$props = array(
$props = array(
'poster' => '',
'preload' => 'metadata',
);

View File

@ -375,7 +375,12 @@ class WP_REST_Attachments_Controller extends WP_REST_Posts_Controller {
// Wrap the data in a response object.
$response = rest_ensure_response( $data );
$response->add_links( $links );
foreach ( $links as $rel => $rel_links ) {
foreach ( $rel_links as $link ) {
$response->add_link( $rel, $link['href'], $link['attributes'] );
}
}
/**
* Filters an attachment returned from the REST API.

View File

@ -1467,6 +1467,11 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control
$links = $response->get_links();
$this->assertArrayHasKey( 'self', $links );
$this->assertArrayHasKey( 'author', $links );
$this->assertCount( 1, $links['author'] );
$this->assertArrayHasKey( 'embeddable', $links['author'][0]['attributes'] );
$this->assertTrue( $links['author'][0]['attributes']['embeddable'] );
}
public function test_publish_action_ldo_not_registered() {

View File

@ -4079,27 +4079,22 @@ mockedApiResponse.MediaCollection = [
"_links": {
"self": [
{
"attributes": [],
"href": "http://example.org/index.php?rest_route=/wp/v2/media/8"
}
],
"collection": [
{
"attributes": [],
"href": "http://example.org/index.php?rest_route=/wp/v2/media"
}
],
"about": [
{
"attributes": [],
"href": "http://example.org/index.php?rest_route=/wp/v2/types/attachment"
}
],
"replies": [
{
"attributes": {
"embeddable": true
},
"embeddable": true,
"href": "http://example.org/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=8"
}
]