Coding Standards: Use strict comparison in wp_xmlrpc_server::wp_getUsersBlogs().

Includes a micro-optimization to avoid calling `get_current_network_id()` in a loop.

Follow-up to [8075], [9798], [26120], [38814].

Props aristath, poena, afercia, SergeyBiryukov.
See #62279.

git-svn-id: https://develop.svn.wordpress.org/trunk@59738 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Sergey Biryukov 2025-01-30 11:20:58 +00:00
parent 21be4bc5f1
commit 6b41380785
2 changed files with 11 additions and 4 deletions

View File

@ -735,17 +735,20 @@ class wp_xmlrpc_server extends IXR_Server {
*/
do_action( 'xmlrpc_call', 'wp.getUsersBlogs', $args, $this );
$blogs = (array) get_blogs_of_user( $user->ID );
$struct = array();
$blogs = (array) get_blogs_of_user( $user->ID );
$struct = array();
$primary_blog_id = 0;
$active_blog = get_active_blog_for_user( $user->ID );
if ( $active_blog ) {
$primary_blog_id = (int) $active_blog->blog_id;
}
$current_network_id = get_current_network_id();
foreach ( $blogs as $blog ) {
// Don't include blogs that aren't hosted at this site.
if ( get_current_network_id() != $blog->site_id ) {
if ( $blog->site_id !== $current_network_id ) {
continue;
}

View File

@ -76,9 +76,12 @@ function get_active_blog_for_user( $user_id ) {
) {
$blogs = get_blogs_of_user( $user_id, true ); // If a user's primary blog is shut down, check their other blogs.
$ret = false;
if ( is_array( $blogs ) && count( $blogs ) > 0 ) {
$current_network_id = get_current_network_id();
foreach ( (array) $blogs as $blog_id => $blog ) {
if ( get_current_network_id() !== $blog->site_id ) {
if ( $blog->site_id !== $current_network_id ) {
continue;
}
@ -99,6 +102,7 @@ function get_active_blog_for_user( $user_id ) {
} else {
return;
}
return $ret;
} else {
return $primary;