Make WordPress Core

Opened 8 years ago

Closed 8 years ago

#38607 closed enhancement (fixed)

Add `rest_base` to response objects of `wp/v2/taxonomies` and `wp/v2/types` on the REST Api

Reported by: youknowriad's profile youknowriad Owned by: joehoyle's profile joehoyle
Milestone: 4.7 Priority: normal
Severity: normal Version: 4.7
Component: REST API Keywords: has-patch has-unit-tests
Focuses: rest-api Cc:

Description

As noted by @jnylen0 on this ticket https://core.trac.wordpress.org/ticket/38439#comment:8 currently there's not a way to programmatically link the taxonomy parameters to the term endpoints or the post type items to the corresponding post endpoints.

This ticket aims to add the rest_base attribute to the corresponding endpoints.

Attachments (4)

rest-base.patch (5.3 KB) - added by youknowriad 8 years ago.
Proposed patch
post-type-links.patch (2.4 KB) - added by youknowriad 8 years ago.
Links to Post Types
38607.diff (6.2 KB) - added by jnylen0 8 years ago.
Refreshed patch for rest_base
38607.2.diff (6.8 KB) - added by joehoyle 8 years ago.

Download all attachments as: .zip

Change History (17)

@youknowriad
8 years ago

Proposed patch

#1 @youknowriad
8 years ago

  • Keywords has-patch added

#2 @youknowriad
8 years ago

  • Keywords has-unit-tests added

#3 @rmccue
8 years ago

Previously discussed in https://github.com/WP-API/WP-API/issues/1381

We want to avoid exposing the raw value of rest_base in favour of exposing links that use them. Exposing the raw value encourages manual URL building, but we're trying to heavily encourage using the URLs. This may change based on #38439 however.

#4 @jnylen0
8 years ago

Here's one example of a link that is currently missing:

Once taxonomies are added to post types in #38438 there will be a similar situation, but in reverse: going from a post type in /wp/v2/types to its taxonomies.

Last edited 8 years ago by jnylen0 (previous) (diff)

@youknowriad
8 years ago

Links to Post Types

#5 @youknowriad
8 years ago

Oh! I see. I added a second patch. This time I add a link to post_types on the taxonomy endpoints. @jnylen0 We can do the same on the /types endpoint when we add taxonomies.

#6 @rachelbaker
8 years ago

I am +1 for this. We should return the WP_Post_Type and WP_Taxonomy objects in these responses, and the rest_base property is a part of those objects.

#7 @rachelbaker
8 years ago

@youknowriad @jnylen0 post-type-links.patch looks like it may belong to another ticket?

#8 @jnylen0
8 years ago

The links patch is in response to https://core.trac.wordpress.org/ticket/38607#comment:3:

We want to avoid exposing the raw value of rest_base in favour of exposing links that use them

#9 @jnylen0
8 years ago

Given the decision in #38439, rest_base is no longer useful for building URLs. We should still add it though. Here's another example where it would be useful:

  1. I'm looking at a taxonomy response e.g. /wp/v2/taxonomies/post_tag
  2. I follow the collection link to find some interesting terms in this taxonomy
  3. I want to add one of these terms to a post. Which property name do I use?

In step 3 I want the taxonomy's rest_base, but it's not available. Currently the only way I see to get it is by looking at the last piece of the collection URL.

@jnylen0
8 years ago

Refreshed patch for rest_base

#10 @jnylen0
8 years ago

  • Milestone changed from Awaiting Review to 4.7

38607.diff is rest-base.patch from @youknowriad, refreshed against latest trunk. Let's get this simple and helpful change in 4.7.

@joehoyle
8 years ago

#11 @joehoyle
8 years ago

Updated patch with schema type => string fix, and also used the $base vars to account for rest_base not existing on the post type / taxonomy.

This ticket was mentioned in Slack in #core-restapi by joehoyle. View the logs.


8 years ago

#13 @joehoyle
8 years ago

  • Owner set to joehoyle
  • Resolution set to fixed
  • Status changed from new to closed

In 39191:

REST API: Add rest_base to response objects of wp/v2/taxonomies and wp/v2/types

Though we have the _links.collection available, having this value can be useful to know post type / taxonomy urls if you need to build them another way.

Props youknowriad, jnylen0.
Fixes #38607.

Note: See TracTickets for help on using tickets.