Skip to content
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

Implement core style of including revisions data on Post response #7495

Merged
merged 3 commits into from
Jun 25, 2018

Conversation

danielbachhuber
Copy link
Member

Description

Incorporates core pattern of including revisions data on Post response

See https://core.trac.wordpress.org/ticket/44321#comment:9
Fixes #3258

How has this been tested?

  1. Create a new post.
  2. Hit "Save Draft" a couple of times.
  3. See revisions UI in post settings:

image

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • My code has proper inline documentation.

@danielbachhuber danielbachhuber added REST API Interaction Related to REST API [Feature] Saving Related to saving functionality labels Jun 22, 2018
@danielbachhuber danielbachhuber added this to the 3.2 milestone Jun 22, 2018
@danielbachhuber danielbachhuber requested a review from a team June 22, 2018 19:16
lib/rest-api.php Outdated
$new_links = array();
$orig_links = $response->get_links();

if ( in_array( $post->post_type, array( 'post', 'page' ), true ) || post_type_supports( $post->post_type, 'revisions' ) ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we hardcode support for post and page types, rather than letting it follow the same logic of using post_type_supports (since, by default, they do register support)? If it's needed, can we leave an inline comment explaining why?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we hardcode support for post and page types, rather than letting it follow the same logic of using post_type_supports (since, by default, they do register support)?

To "force" Posts and Pages to include the revisions endpoint (even if a developer has removed support via post_type_supports). This was a decision made in the original API design. The conditional is copied directly.

However, this is moot with 874d8b7

lib/rest-api.php Outdated
$revisions_count = count( $revisions );

$new_links['version-history'] = array(
'href' => $orig_href . '/revisions',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a reliable way to generate a revisions API URL ? Could we use WP_REST_Response::get_links to retrieve the original links before removing version-history and just alter (even via remove_link + add_link) the original value to include the count field?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, updated in 874d8b7

lib/rest-api.php Outdated
if ( $revisions_count > 0 ) {
$last_revision = array_shift( $revisions );

$new_links['predecessor'] = array(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per this comment and the referenced RFC, should this be predecessor-version ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be predecessor-version

Yes, corrected in 9823c74

@danielbachhuber danielbachhuber requested a review from a team June 25, 2018 13:49
'count' => $revisions_count,
);

if ( $revisions_count > 0 ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't it be greater than 1? I think we don't render the link if there is only 1 revision.

Yep, confirmed:

if ( ! lastRevisionId || revisionsCount < 2 ) {

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't it be greater than 1? I think we don't render the link if there is only 1 revision.

That's a client specific detail. Seems to me the REST API should provide the raw value (maybe even if it were 0).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assuming it is still a correct url, is fine as is.

$revisions = wp_get_post_revisions( $post->ID, array( 'fields' => 'ids' ) );
$revisions_count = count( $revisions );

$new_links['version-history'] = array(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: If intent is to merge in the count attribute, may be more clear if used array_merge to indicate as such.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$orig_links['version-history'] has a different format and can't be used directly.

@danielbachhuber danielbachhuber merged commit e5e7335 into master Jun 25, 2018
@danielbachhuber danielbachhuber deleted the 3258-revision-data branch June 25, 2018 16:53
oxyc added a commit to generoi/gutenberg that referenced this pull request Jun 26, 2018
* 'master' of https://github.com/WordPress/gutenberg: (69 commits)
  fix: Show permalink editor in editor (WordPress#7494)
  Fix text wrapping in Firefox. (WordPress#7472)
  Try another approach to fixing the sibling inserter in Firefox (WordPress#7530)
  fix: Improve "add block" text in NUX onboarding (WordPress#7511)
  Implement core style of including revisions data on Post response (WordPress#7495)
  Testing: Add e2e test for PluginPostStatusInfo (WordPress#7284)
  Add end 2 end test for sidebar behaviours on mobile and desktop. (WordPress#6877)
  Only save metaboxes when it's not an autosave (WordPress#7502)
  Fix broken links in documentation (WordPress#7532)
  Remove post type 'viewable' compatibility shim (WordPress#7496)
  Fix typo. (WordPress#7528)
  Blocks: Remove wrapping div from paragraph block (WordPress#7477)
  fix: change import for InnerBlocks (WordPress#7484)
  Polish library just a teeeeensy bit (WordPress#7522)
  feat: Add snapshot update script (WordPress#7514)
  Display server error message when one exists (WordPress#7434)
  Fix issues with gallery in IE11. (WordPress#7465)
  Polish region focus style (WordPress#7459)
  Fix IE11 formatting toolbar visibility (WordPress#7413)
  Update plugin version to 3.1. (WordPress#7402)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Saving Related to saving functionality REST API Interaction Related to REST API
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants