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

WordPress Trac noreply at wordpress.org
Tue Jul 25 19:08:45 UTC 2017


#29684: Add get_main_site() function
-------------------------------------------------+-------------------------
 Reporter:  rmccue                               |       Owner:  flixos90
     Type:  enhancement                          |      Status:  accepted
 Priority:  normal                               |   Milestone:  4.9
Component:  Networks and Sites                   |     Version:  3.9
 Severity:  normal                               |  Resolution:
 Keywords:  has-patch has-unit-tests dev-        |     Focuses:  multisite
  feedback                                       |
-------------------------------------------------+-------------------------

Comment (by spacedmonkey):

 My recommend is the following.

 That we change `WP_Network` so that it uses a magic getter on `blog_id`,
 to dynamically load the blog id. Code found in the bootstrap process can
 be moved into the `WP_Network` class. Specially these lines

 {{{#!php

 if ( ! $current_site->blog_id = wp_cache_get( 'network:' .
 $current_site->id . ':main_site', 'site-options' ) ) {
                         $current_site->blog_id = $wpdb->get_var(
 $wpdb->prepare( "SELECT blog_id FROM $wpdb->blogs WHERE domain = %s AND
 path = %s",
                                 $current_site->domain, $current_site->path
 ) );
                         wp_cache_add( 'network:' . $current_site->id .
 ':main_site', $current_site->blog_id, 'site-options' );

 }}}
 Instead of caching the result in object cache, it should be cached as a
 network option. The network option of main_site should be populared on
 network creation as well.

 This add a massive benefit of being about to do this as well,
 `get_network(33)->blog_id` and be able to trust that `blog_id` is always
 set.

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


More information about the wp-trac mailing list