-
Notifications
You must be signed in to change notification settings - Fork 658
Add Embeddable Taxonomy Term Links to the Post Response #1048
Conversation
In v1 the taxonomy terms were included in the Post response, this moves them to embeddable resource links. Any taxonomy that is returned by |
$terms = get_terms( $taxonomy, $prepared_args ); | ||
if ( isset( $request['post'] ) ) { | ||
$post_id = absint( $request['post'] ); | ||
$terms = wp_get_object_terms( $post_id, $taxonomy, $prepared_args ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we validate the taxonomy for the post type?
…th the given taxonomy.
@danielbachhuber db2c077 adds checks to be sure a post exists and that the taxonomy is related to the post. |
|
||
$valid_taxonomies = get_object_taxonomies( $post->post_type ); | ||
if ( in_array( $taxonomy, $valid_taxonomies ) ) { | ||
return $taxonomy; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why isn't this just returning bool
? I don't understand why you'd need $taxonomy
returned when you're passing it in the first place.
@@ -1133,6 +1133,19 @@ protected function prepare_links( $post ) { | |||
); | |||
} | |||
|
|||
$taxonomies = get_object_taxonomies( $post->post_type ); | |||
if ( ! empty( $taxonomies ) ) { | |||
foreach ( $taxonomies as $tax ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to check the taxonomy isn't private. This would benefit from a test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WordPress doesn't have private taxonomies: https://core.trac.wordpress.org/ticket/21949 Related #419
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We still need to check. Otherwise we will be exposing private data.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added in line 1156
Just a few nits. |
I found a big hole in my logic here. I need to check that a user has permission to read a post before we return the terms associated with it. Still a WIP. |
… and get_item methods.
- Renamed method check_valid_taxonomy_for_post to check_post_taxonomy_permission. - Return either a WP_Error or null.
…ost_tag taxonomy.
…am from taxonomy validation.
Includes:
|
* | ||
* @param string $taxonomy | ||
* @param integer $post_id | ||
* @return null|WP_Error |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why return null
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It just returns....what would you do?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True?
@danielbachhuber Both pieces of recent feedback have been addressed in |
Add Embeddable Taxonomy Term Links to the Post Response
Fixes #900
The _links in the Post response now include embeddable references for each object taxonomy.