[wp-trac] [WordPress Trac] #29684: Add get_main_site_id() function

WordPress Trac noreply at wordpress.org
Thu Aug 31 13:15:52 UTC 2017


#29684: Add get_main_site_id() function
-------------------------------------------------+-------------------------
 Reporter:  rmccue                               |       Owner:  jeremyfelt
     Type:  enhancement                          |      Status:  reviewing
 Priority:  normal                               |   Milestone:  4.9
Component:  Networks and Sites                   |     Version:  3.9
 Severity:  normal                               |  Resolution:
 Keywords:  has-patch has-unit-tests ms-roadmap  |     Focuses:  multisite
-------------------------------------------------+-------------------------

Comment (by spacedmonkey):

 [https://core.trac.wordpress.org/attachment/ticket/29684/29684.14.diff
 29684.14.diff]

 Is a big refactor of the code. Key points.
 - Moved logic from `get_main_site_id` to `get_main_site_id` method on
 WP_Network. This has a number of benefits. It keeps logic related to the
 WP_Network class, in it's class. You can also check to see if `blog_id` is
 already set before doing anything. It can also just reference other class
 level properties really easily.
 - Only run the logic once and just reference `blog_id` going forward. This
 is a performance win, as stop code running unnecessarily.
 - In ms-load.php I removed repeated logic. It is not required, as
 get_main_site_id method will do it now.
 - In ms-load.php pass the object instead of the id into get_main_site_id.
 This just force the getter to run making sure that `blog_id` is already
 set.




 The key point about this change is the `blog_id` should be seen as truth,
 not the function. If you setup your own `$current_site` with your own
 logic in the sunrise, you should never need this code.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/29684#comment:33>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list