Skip to content

Commit 6b41380

Browse files
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
1 parent 21be4bc commit 6b41380

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

src/wp-includes/class-wp-xmlrpc-server.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -735,17 +735,20 @@ public function wp_getUsersBlogs( $args ) {
735735
*/
736736
do_action( 'xmlrpc_call', 'wp.getUsersBlogs', $args, $this );
737737

738-
$blogs = (array) get_blogs_of_user( $user->ID );
739-
$struct = array();
738+
$blogs = (array) get_blogs_of_user( $user->ID );
739+
$struct = array();
740+
740741
$primary_blog_id = 0;
741742
$active_blog = get_active_blog_for_user( $user->ID );
742743
if ( $active_blog ) {
743744
$primary_blog_id = (int) $active_blog->blog_id;
744745
}
745746

747+
$current_network_id = get_current_network_id();
748+
746749
foreach ( $blogs as $blog ) {
747750
// Don't include blogs that aren't hosted at this site.
748-
if ( get_current_network_id() != $blog->site_id ) {
751+
if ( $blog->site_id !== $current_network_id ) {
749752
continue;
750753
}
751754

src/wp-includes/ms-functions.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,12 @@ function get_active_blog_for_user( $user_id ) {
7676
) {
7777
$blogs = get_blogs_of_user( $user_id, true ); // If a user's primary blog is shut down, check their other blogs.
7878
$ret = false;
79+
7980
if ( is_array( $blogs ) && count( $blogs ) > 0 ) {
81+
$current_network_id = get_current_network_id();
82+
8083
foreach ( (array) $blogs as $blog_id => $blog ) {
81-
if ( get_current_network_id() !== $blog->site_id ) {
84+
if ( $blog->site_id !== $current_network_id ) {
8285
continue;
8386
}
8487

@@ -99,6 +102,7 @@ function get_active_blog_for_user( $user_id ) {
99102
} else {
100103
return;
101104
}
105+
102106
return $ret;
103107
} else {
104108
return $primary;

0 commit comments

Comments
 (0)