Make WordPress Core

Ticket #11644: 11644.9.diff

File 11644.9.diff, 14.6 KB (added by nacin, 15 years ago)

More multisite initialization cleanup

  • wp-includes/default-constants.php

     
    11<?php
    2 
    32/**
    43 * Defines constants and global variables that can be overridden, generally in wp-config.php.
    54 *
     
    9493                         * Allows for the plugins directory to be moved from the default location.
    9594                         *
    9695                         * @since 2.1.0
     96                         * @deprecated
    9797                         */
    9898                        if ( !defined('PLUGINDIR') )
    9999                                define( 'PLUGINDIR', 'wp-content/plugins' ); // Relative to ABSPATH.  For back compat.
    100                         break;
    101100
    102                 case 'ms_network_settings_loaded':
    103 
    104101                        /**
    105102                         * Allows for the mu-plugins directory to be moved from the default location.
    106103                         *
     
    121118                         * Allows for the mu-plugins directory to be moved from the default location.
    122119                         *
    123120                         * @since 2.8.0
     121                         * @deprecated
    124122                         */
    125123                        if ( !defined( 'MUPLUGINDIR' ) )
    126124                                define( 'MUPLUGINDIR', 'wp-content/mu-plugins' ); // Relative to ABSPATH.  For back compat.
     
    149147                        $wp_default_secret_key = 'put your unique phrase here';
    150148
    151149                        /**
    152                          * It is possible to define this in wp-config.php
    153150                         * @since 2.0.0
    154151                         */
    155152                        if ( !defined('USER_COOKIE') )
    156153                                define('USER_COOKIE', 'wordpressuser_' . COOKIEHASH);
    157154
    158155                        /**
    159                          * It is possible to define this in wp-config.php
    160156                         * @since 2.0.0
    161157                         */
    162158                        if ( !defined('PASS_COOKIE') )
    163159                                define('PASS_COOKIE', 'wordpresspass_' . COOKIEHASH);
    164160
    165161                        /**
    166                          * It is possible to define this in wp-config.php
    167162                         * @since 2.5.0
    168163                         */
    169164                        if ( !defined('AUTH_COOKIE') )
    170165                                define('AUTH_COOKIE', 'wordpress_' . COOKIEHASH);
    171166
    172167                        /**
    173                          * It is possible to define this in wp-config.php
    174168                         * @since 2.6.0
    175169                         */
    176170                        if ( !defined('SECURE_AUTH_COOKIE') )
    177171                                define('SECURE_AUTH_COOKIE', 'wordpress_sec_' . COOKIEHASH);
    178172
    179173                        /**
    180                          * It is possible to define this in wp-config.php
    181174                         * @since 2.6.0
    182175                         */
    183176                        if ( !defined('LOGGED_IN_COOKIE') )
    184177                                define('LOGGED_IN_COOKIE', 'wordpress_logged_in_' . COOKIEHASH);
    185178
    186179                        /**
    187                          * It is possible to define this in wp-config.php
    188180                         * @since 2.3.0
    189181                         */
    190182                        if ( !defined('TEST_COOKIE') )
    191183                                define('TEST_COOKIE', 'wordpress_test_cookie');
    192184
    193185                        /**
    194                          * It is possible to define this in wp-config.php
    195186                         * @since 1.2.0
    196187                         */
    197188                        if ( !defined('COOKIEPATH') )
    198189                                define('COOKIEPATH', preg_replace('|https?://[^/]+|i', '', get_option('home') . '/' ) );
    199190
    200191                        /**
    201                          * It is possible to define this in wp-config.php
    202192                         * @since 1.5.0
    203193                         */
    204194                        if ( !defined('SITECOOKIEPATH') )
    205195                                define('SITECOOKIEPATH', preg_replace('|https?://[^/]+|i', '', get_option('siteurl') . '/' ) );
    206196
    207197                        /**
    208                          * It is possible to define this in wp-config.php
    209198                         * @since 2.6.0
    210199                         */
    211200                        if ( !defined('ADMIN_COOKIE_PATH') )
    212201                                define( 'ADMIN_COOKIE_PATH', SITECOOKIEPATH . 'wp-admin' );
    213202
    214203                        /**
    215                          * It is possible to define this in wp-config.php
    216204                         * @since 2.6.0
    217205                         */
    218206                        if ( !defined('PLUGINS_COOKIE_PATH') )
    219207                                define( 'PLUGINS_COOKIE_PATH', preg_replace('|https?://[^/]+|i', '', WP_PLUGIN_URL)  );
    220208
    221209                        /**
    222                          * It is possible to define this in wp-config.php
    223210                         * @since 2.0.0
    224211                         */
    225212                        if ( !defined('COOKIE_DOMAIN') )
    226213                                define('COOKIE_DOMAIN', false);
    227214
    228215                        /**
    229                          * It is possible to define this in wp-config.php
    230216                         * @since 2.6.0
    231217                         */
    232218                        if ( !defined('FORCE_SSL_ADMIN') )
     
    234220                        force_ssl_admin(FORCE_SSL_ADMIN);
    235221
    236222                        /**
    237                          * It is possible to define this in wp-config.php
    238223                         * @since 2.6.0
    239224                         */
    240225                        if ( !defined('FORCE_SSL_LOGIN') )
     
    242227                        force_ssl_login(FORCE_SSL_LOGIN);
    243228
    244229                        /**
    245                          * It is possible to define this in wp-config.php
    246230                         * @since 2.5.0
    247231                         */
    248232                        if ( !defined( 'AUTOSAVE_INTERVAL' ) )
    249233                                define( 'AUTOSAVE_INTERVAL', 60 );
    250234
    251235                        /**
    252                          * It is possible to define this in wp-config.php
    253236                         * @since 2.9.0
    254237                         */
    255238                        if ( !defined( 'EMPTY_TRASH_DAYS' ) )
  • wp-includes/ms-default-constants.php

     
    1616        switch( $context ) {
    1717                case 'uploads' :
    1818                        global $wpdb;
     19                        /** @since 3.0.0 */
    1920                        if ( !defined( 'UPLOADBLOGSDIR' ) )
    2021                                define( 'UPLOADBLOGSDIR', 'wp-content/blogs.dir' );
    21                
     22                        /** @since 3.0.0 */
    2223                        if ( !defined( 'UPLOADS' ) )
    2324                                define( 'UPLOADS', UPLOADBLOGSDIR . "/{$wpdb->blogid}/files/" );
    24                
     25                        /** @since 3.0.0 */
    2526                        if ( !defined( 'BLOGUPLOADDIR' ) )
    2627                                define( 'BLOGUPLOADDIR', WP_CONTENT_DIR . "/blogs.dir/{$wpdb->blogid}/files/" );
    2728                        break;
    2829                case 'cookies' :
    2930                        global $current_site;
    3031                        /**
    31                          * It is possible to define this in wp-config.php
    3232                         * @since 1.2.0
    3333                         */
    3434                        if ( !defined( 'COOKIEPATH' ) )
    3535                                        define( 'COOKIEPATH', $current_site->path );
    36        
    3736                        /**
    38                          * It is possible to define this in wp-config.php
    3937                         * @since 1.5.0
    4038                         */
    4139                        if ( !defined( 'SITECOOKIEPATH' ) )
    4240                                        define( 'SITECOOKIEPATH', $current_site->path );
    43        
    4441                        /**
    45                          * It is possible to define this in wp-config.php
    4642                         * @since 2.6.0
    4743                         */
    4844                        if ( !defined( 'ADMIN_COOKIE_PATH' ) ) {
     
    5349                                        }
    5450                        }
    5551                        /**
    56                          * It is possible to define this in wp-config.php
    5752                         * @since 2.0.0
    5853                         */
    5954                        if ( !defined('COOKIE_DOMAIN') )
  • wp-includes/ms-load.php

     
    99 */
    1010
    1111/**
    12  * Whether a subdomain configuration is enabled
     12 * Whether a subdomain configuration is enabled.
    1313 *
    1414 * @since 3.0
    1515 *
     
    2222        return false;
    2323}
    2424
    25 function ms_network_settings() {
    26         global $wpdb, $current_site, $cookiehash;
    27 
    28         if ( !isset($current_site->site_name) )
    29                 $current_site->site_name = get_site_option('site_name');
    30 
    31         if ( $current_site->site_name == false )
    32                 $current_site->site_name = ucfirst( $current_site->domain );
    33 }
    34 
     25/**
     26 * Returns array of sitewide plugin files to be included in global scope.
     27 *
     28 * @access private
     29 * @since 3.0.0
     30 * @return array Files to include
     31 */
    3532function ms_network_plugins() {
    3633        $network_plugins = array();
    3734        $deleted_sitewide_plugins = array();
     
    6259        return $network_plugins;
    6360}
    6461
     62/**
     63 * Checks status of current blog.
     64 *
     65 * Checks if the blog is deleted, inactive, archived, or spammed.
     66 *
     67 * Dies with a default message if the blog does not pass the check.
     68 *
     69 * To change the default message when a blog does not pass the check,
     70 * use the wp-content/blog-deleted.php, blog-inactive.php and
     71 * blog-suspended.php drop-ins.
     72 *
     73 * @return bool|string Returns true on success, or drop-in file to include.
     74 */
    6575function ms_site_check() {
    6676        global $wpdb, $current_blog;
    6777
     
    6979                        if ( file_exists( WP_CONTENT_DIR . '/blog-deleted.php' ) ) {
    7080                                        return WP_CONTENT_DIR . '/blog-deleted.php';
    7181                        } else {
    72                                         header('HTTP/1.1 410 Gone');
    73                                         wp_die(__('This user has elected to delete their account and the content is no longer available.'));
     82                                        header( 'HTTP/1.1 410 Gone' );
     83                                        wp_die( __( 'This user has elected to delete their account and the content is no longer available.' ) );
    7484                        }
    75         } elseif ( '2' == $current_blog->deleted ) {
     85        }
     86
     87        if ( '2' == $current_blog->deleted ) {
    7688                        if ( file_exists( WP_CONTENT_DIR . '/blog-inactive.php' ) )
    7789                                return WP_CONTENT_DIR . '/blog-inactive.php';
    7890                        else
     
    8395                        if ( file_exists( WP_CONTENT_DIR . '/blog-suspended.php' ) ) {
    8496                                        return WP_CONTENT_DIR . '/blog-suspended.php';
    8597                        } else {
    86                                         header('HTTP/1.1 410 Gone');
    87                                         wp_die(__('This blog has been archived or suspended.'));
     98                                        header( 'HTTP/1.1 410 Gone' );
     99                                        wp_die( __( 'This blog has been archived or suspended.' ) );
    88100                        }
    89101        }
    90102
    91103        return true;
    92104}
    93105
     106/**
     107 * Gets current site name.
     108 *
     109 * @since 3.0.0
     110 * @return string Name of site
     111 */
    94112function get_current_site_name( $current_site ) {
    95113        global $wpdb;
    96114        $current_site->site_name = wp_cache_get( $current_site->id . ':current_site_name', "site-options" );
    97         if ( !$current_site->site_name ) {
     115        if ( ! $current_site->site_name ) {
    98116                $current_site->site_name = $wpdb->get_var( $wpdb->prepare( "SELECT meta_value FROM $wpdb->sitemeta WHERE site_id = %d AND meta_key = 'site_name'", $current_site->id ) );
    99                 if ( $current_site->site_name == null )
     117                if ( ! $current_site->site_name )
    100118                        $current_site->site_name = ucfirst( $current_site->domain );
    101                 wp_cache_set( $current_site->id . ':current_site_name', $current_site->site_name, 'site-options');
     119                wp_cache_set( $current_site->id . ':current_site_name', $current_site->site_name, 'site-options' );
    102120        }
    103121        return $current_site;
    104122}
     
    186204function is_installed() {
    187205        global $wpdb, $domain, $path;
    188206        $base = stripslashes( $base );
    189         if ( defined( "WP_INSTALLING" ) == false ) {
    190                 $check = $wpdb->get_results( "SELECT * FROM $wpdb->site" );
    191                 $msg = "If your blog does not display, please contact the owner of this site.<br /><br />If you are the owner of this site please check that MySQL is running properly and all tables are error free.<br /><br />";
    192                 if ( $check == false ) {
    193                         $msg .= "<strong>Database Tables Missing.</strong><br />Database tables are missing. This means that MySQL is either not running, WPMU was not installed properly, or someone deleted {$wpdb->site}. You really <em>should</em> look at your database now.<br />";
    194                 } else {
    195                         $msg .= '<strong>Could Not Find Blog!</strong><br />';
    196                         $msg .= "Searched for <em>" . $domain . $path . "</em> in " . DB_NAME . "::" . $wpdb->blogs . " table. Is that right?<br />";
    197                 }
    198                 $msg .= "<br />\n<h1>What do I do now?</h1>";
    199                 $msg .= "Read the <a target='_blank' href='http://codex.wordpress.org/Debugging_WPMU'>bug report</a> page. Some of the guidelines there may help you figure out what went wrong.<br />";
    200                 $msg .= "If you're still stuck with this message, then check that your database contains the following tables:<ul>
    201                         <li> $wpdb->blogs </li>
    202                         <li> $wpdb->users </li>
    203                         <li> $wpdb->usermeta </li>
    204                         <li> $wpdb->site </li>
    205                         <li> $wpdb->sitemeta </li>
    206                         <li> $wpdb->sitecategories </li>
    207                         </ul>";
    208                 $msg .= "If you suspect a problem please report it to the support forums but you must include the information asked for in the <a href='http://codex.wordpress.org/Debugging_WPMU'>WPMU bug reporting guidelines</a>!<br /><br />";
    209                 if ( is_file( 'release-info.txt' ) ) {
    210                         $msg .= 'Your bug report must include the following text: "';
    211                         $info = file( 'release-info.txt' );
    212                         $msg .= $info[ 4 ] . '"';
    213                 }
     207        if ( defined( 'WP_INSTALLING' ) )
     208                return;
    214209
    215                 die( "<h1>Fatal Error</h1> " . $msg );
     210        $msg = '<h1>' . esc_html__( 'Fatal Error' ) . '</h1>';
     211        $msg  = '<p>' . __( 'If your blog does not display, please contact the owner of this site.' ) . '</p>';
     212        $msg .= '<p>' . __( 'If you are the owner of this site please check that MySQL is running properly and all tables are error free.' ) . '</p>';
     213        if ( ! $wpdb->get_var( "SHOW TABLES LIKE '$wpdb->site'" ) )
     214                $msg .= '<p>' . sprintf( __( '<strong>Database tables are missing.</strong> This means that MySQL is not running, WordPress was not installed properly, or someone deleted <code>%s</code>. You really <em>should</em> look at your database now.' ), $wpdb->site ) . '</p>';
     215        else
     216                $msg .= '<p>' . sprintf( __( '<strong>Could Not Find Blog!</strong> Searched for table <em>%1$s</em> in <code>%2$s</code>. Is that right?' ), $domain . $path, DB_NAME, $wpdb->blogs ) . '</p>';
     217        $msg .= '<h1>' . esc_html__( 'What do I do now?' ) . '</h1>';
     218        // @todo Update WPMU codex link.
     219        $msg .= '<p>' . __( 'Read the <a target="_blank" href="http://codex.wordpress.org/Debugging_WPMU">bug report</a> page. Some of the guidelines there may help you figure out what went wrong.' ) . '</p>';
     220        $msg .= '<p>' . __( "If you're still stuck with this message, then check that your database contains the following tables:" ) . '</p><ul>';
     221        foreach ( $wpdb->global_tables as $table ) {
     222                $msg .= '<li>' . $wpdb->prefix . $table . '</li>';
    216223        }
     224        $msg .= '</ul>';
     225        // @todo Update WPMU codex link and support instructions.
     226        $msg = '<p>' . __( 'If you suspect a problem please report it to the support forums but you must include the information asked for in the <a target="_blank" href="http://codex.wordpress.org/Debugging_WPMU">WPMU bug reporting guidelines</a>! ' ) . '</p>';
     227
     228        // @todo This file no longer exists post-merge.
     229        if ( is_file( 'release-info.txt' ) ) {
     230                $msg .= '<p>' . __( 'Your bug report must include the following text:' ) . '</p>';
     231                $info = file( 'release-info.txt' );
     232                $msg .= $info[ 4 ] . '"';
     233        }
     234
     235        die( $msg );
    217236}
    218237
    219238?>
  • wp-includes/ms-settings.php

     
    6464                $blogname = substr( $blogname, 0, strpos( $blogname, '?' ) );
    6565        $reserved_blognames = array( 'page', 'comments', 'blog', 'wp-admin', 'wp-includes', 'wp-content', 'files', 'feed' );
    6666        if ( $blogname != '' && ! in_array( $blogname, $reserved_blognames ) && ! is_file( $blogname ) )
    67                 $path = $path . $blogname . '/';
     67                $path .= $blogname . '/';
    6868        $current_blog = wp_cache_get( 'current_blog_' . $domain . $path, 'site-options' );
    6969        if ( ! $current_blog ) {
    7070                $current_blog = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->blogs WHERE domain = %s AND path = %s", $domain, $path ) );
     
    104104        $current_blog->site_id = 1;
    105105$site_id = $current_blog->site_id;
    106106
    107 $current_site = get_current_site_name( $current_site );
    108 
    109107if ( ! $blog_id ) {
    110108        if ( defined('WP_INSTALLING') ) {
    111109                $current_blog->blog_id = $blog_id = 1;
     
    120118$wpdb->set_prefix( $table_prefix ); // set up blog tables
    121119$table_prefix = $wpdb->get_blog_prefix();
    122120
     121$current_site = get_current_site_name( $current_site );
     122
    123123// need to init cache again after blog_id is set
    124124wp_start_object_cache();
    125125
  • wp-settings.php

     
    132132}
    133133
    134134// Define constants that rely on the API to obtain the default value.
     135// Define must-use plugin directory constants, which may be overridden in the sunrise.php drop-in.
    135136wp_default_constants( 'wp_included' );
    136137
    137 // Set up multisite if enabled.
    138 if ( is_multisite() )
    139         ms_network_settings();
    140 
    141 // Define must-use plugin directory constants, which may be overridden in the sunrise.php drop-in.
    142 wp_default_constants( 'ms_network_settings_loaded' );
    143 
    144138// Load must-use plugins.
    145139foreach( wp_muplugins_to_load() as $mu_plugin )
    146140        include_once( $mu_plugin );