WordPress.org

Make WordPress Core

Changeset 43681


Ignore:
Timestamp:
10/08/2018 06:18:25 PM (2 years ago)
Author:
danielbachhuber
Message:

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.

Props TimothyBlynJacobs.
Fixes #44750.

Location:
branches/5.0
Files:
3 edited

Legend:

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

    r43530 r43681  
    373373        // Wrap the data in a response object.
    374374        $response = rest_ensure_response( $data );
    375         $response->add_links( $links );
     375
     376        foreach ( $links as $rel => $rel_links ) {
     377            foreach ( $rel_links as $link ) {
     378                $response->add_link( $rel, $link['href'], $link['attributes'] );
     379            }
     380        }
    376381
    377382        /**
  • branches/5.0/tests/phpunit/tests/rest-api/rest-attachments-controller.php

    r43530 r43681  
    12611261
    12621262        $this->assertArrayHasKey( 'self', $links );
     1263        $this->assertArrayHasKey( 'author', $links );
     1264
     1265        $this->assertCount( 1, $links['author'] );
     1266        $this->assertArrayHasKey( 'embeddable', $links['author'][0]['attributes'] );
     1267        $this->assertTrue( $links['author'][0]['attributes']['embeddable'] );
    12631268    }
    12641269
  • branches/5.0/tests/qunit/fixtures/wp-api-generated.js

    r43442 r43681  
    39443944            "self": [
    39453945                {
    3946                     "attributes": [],
    39473946                    "href": "http://example.org/index.php?rest_route=/wp/v2/media/8"
    39483947                }
     
    39503949            "collection": [
    39513950                {
    3952                     "attributes": [],
    39533951                    "href": "http://example.org/index.php?rest_route=/wp/v2/media"
    39543952                }
     
    39563954            "about": [
    39573955                {
    3958                     "attributes": [],
    39593956                    "href": "http://example.org/index.php?rest_route=/wp/v2/types/attachment"
    39603957                }
     
    39623959            "replies": [
    39633960                {
    3964                     "attributes": {
    3965                         "embeddable": true
    3966                     },
     3961                    "embeddable": true,
    39673962                    "href": "http://example.org/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=8"
    39683963                }
Note: See TracChangeset for help on using the changeset viewer.