-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Allow for custom revision / autosave endpoints classes. #3533
Allow for custom revision / autosave endpoints classes. #3533
Conversation
What would the autosaves / revisions controllers look like when they need to be custom for templates/template parts. |
tests/phpunit/tests/rest-api/wpRestTemplateRevisionsController.php
Outdated
Show resolved
Hide resolved
tests/phpunit/tests/rest-api/wpRestTemplateRevisionsController.php
Outdated
Show resolved
Hide resolved
tests/phpunit/tests/rest-api/wpRestTemplateRevisionsController.php
Outdated
Show resolved
Hide resolved
…are_item test method.
…item_schema test method.
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.
Takes a lot of code to do this, doesn't it! Thanks for fleshing out the unit tests more, @spacedmonkey .
I am fine with the overall approach, and mostly want to encourage a full once-over of all docblocks to make sure they're not strictly copy-pasted from the base controller when more specific wording might help us in the future.
src/wp-includes/rest-api/endpoints/class-wp-rest-template-autosaves-controller.php
Outdated
Show resolved
Hide resolved
src/wp-includes/rest-api/endpoints/class-wp-rest-template-revisions-controller.php
Outdated
Show resolved
Hide resolved
@kadamwhite I 100% agree, we need to do a full pass on the docs. But can be done after commit / RC stage. I will review docs again, but I don't want docs to be the reason we miss WP 6.4, this change has been punted 3 times already. |
Co-authored-by: K Adam White <[email protected]>
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.
Thanks @spacedmonkey!
Some minor feedback then this is good from my perspective. 🙂
src/wp-includes/rest-api/endpoints/class-wp-rest-template-autosaves-controller.php
Outdated
Show resolved
Hide resolved
src/wp-includes/rest-api/endpoints/class-wp-rest-template-autosaves-controller.php
Show resolved
Hide resolved
src/wp-includes/rest-api/endpoints/class-wp-rest-template-autosaves-controller.php
Outdated
Show resolved
Hide resolved
src/wp-includes/rest-api/endpoints/class-wp-rest-template-revisions-controller.php
Outdated
Show resolved
Hide resolved
src/wp-includes/rest-api/endpoints/class-wp-rest-template-revisions-controller.php
Outdated
Show resolved
Hide resolved
src/wp-includes/rest-api/endpoints/class-wp-rest-templates-controller.php
Outdated
Show resolved
Hide resolved
tests/phpunit/tests/rest-api/wpRestTemplateAutosavesController.php
Outdated
Show resolved
Hide resolved
tests/phpunit/tests/rest-api/wpRestTemplateRevisionsController.php
Outdated
Show resolved
Hide resolved
Co-authored-by: Colin Stewart <[email protected]>
Co-authored-by: Colin Stewart <[email protected]>
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.
Just the ! empty()
conversation and these two typo corrections left. Pre-approving as I'll be AFK for a bit. 🙂
tests/phpunit/tests/rest-api/wpRestTemplateAutosavesController.php
Outdated
Show resolved
Hide resolved
tests/phpunit/tests/rest-api/wpRestTemplateAutosavesController.php
Outdated
Show resolved
Hide resolved
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.
Fair point, @spacedmonkey , so long as we do come back to the docs before release. Thank you for addressing the top issues I flagged—approving from my end to unblock moving forward.
….php Co-authored-by: Colin Stewart <[email protected]>
….php Co-authored-by: Colin Stewart <[email protected]>
….php Co-authored-by: Colin Stewart <[email protected]>
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.
Thanks @spacedmonkey for the PR. Left some minor feedback. Do we need the changes from tests/qunit/fixtures/wp-api-generated.js
file?
Co-authored-by: Mukesh Panchal <[email protected]>
Yes, it is needed. All updates to the rest api need this update. See this example 4f56c3d |
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.
Explanation of why these changes are needed:
- https://core.trac.wordpress.org/ticket/56922#comment:31
- https://core.trac.wordpress.org/ticket/56922#comment:38
Additionally, the rest-schema-setup.php
and wp-api-generated.js
files will need to be updated too.
* Matches theme's directory: `/themes/<subdirectory>/<theme>/` or `/themes/<theme>/`. | ||
* Excludes invalid directory name characters: `/:<>*?"|`. | ||
*/ | ||
'([^\/:<>\*\?"\|]+(?:\/[^\/:<>\*\?"\|]+)?)', |
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.
'([^\/:<>\*\?"\|]+(?:\/[^\/:<>\*\?"\|]+)?)', | |
'([^\/:<>\*\?"\|]+\/\/?[^\/:<>\*\?"\|]+)', |
* Matches theme's directory: `/themes/<subdirectory>/<theme>/` or `/themes/<theme>/`. | ||
* Excludes invalid directory name characters: `/:<>*?"|`. | ||
*/ | ||
'([^\/:<>\*\?"\|]+(?:\/[^\/:<>\*\?"\|]+)?)', |
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.
'([^\/:<>\*\?"\|]+(?:\/[^\/:<>\*\?"\|]+)?)', | |
'([^\/:<>\*\?"\|]+\/\/?[^\/:<>\*\?"\|]+)', |
* Matches theme's directory: `/themes/<subdirectory>/<theme>/` or `/themes/<theme>/`. | ||
* Excludes invalid directory name characters: `/:<>*?"|`. | ||
*/ | ||
'([^\/:<>\*\?"\|]+(?:\/[^\/:<>\*\?"\|]+)?)', |
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.
'([^\/:<>\*\?"\|]+(?:\/[^\/:<>\*\?"\|]+)?)', | |
'([^\/:<>\*\?"\|]+\/\/?[^\/:<>\*\?"\|]+)', |
* Matches theme's directory: `/themes/<subdirectory>/<theme>/` or `/themes/<theme>/`. | ||
* Excludes invalid directory name characters: `/:<>*?"|`. | ||
*/ | ||
'([^\/:<>\*\?"\|]+(?:\/[^\/:<>\*\?"\|]+)?)', |
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.
'([^\/:<>\*\?"\|]+(?:\/[^\/:<>\*\?"\|]+)?)', | |
'([^\/:<>\*\?"\|]+\/\/?[^\/:<>\*\?"\|]+)', |
public function test_register_routes() { | ||
$routes = rest_get_server()->get_routes(); | ||
$this->assertArrayHasKey( | ||
'/wp/v2/templates/(?P<id>([^\/:<>\*\?"\|]+(?:\/[^\/:<>\*\?"\|]+)?)[\/\w%-]+)/autosaves', |
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.
'/wp/v2/templates/(?P<id>([^\/:<>\*\?"\|]+(?:\/[^\/:<>\*\?"\|]+)?)[\/\w%-]+)/autosaves', | |
'/wp/v2/templates/(?P<id>([^\/:<>\*\?"\|]+\/\/?[^\/:<>\*\?"\|]+)[\/\w%-]+)/autosaves', |
'Template part autosaves route does not exist.' | ||
); | ||
$this->assertArrayHasKey( | ||
'/wp/v2/template-parts/(?P<parent>([^\/:<>\*\?"\|]+(?:\/[^\/:<>\*\?"\|]+)?)[\/\w%-]+)/autosaves/(?P<id>[\d]+)', |
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.
'/wp/v2/template-parts/(?P<parent>([^\/:<>\*\?"\|]+(?:\/[^\/:<>\*\?"\|]+)?)[\/\w%-]+)/autosaves/(?P<id>[\d]+)', | |
'/wp/v2/template-parts/(?P<parent>([^\/:<>\*\?"\|]+\/\/?[^\/:<>\*\?"\|]+)[\/\w%-]+)/autosaves/(?P<id>[\d]+)', |
public function test_register_routes() { | ||
$routes = rest_get_server()->get_routes(); | ||
$this->assertArrayHasKey( | ||
'/wp/v2/templates/(?P<parent>([^\/:<>\*\?"\|]+(?:\/[^\/:<>\*\?"\|]+)?)[\/\w%-]+)/revisions', |
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.
'/wp/v2/templates/(?P<parent>([^\/:<>\*\?"\|]+(?:\/[^\/:<>\*\?"\|]+)?)[\/\w%-]+)/revisions', | |
'/wp/v2/templates/(?P<parent>([^\/:<>\*\?"\|]+\/\/?[^\/:<>\*\?"\|]+)[\/\w%-]+)/revisions', |
'Template revisions route does not exist.' | ||
); | ||
$this->assertArrayHasKey( | ||
'/wp/v2/templates/(?P<parent>([^\/:<>\*\?"\|]+(?:\/[^\/:<>\*\?"\|]+)?)[\/\w%-]+)/revisions/(?P<id>[\d]+)', |
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.
'/wp/v2/templates/(?P<parent>([^\/:<>\*\?"\|]+(?:\/[^\/:<>\*\?"\|]+)?)[\/\w%-]+)/revisions/(?P<id>[\d]+)', | |
'/wp/v2/templates/(?P<parent>([^\/:<>\*\?"\|]+\/\/?[^\/:<>\*\?"\|]+)[\/\w%-]+)/revisions/(?P<id>[\d]+)', |
'Single template revision based on the given ID route does not exist.' | ||
); | ||
$this->assertArrayHasKey( | ||
'/wp/v2/template-parts/(?P<parent>([^\/:<>\*\?"\|]+(?:\/[^\/:<>\*\?"\|]+)?)[\/\w%-]+)/revisions', |
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.
'/wp/v2/template-parts/(?P<parent>([^\/:<>\*\?"\|]+(?:\/[^\/:<>\*\?"\|]+)?)[\/\w%-]+)/revisions', | |
'/wp/v2/template-parts/(?P<parent>([^\/:<>\*\?"\|]+\/\/?[^\/:<>\*\?"\|]+)[\/\w%-]+)/revisions', |
'Template part revisions route does not exist.' | ||
); | ||
$this->assertArrayHasKey( | ||
'/wp/v2/template-parts/(?P<parent>([^\/:<>\*\?"\|]+(?:\/[^\/:<>\*\?"\|]+)?)[\/\w%-]+)/revisions/(?P<id>[\d]+)', |
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.
'/wp/v2/template-parts/(?P<parent>([^\/:<>\*\?"\|]+(?:\/[^\/:<>\*\?"\|]+)?)[\/\w%-]+)/revisions/(?P<id>[\d]+)', | |
'/wp/v2/template-parts/(?P<parent>([^\/:<>\*\?"\|]+\/\/?[^\/:<>\*\?"\|]+)[\/\w%-]+)/revisions/(?P<id>[\d]+)', |
TODO
Trac ticket: https://core.trac.wordpress.org/ticket/56922
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.