Make WordPress Core

Ticket #36935: 36935.3.diff

File 36935.3.diff, 11.7 KB (added by flixos90, 9 years ago)
  • src/wp-includes/class-wp-site.php

     
    1515 *
    1616 * @since 4.5.0
    1717 *
    18  * @property int $id
    19  * @property int $network_id
     18 * @property      int    $id
     19 * @property      int    $network_id
     20 * @property-read string $blogname
     21 * @property-read string $siteurl
     22 * @property-read string $post_count
     23 * @property-read string $home
    2024 */
    2125final class WP_Site {
    2226
     
    218222         * Getter.
    219223         *
    220224         * Allows current multisite naming conventions when getting properties.
     225         * Also allows to access extended properties from blog details.
    221226         *
    222227         * @since 4.6.0
    223228         * @access public
     
    235240                                return $this->site_id;
    236241                        case 'network_id':
    237242                                return (int) $this->site_id;
     243                        case 'blogname':
     244                        case 'siteurl':
     245                        case 'post_count':
     246                        case 'home':
     247                                $details = $this->get_details();
     248                                return $details->$key;
    238249                }
    239250
    240251                return null;
     
    244255         * Isset-er.
    245256         *
    246257         * Allows current multisite naming conventions when checking for properties.
     258         * Also successfully checks for extended properties from blog details.
    247259         *
    248260         * @since 4.6.0
    249261         * @access public
     
    257269                        case 'blog_id':
    258270                        case 'site_id':
    259271                        case 'network_id':
     272                        case 'blogname':
     273                        case 'siteurl':
     274                        case 'post_count':
     275                        case 'home':
    260276                                return true;
    261277                }
    262278
     
    288304                                $this->$key = $value;
    289305                }
    290306        }
     307
     308        /**
     309         * Retrieve the details for this site.
     310         *
     311         * This method is used internally to lazy-load the extended properties of a site.
     312         *
     313         * @since 4.6.0
     314         * @access private
     315         *
     316         * @see WP_Site::__get()
     317         *
     318         * @return object A raw site object with all details included.
     319         */
     320        private function get_details() {
     321                $details = wp_cache_get( $this->blog_id, 'site-details' );
     322
     323                if ( $details ) {
     324                        return $details;
     325                }
     326
     327                switch_to_blog( $this->blog_id );
     328                // Create a raw copy of the object for backwards compatibility with the filter below.
     329                $details = new stdClass();
     330                foreach ( get_object_vars( $this ) as $key => $value ) {
     331                        $details->$key = $value;
     332                }
     333                $details->blogname   = get_option( 'blogname' );
     334                $details->siteurl    = get_option( 'siteurl' );
     335                $details->post_count = get_option( 'post_count' );
     336                $details->home       = get_option( 'home' );
     337                restore_current_blog();
     338
     339                /**
     340                 * Filters a blog's details.
     341                 *
     342                 * @since MU
     343                 *
     344                 * @param object $details The blog details.
     345                 */
     346                $details = apply_filters( 'blog_details', $details );
     347
     348                wp_cache_set( $this->blog_id, $details, 'site-details' );
     349
     350                return $details;
     351        }
    291352}
  • src/wp-includes/load.php

     
    183183        // If the $upgrading timestamp is older than 10 minutes, don't die.
    184184        if ( ( time() - $upgrading ) >= 600 )
    185185                return;
    186        
     186
    187187        /**
    188188         * Bypass the maintenance mode check
    189189         *
    190190         * This filter should *NOT* be used by plugins. It is designed for non-web
    191          * runtimes. If this filter returns true, maintenance mode will not be 
     191         * runtimes. If this filter returns true, maintenance mode will not be
    192192         * active which can cause problems during updates for web site views.
    193193         *
    194194         * @since 4.6.0
     
    196196         * @param bool True to bypass maintenance
    197197         */
    198198        if ( apply_filters( 'bypass_maintenance_mode', false ) ){
    199                 return; 
     199                return;
    200200        }
    201201
    202202        if ( file_exists( WP_CONTENT_DIR . '/maintenance.php' ) ) {
     
    310310         *
    311311         * @since 4.6.0
    312312         *
    313          * @param bool True to bypass debug mode 
     313         * @param bool True to bypass debug mode
    314314         */
    315315        if ( apply_filters( 'bypass_debug_mode', false ) ){
    316                 return; 
     316                return;
    317317        }
    318318
    319319        if ( WP_DEBUG ) {
     
    507507                wp_cache_init();
    508508
    509509        if ( function_exists( 'wp_cache_add_global_groups' ) ) {
    510                 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' ) );
     510                wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'user_meta', 'useremail', 'userslugs', 'site-transient', 'site-options', 'site-lookup', 'blog-lookup', 'blog-details', 'site-details', 'rss', 'global-posts', 'blog-id-cache', 'networks', 'sites' ) );
    511511                wp_cache_add_non_persistent_groups( array( 'counts', 'plugins' ) );
    512512        }
    513513}
  • src/wp-includes/ms-blogs.php

     
    108108 * Retrieve the details for a blog from the blogs table and blog options.
    109109 *
    110110 * @since MU
     111 * @since 4.6.0 Extended blog details are lazy-loaded through `WP_Site` and are available as object properties
     112 *              regardless of the `$get_all` parameter.
    111113 *
    112114 * @global wpdb $wpdb WordPress database abstraction object.
    113115 *
     
    126128                } elseif ( isset($fields['domain']) && isset($fields['path']) ) {
    127129                        $key = md5( $fields['domain'] . $fields['path'] );
    128130                        $blog = wp_cache_get($key, 'blog-lookup');
    129                         if ( false !== $blog )
    130                                 return $blog;
    131                         if ( substr( $fields['domain'], 0, 4 ) == 'www.' ) {
    132                                 $nowww = substr( $fields['domain'], 4 );
    133                                 $blog = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->blogs WHERE domain IN (%s,%s) AND path = %s ORDER BY CHAR_LENGTH(domain) DESC", $nowww, $fields['domain'], $fields['path'] ) );
    134                         } else {
    135                                 $blog = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->blogs WHERE domain = %s AND path = %s", $fields['domain'], $fields['path'] ) );
    136                         }
    137131                        if ( $blog ) {
    138                                 wp_cache_set($blog->blog_id . 'short', $blog, 'blog-details');
    139132                                $blog_id = $blog->blog_id;
    140133                        } else {
    141                                 return false;
     134                                if ( substr( $fields['domain'], 0, 4 ) == 'www.' ) {
     135                                        $nowww = substr( $fields['domain'], 4 );
     136                                        $blog = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->blogs WHERE domain IN (%s,%s) AND path = %s ORDER BY CHAR_LENGTH(domain) DESC", $nowww, $fields['domain'], $fields['path'] ) );
     137                                } else {
     138                                        $blog = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->blogs WHERE domain = %s AND path = %s", $fields['domain'], $fields['path'] ) );
     139                                }
     140                                if ( $blog ) {
     141                                        $key = md5( $blog->domain . $blog->path );
     142                                        wp_cache_set( $key, $blog, 'blog-lookup' );
     143                                        $blog_id = $blog->blog_id;
     144                                } else {
     145                                        return false;
     146                                }
    142147                        }
    143148                } elseif ( isset($fields['domain']) && is_subdomain_install() ) {
    144149                        $key = md5( $fields['domain'] );
     
    152157                                $blog = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->blogs WHERE domain = %s", $fields['domain'] ) );
    153158                        }
    154159                        if ( $blog ) {
    155                                 wp_cache_set($blog->blog_id . 'short', $blog, 'blog-details');
     160                                $key = md5( $blog->domain );
     161                                wp_cache_set( $key, $blog, 'blog-lookup' );
    156162                                $blog_id = $blog->blog_id;
    157163                        } else {
    158164                                return false;
     
    171177
    172178        $blog_id = (int) $blog_id;
    173179
    174         $all = $get_all == true ? '' : 'short';
    175         $details = wp_cache_get( $blog_id . $all, 'blog-details' );
    176 
    177         if ( $details ) {
    178                 if ( ! is_object( $details ) ) {
    179                         if ( $details == -1 ) {
    180                                 return false;
    181                         } else {
    182                                 // Clear old pre-serialized objects. Cache clients do better with that.
    183                                 wp_cache_delete( $blog_id . $all, 'blog-details' );
    184                                 unset($details);
    185                         }
    186                 } else {
    187                         return $details;
    188                 }
    189         }
    190 
    191         // Try the other cache.
    192         if ( $get_all ) {
    193                 $details = wp_cache_get( $blog_id . 'short', 'blog-details' );
     180        if ( isset( $blog ) ) {
     181                $blog = new WP_Site( $blog );
    194182        } else {
    195                 $details = wp_cache_get( $blog_id, 'blog-details' );
    196                 // If short was requested and full cache is set, we can return.
    197                 if ( $details ) {
    198                         if ( ! is_object( $details ) ) {
    199                                 if ( $details == -1 ) {
    200                                         return false;
    201                                 } else {
    202                                         // Clear old pre-serialized objects. Cache clients do better with that.
    203                                         wp_cache_delete( $blog_id, 'blog-details' );
    204                                         unset($details);
    205                                 }
    206                         } else {
    207                                 return $details;
    208                         }
    209                 }
     183                $blog = WP_Site::get_instance( $blog_id );
    210184        }
    211185
    212         if ( empty($details) ) {
    213                 $details = WP_Site::get_instance( $blog_id );
    214                 if ( ! $details ) {
    215                         // Set the full cache.
    216                         wp_cache_set( $blog_id, -1, 'blog-details' );
    217                         return false;
    218                 }
    219         }
    220 
    221         if ( ! $details instanceof WP_Site ) {
    222                 $details = new WP_Site( $details );
    223         }
    224 
    225         if ( ! $get_all ) {
    226                 wp_cache_set( $blog_id . $all, $details, 'blog-details' );
    227                 return $details;
    228         }
    229 
    230         switch_to_blog( $blog_id );
    231         $details->blogname   = get_option( 'blogname' );
    232         $details->siteurl    = get_option( 'siteurl' );
    233         $details->post_count = get_option( 'post_count' );
    234         $details->home       = get_option( 'home' );
    235         restore_current_blog();
    236 
    237         /**
    238          * Filters a blog's details.
    239          *
    240          * @since MU
    241          *
    242          * @param object $details The blog details.
    243          */
    244         $details = apply_filters( 'blog_details', $details );
    245 
    246         wp_cache_set( $blog_id . $all, $details, 'blog-details' );
    247 
    248         $key = md5( $details->domain . $details->path );
    249         wp_cache_set( $key, $details, 'blog-lookup' );
    250 
    251         return $details;
     186        return $blog;
    252187}
    253188
    254189/**
     
    312247        if ( empty($current_details) )
    313248                return false;
    314249
    315         $current_details = get_object_vars($current_details);
     250        $current_details = $current_details->to_array();
    316251
    317252        $details = array_merge($current_details, $details);
    318253        $details['last_updated'] = current_time('mysql', true);
     
    447382        $domain_path_key = md5( $blog->domain . $blog->path );
    448383
    449384        wp_cache_delete( $blog_id, 'sites' );
    450         wp_cache_delete( $blog_id , 'blog-details' );
    451         wp_cache_delete( $blog_id . 'short' , 'blog-details' );
    452         wp_cache_delete(  $domain_path_key, 'blog-lookup' );
     385        wp_cache_delete( $blog_id, 'site-details' );
     386        wp_cache_delete( $domain_path_key, 'blog-lookup' );
    453387        wp_cache_delete( 'current_blog_' . $blog->domain, 'site-options' );
    454388        wp_cache_delete( 'current_blog_' . $blog->domain . $blog->path, 'site-options' );
    455389        wp_cache_delete( 'get_id_from_blogname_' . trim( $blog->path, '/' ), 'blog-details' );
     
    549483
    550484        foreach ( $sites as $site ) {
    551485                wp_cache_add( $site->blog_id, $site, 'sites' );
    552                 wp_cache_add( $site->blog_id . 'short', $site, 'blog-details' );
    553486        }
    554487}
    555488
     
    814747                        if ( is_array( $global_groups ) ) {
    815748                                wp_cache_add_global_groups( $global_groups );
    816749                        } else {
    817                                 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' ) );
     750                                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', 'site-details' ) );
    818751                        }
    819752                        wp_cache_add_non_persistent_groups( array( 'counts', 'plugins' ) );
    820753                }
     
    885818                        if ( is_array( $global_groups ) ) {
    886819                                wp_cache_add_global_groups( $global_groups );
    887820                        } else {
    888                                 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' ) );
     821                                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', 'site-details' ) );
    889822                        }
    890823                        wp_cache_add_non_persistent_groups( array( 'counts', 'plugins' ) );
    891824                }