[wp-trac] [WordPress Trac] #63910: In wp_switch_roles_and_user there is no cast to int applied to $new_site_id and $old_site_id
WordPress Trac
noreply at wordpress.org
Thu Sep 4 08:44:45 UTC 2025
#63910: In wp_switch_roles_and_user there is no cast to int applied to $new_site_id
and $old_site_id
--------------------------------+------------------------------
Reporter: eumene | Owner: (none)
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Networks and Sites | Version: 4.9.8
Severity: minor | Resolution:
Keywords: | Focuses: multisite
--------------------------------+------------------------------
Changes (by eumene):
* version: 4.9 => 4.9.8
* type: defect (bug) => enhancement
* severity: normal => minor
Comment:
Hi @spacedmonkey
This is just a suggestion to prevent my problem.
I'm working on an old WP multi-site installation, with custom code.
I'm updating it to newer WP version
I got an infinite loop calling Rest API.
In this case the custom code calls
{{{#!php
<?php
switch_to_blog(BLOG_ID_CURRENT_SITE);
}}}
but the old wp-config.php was
{{{#!php
<?php
define('SITE_ID_CURRENT_SITE', '1');
define('BLOG_ID_CURRENT_SITE', '1');
}}}
So, I changed it
{{{#!php
<?php
define('SITE_ID_CURRENT_SITE', 1);
define('BLOG_ID_CURRENT_SITE', 1);
}}}
**It works**
But, surfing WP code, I found many (int) cast and I thought that WP core
team want to handle this kind of config type error - searching for ")
$site_id" in WP code.
Some example
wp-includes/ms-site.php
{{{#!php
<?php
function wp_is_site_initialized( $site_id ) {
global $wpdb;
if ( is_object( $site_id ) ) {
$site_id = $site_id->blog_id;
}
$site_id = (int) $site_id;
}}}
wp-includes/class-wp-site.php
{{{#!php
<?php
public static function get_instance( $site_id ) {
global $wpdb;
$site_id = (int) $site_id;
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/63910#comment:2>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list