-
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
/wp/v2/pattern-directory/patterns
endpoint: slug parameter has no effect on the response
#2625
/wp/v2/pattern-directory/patterns
endpoint: slug parameter has no effect on the response
#2625
Conversation
We must also implode slugs as implode doesn't work with multi-dimensional arrays.
src/wp-includes/rest-api/endpoints/class-wp-rest-pattern-directory-controller.php
Outdated
Show resolved
Hide resolved
Strings will be automatically converted to an array. Per suggestion here: WordPress#2625 (comment)
…nsient_key method as it would be helpful to make it available to child classes.
src/wp-includes/rest-api/endpoints/class-wp-rest-pattern-directory-controller.php
Outdated
Show resolved
Hide resolved
src/wp-includes/rest-api/endpoints/class-wp-rest-pattern-directory-controller.php
Outdated
Show resolved
Hide resolved
…supposed to be null.
src/wp-includes/rest-api/endpoints/class-wp-rest-pattern-directory-controller.php
Outdated
Show resolved
Hide resolved
src/wp-includes/rest-api/endpoints/class-wp-rest-pattern-directory-controller.php
Outdated
Show resolved
Hide resolved
} | ||
} | ||
|
||
return 'wp_remote_block_patterns_' . md5( implode( '-', $query_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.
return 'wp_remote_block_patterns_' . md5( implode( '-', $query_args ) ); | |
return 'wp_remote_block_patterns_' . md5( serialize( $query_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.
Yes, I've been thinking about replacing implode
with wp_json_encode
(json_encode
is faster than serialize
) in the scope of another PR, but serialize
will do too.
The result produced by implode
doesn't depend on the keys of the $query_args
array. Therefore, this increases the chance of collisions.
Fixed in 2c08eea
P.S. I didn't change it because I was afraid that it would cause a sharp increase in the number of requests to the wp/v2/pattern-directory/patterns
endpoint once WordPress 6.0 is released. The old values stored in the cache will be invalidated because this PR replaces implode
with serialize
.
I hope it will not happen since not all WordPress sites are updated simultaneously.
tests/phpunit/tests/rest-api/rest-pattern-directory-controller.php
Outdated
Show resolved
Hide resolved
tests/phpunit/tests/rest-api/rest-pattern-directory-controller.php
Outdated
Show resolved
Hide resolved
tests/phpunit/tests/rest-api/rest-pattern-directory-controller.php
Outdated
Show resolved
Hide resolved
src/wp-includes/rest-api/endpoints/class-wp-rest-pattern-directory-controller.php
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.
There are a number of changes required here.
Use WP_REST_Pattern_Directory_Controller_Test::setUp to set up the controller.
It seems there is some issue with the ::setUp method.
Thank you for the review, @spacedmonkey! |
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.
LGTM
tests/phpunit/tests/rest-api/rest-pattern-directory-controller.php
Outdated
Show resolved
Hide resolved
…s_get_generated_correctly: add error messages.
…s_get_generated_correctly: add error messages.
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.
LGTM 👍
@anton-vlasenko I'm working on cleaning up the 6.0 Project Board. Are we waiting on anything else for this PR? |
@ndiego I don't know if there are any problems from an organizational point of view. |
src/wp-includes/rest-api/endpoints/class-wp-rest-pattern-directory-controller.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.
Ready for commit.
Committed via changeset https://core.trac.wordpress.org/changeset/53333. |
…ay arguments (#40900) * Backport WordPress/wordpress-develop#2591 to Gutenberg. * Backport WordPress/wordpress-develop#2625 to Gutenberg. * Update PHPDoc block. * Fix comments * Replace WP with WordPress.
Trac ticket: https://core.trac.wordpress.org/ticket/55617
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.