This repository has been archived by the owner on May 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Use core WP's query var allow-list #131
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -131,14 +131,23 @@ public function register_rest_routes() { | |
* @return array | ||
*/ | ||
public function get_route_response( $request ) { | ||
|
||
// phpcs:ignore WordPress.WP.GlobalVariablesOverride.OverrideProhibited | ||
global $wp; | ||
|
||
/** | ||
* Action fired on the request. | ||
* | ||
* @param \WP_REST_Request $request WP_REST_Request object. | ||
*/ | ||
do_action( 'wp_irving_components_request', $request ); | ||
|
||
$this->params = $request->get_params(); | ||
// Remove any request parameters that haven't been allow-listed by the | ||
// global $wp object's $public_query_vars array. | ||
$this->params = array_intersect_key( | ||
$request->get_params(), | ||
array_flip( $wp->public_query_vars ) | ||
); | ||
|
||
// Parse path and context. | ||
$this->parse_path( $this->params['path'] ?? '' ); | ||
|
@@ -366,7 +375,7 @@ public function build_query() { | |
$wp_query = apply_filters( 'wp_irving_components_wp_query', $wp_query, $this->path, $this->custom_params, $this->params ); | ||
|
||
// Map to main query and set up globals. | ||
// phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited | ||
// phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited, WordPress.WP.GlobalVariablesOverride.OverrideProhibited | ||
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. Did the sniff rule change, or do we really need to be ignoring both here? 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. I'm not sure I know enough about each of those vars to make an educated decision on whether or not they should be present. I do believe we should be mimicking WordPress core as much as possible though. One of those phpcs rules hits me locally, one hits me on Travis, so I included both for the sake of it right now. |
||
$wp_the_query = $wp_query; | ||
$this->register_globals(); | ||
|
||
|
@@ -396,7 +405,7 @@ public function permissions_check( $request ) { | |
* @see https://github.com/WordPress/WordPress/blob/master/wp-includes/class-wp.php#L580 | ||
*/ | ||
public function register_globals() { | ||
// phpcs:disable WordPress.WP.GlobalVariablesOverride.Prohibited | ||
// phpcs:disable WordPress.WP.GlobalVariablesOverride.Prohibited, WordPress.WP.GlobalVariablesOverride.OverrideProhibited | ||
global $wp_the_query, $wp_query; | ||
$wp_query = $wp_the_query; | ||
|
||
|
@@ -442,6 +451,8 @@ public function fix_rest_url( $url ) : string { | |
* @return array $vars Array of query vars. | ||
*/ | ||
public function modify_query_vars( $vars ) { | ||
$vars[] = 'context'; | ||
$vars[] = 'path'; | ||
$vars[] = 'irving-path'; | ||
$vars[] = 'irving-path-params'; | ||
return $vars; | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
oh that is clever
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.
Here's the full list of where WP adds public query vars:
https://github.com/WordPress/wordpress-develop/blob/master/src/wp-includes/class-wp.php#L9-L17
Are we sure we want/need to support all of these explicitly? Many of them should be handled by the route parsing on the WP side, I would think.