Skip to content
This repository was archived by the owner on Sep 24, 2018. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions lib/endpoints/class-wp-json-posts-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ protected function prepare_items_query( $prepared_args = array() ) {
$valid_vars = array_merge( $valid_vars, $private );
}
// Define our own in addition to WP's normal vars
$json_valid = array( 'posts_per_page', 'ignore_sticky_posts' );
$json_valid = array( 'posts_per_page', 'ignore_sticky_posts', 'post_parent' );
$valid_vars = array_merge( $valid_vars, $json_valid );

/**
Expand Down Expand Up @@ -1124,6 +1124,15 @@ protected function prepare_links( $post ) {
);
}

if ( ! in_array( $post->post_type, array( 'attachment', 'nav_menu_item', 'revision' ) ) ) {
$attachments_url = json_url( 'wp/media' );
$attachments_url = add_query_arg( 'post_parent', $post->ID, $attachments_url );
$links['attachments'] = array(
'href' => $attachments_url,
'embeddable' => true,
);
}

return $links;
}

Expand Down Expand Up @@ -1337,7 +1346,6 @@ public function get_item_schema() {
break;

}

}

if ( 'post' === $this->post_type ) {
Expand Down
4 changes: 4 additions & 0 deletions tests/test-json-posts-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ public function test_get_item_links() {
$this->assertEquals( $replies_url, $links['replies'][0]['href'] );

$this->assertEquals( json_url( '/wp/posts/' . $this->post_id . '/revisions' ), $links['version-history'][0]['href'] );

$attachments_url = json_url( 'wp/media' );
$attachments_url = add_query_arg( 'post_parent', $this->post_id, $attachments_url );
$this->assertEquals( $attachments_url, $links['attachments'][0]['href'] );
}

public function test_get_post_without_permission() {
Expand Down