Skip to content

Commit c8011cb

Browse files
committed
Explain why I cast to array to avoid triggering the __get()
1 parent c9f2694 commit c8011cb

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

class-super-admin-performance-boost.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,14 @@ public function super_admin_get_blogs_of_user( ?array $sites, int $user_id, bool
7878
$sites = [];
7979
foreach ( $_sites as $site ) {
8080

81+
/**
82+
* Cast to array to avoid triggering the __get() method in the WP_Site class. This is a performance boost.
83+
*
84+
* The __get() method is triggered when accessing a property that does not exist in the class,
85+
* and since it uses `switch default`, it will trigger a get_blog_details() for any property that does not exist.
86+
*
87+
* Below we try to use get_blog_deatis only once for each property per site.
88+
*/
8189
$s = (array) $site;
8290
$blogname = get_site_meta( $s['blog_id'], 'blogname', true );
8391
$siteurl = get_site_meta( $s['blog_id'], 'siteurl', true );

0 commit comments

Comments
 (0)