Repository navigation
REST API: Accept a post object in the global styles controller's prepare_links() #15826
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
20efbb1
350f893
8d7f744
993719f
509c84f
81990dc
80f20b7
874f374
c2c4d3a
204f7fe
f90036b
8dcc17b
887706a
cc16935
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -359,6 +359,7 @@ public function prepare_item_for_response( $post, $request ) { | |
| $response = rest_ensure_response( $data ); | ||
|
|
||
| if ( rest_is_field_included( '_links', $fields ) || rest_is_field_included( '_embedded', $fields ) ) { | ||
| // The ID is passed on purpose, since subclasses that override prepare_links() may expect an ID rather than a post object. | ||
| $links = $this->prepare_links( $post->ID ); | ||
|
|
||
| // Only return resolved URIs for get requests to user theme JSON. | ||
|
|
@@ -387,11 +388,19 @@ public function prepare_item_for_response( $post, $request ) { | |
| * | ||
| * @since 5.9.0 | ||
| * @since 6.3.0 Adds revisions count and rest URL href to version-history. | ||
| * @since 7.2.0 Accepts a post object, matching the parent method. | ||
| * | ||
| * @param int $id ID. | ||
| * @return array Links for the given post. | ||
| * @param WP_Post|int $post Post object or ID. | ||
| * @return array<string, array<string, string|int>> Links for the given post. | ||
| * | ||
| * @phpstan-return array{ | ||
| * self: array{ href: non-falsy-string }, | ||
| * about: array{ href: non-falsy-string }, | ||
| * version-history?: array{ href: non-falsy-string, count: int<0, max> }, | ||
| * } | ||
| */ | ||
| protected function prepare_links( $id ) { | ||
| protected function prepare_links( $post ) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit:
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, good point.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added in 887706a |
||
| $id = $post instanceof WP_Post ? $post->ID : $post; | ||
| $base = sprintf( '%s/%s', $this->namespace, $this->rest_base ); | ||
|
|
||
| $links = array( | ||
|
|
@@ -404,7 +413,7 @@ protected function prepare_links( $id ) { | |
| ); | ||
|
|
||
| if ( post_type_supports( $this->post_type, 'revisions' ) ) { | ||
| $revisions = wp_get_latest_revision_id_and_total_count( $id ); | ||
| $revisions = wp_get_latest_revision_id_and_total_count( $post ); | ||
| $revisions_count = ! is_wp_error( $revisions ) ? $revisions['count'] : 0; | ||
| $revisions_base = sprintf( '/%s/%d/revisions', $base, $id ); | ||
| $links['version-history'] = array( | ||
|
|
||
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.
This also changes what
found_postsfilter callbacks receive whenfound_posts_queryreturns a negative number: they now get0. Unlikely in practice, but maybe the@since 7.2.0note on the filter could mention this too, not just the clamped return value?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 887706a