WordPress/wp-includes/rest-api/endpoints
hellofromTonya d7893c3cea Code Modernization: Fix null to non-nullable deprecation in WP_REST_Users_Controller::update_item().
Not all requests are accompanied by a `$request['email']`. This leads to a PHP 8.1 "passing null to non-nullable" deprecation notice when the `WP_REST_Users_Controller::update_item()` method passes a `null` email address onto `email_exists()`, which eventually reached the `WP_User::get_data_by()` method where things go wrong.

In the next condition in the code of the `WP_REST_Users_Controller::update_item()` method - `if ( $owner_id && $owner_id !== $id )` - you can see that the code already takes this into account as it will not throw a `WP_Error` if `$owner_id` is falsey.

`WP_User::get_data_by()` returns `false` for a failed field request. The other functions through which the return value is passed through, do the same.

So, by setting a default value for `$owner_id` of `false` and only checking `email_exists()` when there is an email to check, the "passing null to non-nullable" deprecation notice is bypassed without breaking BC.

Fixes a whole slew of test errors along the lines of:
{{{
6) WP_Test_REST_Users_Controller::test_update_item_en_US_locale
trim(): Passing null to parameter https://github.com/WordPress/wordpress-develop/pull/1 ($string) of type string is deprecated

/var/www/src/wp-includes/class-wp-user.php:211
/var/www/src/wp-includes/pluggable.php:105
/var/www/src/wp-includes/user.php:1953
/var/www/src/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php:728
/var/www/src/wp-includes/rest-api/class-wp-rest-server.php:1143
/var/www/src/wp-includes/rest-api/class-wp-rest-server.php:990
/var/www/tests/phpunit/includes/spy-rest-server.php:67
/var/www/tests/phpunit/tests/rest-api/rest-users-controller.php:1719
/var/www/vendor/bin/phpunit:123
}}}

Follow-up to [44641], [38832].

Props jrf.
See #55656.
Built from https://develop.svn.wordpress.org/trunk@54317


git-svn-id: http://core.svn.wordpress.org/trunk@53876 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-09-26 21:46:09 +00:00
..
class-wp-rest-application-passwords-controller.php
class-wp-rest-attachments-controller.php
class-wp-rest-autosaves-controller.php Autosave/REST API: Block autosaving from overwriting changes when locked from editing. 2022-09-11 22:35:08 +00:00
class-wp-rest-block-directory-controller.php
class-wp-rest-block-pattern-categories-controller.php
class-wp-rest-block-patterns-controller.php Editor: Add post types property to wp-rest-block-patterns-controller.php. 2022-09-20 16:29:12 +00:00
class-wp-rest-block-renderer-controller.php
class-wp-rest-block-types-controller.php Coding Standards: Various alignment fixes from composer format. 2022-09-19 19:51:09 +00:00
class-wp-rest-blocks-controller.php
class-wp-rest-comments-controller.php
class-wp-rest-controller.php Code Modernization: Add AllowDynamicProperties attribute to all (parent) classes. 2022-09-12 15:47:14 +00:00
class-wp-rest-edit-site-export-controller.php
class-wp-rest-global-styles-controller.php
class-wp-rest-menu-items-controller.php
class-wp-rest-menu-locations-controller.php
class-wp-rest-menus-controller.php
class-wp-rest-pattern-directory-controller.php
class-wp-rest-plugins-controller.php
class-wp-rest-post-statuses-controller.php
class-wp-rest-post-types-controller.php REST API: Fix check for has_archive inclusion. 2022-09-22 11:33:13 +00:00
class-wp-rest-posts-controller.php
class-wp-rest-revisions-controller.php
class-wp-rest-search-controller.php
class-wp-rest-settings-controller.php REST API: Add support for settings to specify their own additionalProperties. 2022-09-11 23:30:10 +00:00
class-wp-rest-sidebars-controller.php
class-wp-rest-site-health-controller.php
class-wp-rest-taxonomies-controller.php
class-wp-rest-templates-controller.php Editor: Adds template types, is_wp_suggestion, and fallback template content. 2022-09-20 21:21:09 +00:00
class-wp-rest-terms-controller.php
class-wp-rest-themes-controller.php
class-wp-rest-url-details-controller.php
class-wp-rest-users-controller.php Code Modernization: Fix null to non-nullable deprecation in WP_REST_Users_Controller::update_item(). 2022-09-26 21:46:09 +00:00
class-wp-rest-widget-types-controller.php
class-wp-rest-widgets-controller.php