Skip to content
This repository has been archived by the owner on Sep 24, 2018. It is now read-only.

Commit

Permalink
Merge pull request #1726 from WP-API/1710-link-relations
Browse files Browse the repository at this point in the history
Change link relations to use api.w.org
  • Loading branch information
danielbachhuber committed Nov 17, 2015
2 parents 1d3be2d + e4a9fec commit ba185d1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
10 changes: 5 additions & 5 deletions lib/endpoints/class-wp-rest-posts-controller.php
Expand Up @@ -1212,22 +1212,22 @@ protected function prepare_links( $post ) {
// If we have a featured image, add that.
if ( $featured_image = get_post_thumbnail_id( $post->ID ) ) {
$image_url = rest_url( 'wp/v2/media/' . $featured_image );
$links['http://v2.wp-api.org/featuredmedia'] = array(
$links['http://api.w.org/featuredmedia'] = array(
'href' => $image_url,
'embeddable' => true,
);
}
if ( ! in_array( $post->post_type, array( 'attachment', 'nav_menu_item', 'revision' ) ) ) {
$attachments_url = rest_url( 'wp/v2/media' );
$attachments_url = add_query_arg( 'post_parent', $post->ID, $attachments_url );
$links['http://v2.wp-api.org/attachment'] = array(
$links['http://api.w.org/attachment'] = array(
'href' => $attachments_url,
);
}

$taxonomies = get_object_taxonomies( $post->post_type );
if ( ! empty( $taxonomies ) ) {
$links['http://v2.wp-api.org/term'] = array();
$links['http://api.w.org/term'] = array();

foreach ( $taxonomies as $tax ) {
$taxonomy_obj = get_taxonomy( $tax );
Expand All @@ -1239,7 +1239,7 @@ protected function prepare_links( $post ) {
$tax_base = ! empty( $taxonomy_obj->rest_base ) ? $taxonomy_obj->rest_base : $tax;
$terms_url = rest_url( trailingslashit( $base ) . $post->ID . '/terms/' . $tax_base );

$links['http://v2.wp-api.org/term'][] = array(
$links['http://api.w.org/term'][] = array(
'href' => $terms_url,
'taxonomy' => $tax,
'embeddable' => true,
Expand All @@ -1248,7 +1248,7 @@ protected function prepare_links( $post ) {
}

if ( post_type_supports( $post->post_type, 'custom-fields' ) ) {
$links['http://v2.wp-api.org/meta'] = array(
$links['http://api.w.org/meta'] = array(
'href' => rest_url( trailingslashit( $base ) . $post->ID . '/meta' ),
'embeddable' => true,
);
Expand Down
4 changes: 2 additions & 2 deletions tests/test-rest-posts-controller.php
Expand Up @@ -165,9 +165,9 @@ public function test_get_item_links() {

$attachments_url = rest_url( '/wp/v2/media' );
$attachments_url = add_query_arg( 'post_parent', $this->post_id, $attachments_url );
$this->assertEquals( $attachments_url, $links['http://v2.wp-api.org/attachment'][0]['href'] );
$this->assertEquals( $attachments_url, $links['http://api.w.org/attachment'][0]['href'] );

$term_links = $links['http://v2.wp-api.org/term'];
$term_links = $links['http://api.w.org/term'];
$tag_link = $cat_link = null;
foreach ( $term_links as $link ) {
if ( 'post_tag' === $link['attributes']['taxonomy'] ) {
Expand Down

0 comments on commit ba185d1

Please sign in to comment.