Make WordPress Core

Ticket #32450: 32450.2.diff

File 32450.2.diff, 6.2 KB (added by jeremyfelt, 8 years ago)
  • src/wp-includes/class-wp-site.php

     
     1<?php
     2/**
     3 * Site API: WP_Site class
     4 *
     5 * @package WordPress
     6 * @subpackage Multisite
     7 * @since 4.5.0
     8 */
     9
     10/**
     11 * Core class used for interacting with a multisite site.
     12 *
     13 * This class is used during load to populate the `$current_blog` global and
     14 * setup the current site.
     15 *
     16 * @since 4.5.0
     17 */
     18final class WP_Site {
     19
     20        /**
     21         * Site ID.
     22         *
     23         * @since 4.5.0
     24         * @access public
     25         * @var int
     26         */
     27        public $blog_id;
     28
     29        /**
     30         * Domain of the site.
     31         *
     32         * @since 4.5.0
     33         * @access public
     34         * @var string
     35         */
     36        public $domain = '';
     37
     38        /**
     39         * Path of the site.
     40         *
     41         * @since 4.5.0
     42         * @access public
     43         * @var string
     44         */
     45        public $path = '';
     46
     47        /**
     48         * The ID of the site's parent network.
     49         *
     50         * Named "site" vs. "network" for legacy reasons. An individual site's "site" is
     51         * its network.
     52         *
     53         * @since 4.5.0
     54         * @access public
     55         * @var int
     56         */
     57        public $site_id = 0;
     58
     59        /**
     60         * The date on which the site was created or registered.
     61         *
     62         * @since 4.5.0
     63         * @access public
     64         * @var string Date in MySQL's datetime format.
     65         */
     66        public $registered = '0000-00-00 00:00:00';
     67
     68        /**
     69         * The date and time on which site settings were last updated.
     70         *
     71         * @since 4.5.0
     72         * @access public
     73         * @var string Date in MySQL's datetime format.
     74         */
     75        public $last_updated = '0000-00-00 00:00:00';
     76
     77        /**
     78         * Whether the site should be treated as public.
     79         *
     80         * @since 4.5.0
     81         * @access public
     82         * @var int
     83         */
     84        public $public = 1;
     85
     86        /**
     87         * Whether the site should be treated as archived.
     88         *
     89         * @since 4.5.0
     90         * @access public
     91         * @var int
     92         */
     93        public $archived = 0;
     94
     95        /**
     96         * Whether the site should be treated as mature.
     97         *
     98         * Handling for this does not exist throughout WordPress core, but custom
     99         * implementations exist that require the property to be present.
     100         *
     101         * @since 4.5.0
     102         * @access public
     103         * @var int
     104         */
     105        public $mature = 0;
     106
     107        /**
     108         * Whether the site should be treated as spam.
     109         *
     110         * @since 4.5.0
     111         * @access public
     112         * @var int
     113         */
     114        public $spam = 0;
     115
     116        /**
     117         * Whether the site should be treated as deleted.
     118         *
     119         * @since 4.5.0
     120         * @access public
     121         * @var int
     122         */
     123        public $deleted = 0;
     124
     125        /**
     126         * The language pack associated with this site.
     127         *
     128         * @since 4.5.0
     129         * @access public
     130         * @var int
     131         */
     132        public $lang_id = 0;
     133
     134        /**
     135         * Retrieve a site from the database by its ID.
     136         *
     137         * @since 4.5.0
     138         * @access public
     139         *
     140         * @global wpdb $wpdb WordPress database abstraction object.
     141         *
     142         * @param int $site_id The ID of the site to retrieve.
     143         * @return WP_Site|bool The site's object if found. False if not.
     144         */
     145        public static function get_instance( $site_id ) {
     146                global $wpdb;
     147
     148                $site_id = (int) $site_id;
     149                if ( ! $site_id ) {
     150                        return false;
     151                }
     152
     153                $_site = wp_cache_get( $site_id, 'sites' );
     154
     155                if ( ! $_site ) {
     156                        $_site = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->blogs} WHERE blog_id = %d LIMIT 1", $site_id ) );
     157
     158                        if ( empty( $_site ) || is_wp_error( $_site ) ) {
     159                                return false;
     160                        }
     161
     162                        wp_cache_add( $site_id, $_site, 'sites' );
     163                }
     164
     165                return new WP_Site( $_site );
     166        }
     167
     168        /**
     169         * Create a new WP_Site object.
     170         *
     171         * Will populate object properties from the object provided and assign other
     172         * default properties based on that information.
     173         *
     174         * @since 4.5.0
     175         * @access public
     176         *
     177         * @param WP_Site|object $site A site object.
     178         */
     179        public function __construct( $site ) {
     180                foreach( get_object_vars( $site ) as $key => $value ) {
     181                        $this->$key = $value;
     182                }
     183        }
     184}
  • src/wp-includes/ms-blogs.php

     
    210210        }
    211211
    212212        if ( empty($details) ) {
    213                 $details = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->blogs WHERE blog_id = %d /* get_blog_details */", $blog_id ) );
     213                $details = WP_Site::get_instance( $blog_id );
    214214                if ( ! $details ) {
    215215                        // Set the full cache.
    216216                        wp_cache_set( $blog_id, -1, 'blog-details' );
     
    218218                }
    219219        }
    220220
     221        if ( ! $details instanceof WP_Site ) {
     222                $details = new WP_Site( $details );
     223        }
     224
    221225        if ( ! $get_all ) {
    222226                wp_cache_set( $blog_id . $all, $details, 'blog-details' );
    223227                return $details;
     
    442446        $blog_id = $blog->blog_id;
    443447        $domain_path_key = md5( $blog->domain . $blog->path );
    444448
     449        wp_cache_delete( $blog_id, 'sites' );
    445450        wp_cache_delete( $blog_id , 'blog-details' );
    446451        wp_cache_delete( $blog_id . 'short' , 'blog-details' );
    447452        wp_cache_delete(  $domain_path_key, 'blog-lookup' );
     
    655660                        if ( is_array( $global_groups ) ) {
    656661                                wp_cache_add_global_groups( $global_groups );
    657662                        } else {
    658                                 wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'user_meta', 'useremail', 'userslugs', 'site-transient', 'site-options', 'site-lookup', 'blog-lookup', 'blog-details', 'rss', 'global-posts', 'blog-id-cache', 'networks' ) );
     663                                wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'user_meta', 'useremail', 'userslugs', 'site-transient', 'site-options', 'site-lookup', 'blog-lookup', 'blog-details', 'rss', 'global-posts', 'blog-id-cache', 'networks', 'sites' ) );
    659664                        }
    660665                        wp_cache_add_non_persistent_groups( array( 'comment', 'counts', 'plugins' ) );
    661666                }
  • src/wp-includes/ms-settings.php

     
    1313/** WP_Network class */
    1414require_once( ABSPATH . WPINC . '/class-wp-network.php' );
    1515
     16/** WP_Site class */
     17require_once( ABSPATH . WPINC . '/class-wp-site.php' );
     18
    1619/** Multisite loader */
    1720require_once( ABSPATH . WPINC . '/ms-load.php' );
    1821
     
    222225        $current_site = new WP_Network( $current_site );
    223226}
    224227
     228if ( ! $current_blog instanceof WP_Site ) {
     229        $current_blog = new WP_Site( $current_blog );
     230}
     231
    225232// Define upload directory constants
    226233ms_upload_constants();