Skip to content

Commit

Permalink
Coding Standards: Use strict comparison in `wp_xmlrpc_server::wp_getU…
Browse files Browse the repository at this point in the history
…sersBlogs()`.

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
  • Loading branch information
SergeyBiryukov committed Jan 30, 2025
1 parent 21be4bc commit 6b41380
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
9 changes: 6 additions & 3 deletions src/wp-includes/class-wp-xmlrpc-server.php
Original file line number Diff line number Diff line change
Expand Up @@ -735,17 +735,20 @@ public function wp_getUsersBlogs( $args ) {
*/
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;
}

Expand Down
6 changes: 5 additions & 1 deletion src/wp-includes/ms-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -99,6 +102,7 @@ function get_active_blog_for_user( $user_id ) {
} else {
return;
}

return $ret;
} else {
return $primary;
Expand Down

0 comments on commit 6b41380

Please sign in to comment.