Skip to content

[41604] Modified update_item() to read only POST body parameters thereby handling global query parameters #8975

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

Conversation

Vedanshmini26
Copy link

Trac ticket: https://core.trac.wordpress.org/ticket/41604

This PR fixes the issue pointed out by @Mamaduka i.e., the API can contain global query parameters, such as _locale, which fail to pass. This is fixed by replacing the $request->get_params(); by $request->get_body_params()

Copy link

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props sheldorofazeroth.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

Copy link

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • The Plugin and Theme Directories cannot be accessed within Playground.
  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

Comment on lines 146 to +149
$options = $this->get_registered_options();

$params = $request->get_params();
$query_params = $request->get_query_params();
$params = array_diff_key( $params, $query_params );

Choose a reason for hiding this comment

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

Nit: I think we need to align the equals to avoid PHPCS warning errors:

	public function update_item( $request ) {
		$options      = $this->get_registered_options();
		$params       = $request->get_params();
		$query_params = $request->get_query_params();
		$params       = array_diff_key( $params, $query_params );

I don't know why it passed CI, but it gives a warning locally.

composer lint src/wp-includes/rest-api/endpoints/class-wp-rest-settings-controller.php
> @php ./vendor/squizlabs/php_codesniffer/bin/phpcs --report=summary,source 'src/wp-includes/rest-api/endpoints/class-wp-rest-settings-controller.php'
W 1 / 1 (100%)



PHP CODE SNIFFER REPORT SUMMARY
---------------------------------------------------------------------------------------------
FILE                                                                         ERRORS  WARNINGS
---------------------------------------------------------------------------------------------
src/wp-includes/rest-api/endpoints/class-wp-rest-settings-controller.php     0       3
---------------------------------------------------------------------------------------------
A TOTAL OF 0 ERRORS AND 3 WARNINGS WERE FOUND IN 1 FILE
---------------------------------------------------------------------------------------------
PHPCBF CAN FIX 3 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
---------------------------------------------------------------------------------------------

Time: 61ms; Memory: 8MB


PHP CODE SNIFFER VIOLATION SOURCE SUMMARY
-----------------------------------------------------------------------
    SOURCE                                                        COUNT
-----------------------------------------------------------------------
[x] Generic.Formatting.MultipleStatementAlignment.NotSameWarning  3
-----------------------------------------------------------------------
A TOTAL OF 3 SNIFF VIOLATIONS WERE FOUND IN 1 SOURCE
-----------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SOURCES AUTOMATICALLY (3 VIOLATIONS IN TOTAL)
-----------------------------------------------------------------------

Script @php ./vendor/squizlabs/php_codesniffer/bin/phpcs --report=summary,source handling the lint event returned with error code 2

Copy link

A commit was made that fixes the Trac ticket referenced in the description of this pull request.

SVN changeset: 60357
GitHub commit: 3f3fa0f

This PR will be closed, but please confirm the accuracy of this and reopen if there is more work to be done.

@github-actions github-actions bot closed this Jun 27, 2025
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