Coding Standards: Correct $site_id parameter default values in WP_User.
Some checks failed
Cleanup Pull Requests / Clean up pull requests (push) Has been cancelled
Coding Standards / PHP coding standards (push) Has been cancelled
Coding Standards / JavaScript coding standards (push) Has been cancelled
Coding Standards / Slack Notifications (push) Has been cancelled
Coding Standards / Failed workflow tasks (push) Has been cancelled
End-to-end Tests / Test with SCRIPT_DEBUG disabled (push) Has been cancelled
End-to-end Tests / Test with SCRIPT_DEBUG enabled (push) Has been cancelled
End-to-end Tests / Slack Notifications (push) Has been cancelled
End-to-end Tests / Failed workflow tasks (push) Has been cancelled
JavaScript Tests / QUnit Tests (push) Has been cancelled
JavaScript Tests / Slack Notifications (push) Has been cancelled
JavaScript Tests / Failed workflow tasks (push) Has been cancelled
Performance Tests / Determine Matrix (push) Has been cancelled
Performance Tests / ${{ matrix.multisite && 'Multisite' || 'Single Site' }} ${{ matrix.memcached && 'Memcached' || 'Default' }} (push) Has been cancelled
Performance Tests / Compare (push) Has been cancelled
Performance Tests / Slack Notifications (push) Has been cancelled
Performance Tests / Failed workflow tasks (push) Has been cancelled
PHP Compatibility / Check PHP compatibility (push) Has been cancelled
PHP Compatibility / Slack Notifications (push) Has been cancelled
PHP Compatibility / Failed workflow tasks (push) Has been cancelled
PHPUnit Tests / PHP 7.2 (push) Has been cancelled
PHPUnit Tests / PHP 7.3 (push) Has been cancelled
PHPUnit Tests / PHP 7.4 (push) Has been cancelled
PHPUnit Tests / PHP 8.0 (push) Has been cancelled
PHPUnit Tests / PHP 8.1 (push) Has been cancelled
PHPUnit Tests / PHP 8.2 (push) Has been cancelled
PHPUnit Tests / PHP 8.3 (push) Has been cancelled
PHPUnit Tests / PHP 8.4 (push) Has been cancelled
PHPUnit Tests / html-api-html5lib-tests (push) Has been cancelled
PHPUnit Tests / Slack Notifications (push) Has been cancelled
PHPUnit Tests / Failed workflow tasks (push) Has been cancelled
Test Build Processes / Core running from build (push) Has been cancelled
Test Build Processes / Core running from src (push) Has been cancelled
Test Build Processes / Gutenberg running from build (push) Has been cancelled
Test Build Processes / Gutenberg running from src (push) Has been cancelled
Test Build Processes / Slack Notifications (push) Has been cancelled
Test Build Processes / Failed workflow tasks (push) Has been cancelled
Upgrade Develop Version Tests / Build (push) Has been cancelled
Upgrade Develop Version Tests / Upgrade from 4.9 (push) Has been cancelled
Upgrade Develop Version Tests / Upgrade from 6.5 (push) Has been cancelled
Upgrade Develop Version Tests / Upgrade from 6.7 (push) Has been cancelled
Upgrade Develop Version Tests / Upgrade from 6.8-RC1 (push) Has been cancelled
Upgrade Develop Version Tests / Slack Notifications (push) Has been cancelled
Upgrade Develop Version Tests / Failed workflow tasks (push) Has been cancelled
Code Coverage Report / Single site report (push) Has been cancelled
Code Coverage Report / Multisite report (push) Has been cancelled
Code Coverage Report / Slack Notifications (push) Has been cancelled
Code Coverage Report / Failed workflow tasks (push) Has been cancelled

This commit corrects the default `$site_id` parameter values used throughout the `WP_User` class to bring them in line with their `int` doctypes (and the doctypes of the functions used internally by the affected class methods).

More specifically,
* `__construct()`: `$site_id = ''` changed to `$site_id = 0`
* `init()`: `$site_id = ''` changed to `$site_id = 0`
* `for_blog()`: `$blog_id = ''` changed to `$blog_id = 0`
* `for_site()`: `$site_id = ''` changed to `$site_id = 0`

Follow-up to [12796], [15566], [18597], [41624].

Props justlevine.
See #63268.

git-svn-id: https://develop.svn.wordpress.org/trunk@60174 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Sergey Biryukov 2025-04-18 20:26:20 +00:00
parent e800c60ec0
commit 71a56d8f9e

View File

@ -125,7 +125,7 @@ class WP_User {
* @param string $name Optional. User's username
* @param int $site_id Optional Site ID, defaults to current site.
*/
public function __construct( $id = 0, $name = '', $site_id = '' ) {
public function __construct( $id = 0, $name = '', $site_id = 0 ) {
global $wpdb;
if ( ! isset( self::$back_compat_keys ) ) {
@ -175,7 +175,7 @@ class WP_User {
* @param object $data User DB row object.
* @param int $site_id Optional. The site ID to initialize for.
*/
public function init( $data, $site_id = '' ) {
public function init( $data, $site_id = 0 ) {
if ( ! isset( $data->ID ) ) {
$data->ID = 0;
}
@ -852,7 +852,7 @@ class WP_User {
*
* @param int $blog_id Optional. Site ID, defaults to current site.
*/
public function for_blog( $blog_id = '' ) {
public function for_blog( $blog_id = 0 ) {
_deprecated_function( __METHOD__, '4.9.0', 'WP_User::for_site()' );
$this->for_site( $blog_id );
@ -867,7 +867,7 @@ class WP_User {
*
* @param int $site_id Site ID to initialize user capabilities for. Default is the current site.
*/
public function for_site( $site_id = '' ) {
public function for_site( $site_id = 0 ) {
global $wpdb;
if ( ! empty( $site_id ) ) {