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

WIP REST API: Add revision count and links to template parts #3476

Closed
wants to merge 1 commit into from

Conversation

georgeh
Copy link

@georgeh georgeh commented Oct 14, 2022

This adds revision information for template parts, which will be needed for WordPress/gutenberg#44503

TODO

  • Add checks for templates without wp_id
  • Add endpoints for revisions
  • Unit tests

Trac ticket:


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

@georgeh georgeh marked this pull request as draft October 14, 2022 19:45
@github-actions
Copy link

Hi @georgeh! 👋

Thank you for your contribution to WordPress! 💖

It looks like this is your first pull request to wordpress-develop. Here are a few things to be aware of that may help you out!

No one monitors this repository for new pull requests. Pull requests must be attached to a Trac ticket to be considered for inclusion in WordPress Core. To attach a pull request to a Trac ticket, please include the ticket's full URL in your pull request description.

Pull requests are never merged on GitHub. The WordPress codebase continues to be managed through the SVN repository that this GitHub repository mirrors. Please feel free to open pull requests to work on any contribution you are making.

More information about how GitHub pull requests can be used to contribute to WordPress can be found in this blog post.

Please include automated tests. Including tests in your pull request is one way to help your patch be considered faster. To learn about WordPress' test suites, visit the Automated Testing page in the handbook.

If you have not had a chance, please review the Contribute with Code page in the WordPress Core Handbook.

The Developer Hub also documents the various coding standards that are followed:

Thank you,
The WordPress Project

@@ -752,6 +752,23 @@ protected function prepare_links( $id ) {
),
);

$template = get_block_template( $id, $this->post_type );
$revisions = wp_get_latest_revision_id_and_total_count( $template->wp_id );
Copy link
Member

Choose a reason for hiding this comment

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

Not all templates will. have a wp_id.

@georgeh
Copy link
Author

georgeh commented Oct 19, 2022

My goal is to let the template editor know if there are previous revisions so that it can choose whether or not to display the revision link.

Right now I'm trying to get the template and template-part revision REST APIs to mimic the post APIs, but routing is a challenge.

The templates REST controller [accepts more-or-less anything after /wp/v2/templates(https://github.com/WordPress/WordPress/blob/6994dfddd0ccc39b2bea27c358ea900668dbe7ec/wp-includes/rest-api/endpoints/class-wp-rest-templates-controller.php#L98-L108). This is because template ids are in the form of theme-name//template-part so it's difficult to determine whether we are being asked for a template named "revisions" or revisions for a template. Further complicating matters, the API accepts template ids in the form of theme-name/template-part because something is stripping out the double /.

I don't want to get in a situation where you have to name your template a special reserved word. I am currently experimenting with making WP_REST_Revisions_Controller respond to requests in the form of /wp/v2/templates/revisions/{template id}

I'm tempted to go ahead with the quick solution and just add the revision count to the template response, without including any links to previous revisions. This would allow us to move forward on WordPress/gutenberg#44503 but creates a special case for templates.

@georgeh
Copy link
Author

georgeh commented Oct 26, 2022

Making the changes in WordPress/gutenberg#45215 instead

@georgeh georgeh closed this Oct 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants