Make WordPress Core

Ticket #29684: 29684.3.diff

File 29684.3.diff, 2.0 KB (added by spacedmonkey, 7 years ago)
  • src/wp-includes/class-wp-network.php

     
    157157                        case 'id':
    158158                                return (int) $this->id;
    159159                        case 'blog_id':
     160                                $this->get_blog_id();
    160161                                return $this->blog_id;
    161162                        case 'site_id':
     163                                $this->get_blog_id();
    162164                                return (int) $this->blog_id;
    163165                }
    164166
     
    405407
    406408                return false;
    407409        }
     410
     411        private function get_blog_id() {
     412                global $wpdb;
     413                if ( empty( $this->blog_id ) ) {
     414                        $blog_id = get_network_option( $this->id, 'main_site' );
     415                        if ( ! $blog_id ) {
     416                                $blog_id = $wpdb->get_var( $wpdb->prepare( "SELECT blog_id FROM $wpdb->blogs WHERE domain = %s AND path = %s", $this->domain, $this->path ) );
     417                                if ( ! $blog_id ) {
     418                                        add_network_option( $this->id, 'main_site', $blog_id );
     419                                }
     420                        }
     421                        if ( $blog_id ) {
     422                                $this->blog_id = $blog_id;
     423                        }
     424                }
     425        }
    408426}
  • src/wp-includes/ms-load.php

     
    426426        if ( empty( $current_site->blog_id ) ) {
    427427                if ( $current_blog->domain === $current_site->domain && $current_blog->path === $current_site->path ) {
    428428                        $current_site->blog_id = $current_blog->blog_id;
    429                 } elseif ( ! $current_site->blog_id = wp_cache_get( 'network:' . $current_site->id . ':main_site', 'site-options' ) ) {
     429                } elseif ( ! $current_site->blog_id = get_network_option( $current_site->id, 'main_site' ) ) {
    430430                        $current_site->blog_id = $wpdb->get_var( $wpdb->prepare( "SELECT blog_id FROM $wpdb->blogs WHERE domain = %s AND path = %s",
    431431                                $current_site->domain, $current_site->path ) );
    432                         wp_cache_add( 'network:' . $current_site->id . ':main_site', $current_site->blog_id, 'site-options' );
     432                        add_network_option( $current_site->id, 'main_site', $current_site->blog_id );
    433433                }
    434434        }
    435435