WordPress.org

Make WordPress Core

Changeset 12921


Ignore:
Timestamp:
02/01/2010 08:26:08 PM (10 years ago)
Author:
wpmuguru
Message:

reorganize code on ms startup. props nacin, see #11644

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/default-constants.php

    r12771 r12921  
    11<?php
    2 
    32/**
    43 * Defines constants and global variables that can be overridden, generally in wp-config.php.
     
    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;
    101 
    102         case 'ms_network_settings_loaded':
    103100
    104101            /**
     
    122119             *
    123120             * @since 2.8.0
     121             * @deprecated
    124122             */
    125123            if ( !defined( 'MUPLUGINDIR' ) )
     
    150148
    151149            /**
    152              * It is possible to define this in wp-config.php
    153150             * @since 2.0.0
    154151             */
     
    157154
    158155            /**
    159              * It is possible to define this in wp-config.php
    160156             * @since 2.0.0
    161157             */
     
    164160
    165161            /**
    166              * It is possible to define this in wp-config.php
    167162             * @since 2.5.0
    168163             */
     
    171166
    172167            /**
    173              * It is possible to define this in wp-config.php
    174168             * @since 2.6.0
    175169             */
     
    178172
    179173            /**
    180              * It is possible to define this in wp-config.php
    181174             * @since 2.6.0
    182175             */
     
    185178
    186179            /**
    187              * It is possible to define this in wp-config.php
    188180             * @since 2.3.0
    189181             */
     
    192184
    193185            /**
    194              * It is possible to define this in wp-config.php
    195186             * @since 1.2.0
    196187             */
     
    199190
    200191            /**
    201              * It is possible to define this in wp-config.php
    202192             * @since 1.5.0
    203193             */
     
    206196
    207197            /**
    208              * It is possible to define this in wp-config.php
    209198             * @since 2.6.0
    210199             */
     
    213202
    214203            /**
    215              * It is possible to define this in wp-config.php
    216204             * @since 2.6.0
    217205             */
     
    220208
    221209            /**
    222              * It is possible to define this in wp-config.php
    223210             * @since 2.0.0
    224211             */
     
    227214
    228215            /**
    229              * It is possible to define this in wp-config.php
    230216             * @since 2.6.0
    231217             */
     
    235221
    236222            /**
    237              * It is possible to define this in wp-config.php
    238223             * @since 2.6.0
    239224             */
     
    243228
    244229            /**
    245              * It is possible to define this in wp-config.php
    246230             * @since 2.5.0
    247231             */
     
    250234
    251235            /**
    252              * It is possible to define this in wp-config.php
    253236             * @since 2.9.0
    254237             */
  • trunk/wp-includes/ms-default-constants.php

    r12886 r12921  
    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/" );
     
    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             */
     
    5450            }
    5551            /**
    56              * It is possible to define this in wp-config.php
    5752             * @since 2.0.0
    5853             */
  • trunk/wp-includes/ms-load.php

    r12901 r12921  
    1010
    1111/**
    12  * Whether a subdomain configuration is enabled
     12 * Whether a subdomain configuration is enabled.
    1313 *
    1414 * @since 3.0
     
    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();
     
    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
    6878    if ( '1' == $current_blog->deleted ) {
    69             if ( file_exists( WP_CONTENT_DIR . '/blog-deleted.php' ) ) {
    70                     return WP_CONTENT_DIR . '/blog-deleted.php';
    71             } 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.'));
    74             }
    75     } elseif ( '2' == $current_blog->deleted ) {
    76             if ( file_exists( WP_CONTENT_DIR . '/blog-inactive.php' ) )
    77                 return WP_CONTENT_DIR . '/blog-inactive.php';
    78             else
    79                 wp_die( sprintf( __( 'This blog has not been activated yet. If you are having problems activating your blog, please contact <a href="mailto:%1$s">%1$s</a>.' ), str_replace( '@', ' AT ', get_site_option( 'admin_email', "support@{$current_site->domain}" ) ) ) );
     79        if ( file_exists( WP_CONTENT_DIR . '/blog-deleted.php' ) ) {
     80            return WP_CONTENT_DIR . '/blog-deleted.php';
     81        } else {
     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.' ) );
     84        }
     85    }
     86
     87    if ( '2' == $current_blog->deleted ) {
     88        if ( file_exists( WP_CONTENT_DIR . '/blog-inactive.php' ) )
     89            return WP_CONTENT_DIR . '/blog-inactive.php';
     90        else
     91            wp_die( sprintf( __( 'This blog has not been activated yet. If you are having problems activating your blog, please contact <a href="mailto:%1$s">%1$s</a>.' ), str_replace( '@', ' AT ', get_site_option( 'admin_email', "support@{$current_site->domain}" ) ) ) );
    8092    }
    8193
    8294    if ( $current_blog->archived == '1' || $current_blog->spam == '1' ) {
    83             if ( file_exists( WP_CONTENT_DIR . '/blog-suspended.php' ) ) {
    84                     return WP_CONTENT_DIR . '/blog-suspended.php';
    85             } else {
    86                     header('HTTP/1.1 410 Gone');
    87                     wp_die(__('This blog has been archived or suspended.'));
    88             }
     95        if ( file_exists( WP_CONTENT_DIR . '/blog-suspended.php' ) ) {
     96            return WP_CONTENT_DIR . '/blog-suspended.php';
     97        } else {
     98            header( 'HTTP/1.1 410 Gone' );
     99            wp_die( __( 'This blog has been archived or suspended.' ) );
     100        }
    89101    }
    90102
     
    92104}
    93105
     106/**
     107 * Sets current site name.
     108 *
     109 * @access private
     110 * @since 3.0.0
     111 * @return object $current_site object with site_name
     112 */
    94113function get_current_site_name( $current_site ) {
    95114    global $wpdb;
    96115    $current_site->site_name = wp_cache_get( $current_site->id . ':current_site_name', "site-options" );
    97     if ( !$current_site->site_name ) {
     116    if ( ! $current_site->site_name ) {
    98117        $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 )
     118        if ( ! $current_site->site_name )
    100119            $current_site->site_name = ucfirst( $current_site->domain );
    101         wp_cache_set( $current_site->id . ':current_site_name', $current_site->site_name, 'site-options');
     120        wp_cache_set( $current_site->id . ':current_site_name', $current_site->site_name, 'site-options' );
    102121    }
    103122    return $current_site;
    104123}
    105124
     125/**
     126 * Sets current_site object.
     127 *
     128 * @access private
     129 * @since 3.0.0
     130 * @return object $current_site object
     131 */
    106132function wpmu_current_site() {
    107133    global $wpdb, $current_site, $domain, $path, $sites, $cookie_domain;
     
    122148    }
    123149
    124     $current_site = wp_cache_get( "current_site", "site-options" );
     150    $current_site = wp_cache_get( 'current_site', 'site-options' );
    125151    if ( $current_site )
    126152        return $current_site;
    127153
    128154    $sites = $wpdb->get_results( "SELECT * FROM $wpdb->site" ); // usually only one site
    129     if ( count( $sites ) == 1 ) {
     155    if ( 1 == count( $sites ) ) {
    130156        $current_site = $sites[0];
    131157        $path = $current_site->path;
    132         $current_site->blog_id = $wpdb->get_var( "SELECT blog_id FROM {$wpdb->blogs} WHERE domain='{$current_site->domain}' AND path='{$current_site->path}'" );
     158        $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 ) );
    133159        $current_site = get_current_site_name( $current_site );
    134160        if ( substr( $current_site->domain, 0, 4 ) == 'www.' )
    135161            $current_site->cookie_domain = substr( $current_site->domain, 4 );
    136         wp_cache_set( "current_site", $current_site, "site-options" );
     162        wp_cache_set( 'current_site', $current_site, 'site-options' );
    137163        return $current_site;
    138164    }
     
    140166
    141167    if ( $domain == $cookie_domain )
    142         $current_site = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->site WHERE domain = %s AND path = %s", $domain, $path ) );
     168        $current_site = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->site WHERE domain = %s AND path = %s", $domain, $path ) );
    143169    else
    144         $current_site = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->site WHERE domain IN ( %s, %s ) AND path = %s ORDER BY CHAR_LENGTH( domain ) DESC LIMIT 1", $domain, $cookie_domain, $path ) );
    145     if ( $current_site == null ) {
     170        $current_site = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->site WHERE domain IN ( %s, %s ) AND path = %s ORDER BY CHAR_LENGTH( domain ) DESC LIMIT 1", $domain, $cookie_domain, $path ) );
     171
     172    if ( ! $current_site ) {
    146173        if ( $domain == $cookie_domain )
    147174            $current_site = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->site WHERE domain = %s AND path='/'", $domain ) );
     
    149176            $current_site = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->site WHERE domain IN ( %s, %s ) AND path = '/' ORDER BY CHAR_LENGTH( domain ) DESC LIMIT 1", $domain, $cookie_domain, $path ) );
    150177    }
    151     if ( $current_site != null ) {
     178
     179    if ( $current_site ) {
    152180        $path = $current_site->path;
    153181        $current_site->cookie_domain = $cookie_domain;
    154182        return $current_site;
    155     } elseif ( is_subdomain_install() ) {
     183    }
     184   
     185    if ( is_subdomain_install() ) {
    156186        $sitedomain = substr( $domain, 1 + strpos( $domain, '.' ) );
    157187        $current_site = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->site WHERE domain = %s AND path = %s", $sitedomain, $path) );
    158         if ( $current_site != null ) {
     188        if ( $current_site ) {
    159189            $current_site->cookie_domain = $current_site->domain;
    160190            return $current_site;
    161191        }
     192
    162193        $current_site = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->site WHERE domain = %s AND path='/'", $sitedomain) );
    163         if ( $current_site == null && defined( "WP_INSTALLING" ) == false ) {
    164             if ( count( $sites ) == 1 ) {
    165                 $current_site = $sites[0];
    166                 die( "That blog does not exist. Please try <a href='http://{$current_site->domain}{$current_site->path}'>http://{$current_site->domain}{$current_site->path}</a>" );
    167             } else {
    168                 die( "No WPMU site defined on this host. If you are the owner of this site, please check <a href='http://codex.wordpress.org/Debugging_WPMU'>Debugging WPMU</a> for further assistance." );
    169             }
    170         } else {
    171             $path = '/';
    172         }
    173     } elseif ( defined( "WP_INSTALLING" ) == false ) {
    174         if ( count( $sites ) == 1 ) {
    175             $current_site = $sites[0];
    176             die( "That blog does not exist. Please try <a href='http://{$current_site->domain}{$current_site->path}'>http://{$current_site->domain}{$current_site->path}</a>" );
    177         } else {
    178             die( "No WPMU site defined on this host. If you are the owner of this site, please check <a href='http://codex.wordpress.org/Debugging_WPMU'>Debugging WPMU</a> for further assistance." );
    179         }
    180     } else {
     194    }
     195
     196    if ( $current_site || defined( 'WP_INSTALLING' ) ) {
    181197        $path = '/';
    182     }
    183     return $current_site;
    184 }
    185 
     198        return $current_site;
     199    }
     200
     201    // Still no dice.
     202    // @todo Update or remove WPMU codex link.
     203    if ( 1 == count( $sites ) )
     204        wp_die( sprintf( __( 'That blog does not exist. Please try <a href="%s">%s</a>.' ), $sites[0]->domain . $sites[0]->path ) );
     205    else
     206        wp_die( __( 'No site defined on this host. If you are the owner of this site, please check <a href="http://codex.wordpress.org/Debugging_WPMU">Debugging WPMU</a> for further assistance.' ) );
     207}
     208
     209/**
     210 * Displays a failure message when blog does not exist.
     211 *
     212 * Checks for a missing $wpdb->site table as well.
     213 *
     214 * @todo Merge with is_blog_installed(), dead_db(), wp_not_installed(), etc.
     215 * @access private
     216 * @since 3.0.0
     217 */
    186218function is_installed() {
    187219    global $wpdb, $domain, $path;
    188220    $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         }
    214 
    215         die( "<h1>Fatal Error</h1> " . $msg );
    216     }
     221    if ( defined( 'WP_INSTALLING' ) )
     222        return;
     223
     224    $msg = '<h1>' . esc_html__( 'Fatal Error' ) . '</h1>';
     225    $msg  = '<p>' . __( 'If your blog does not display, please contact the owner of this site.' ) . '</p>';
     226    $msg .= '<p>' . __( 'If you are the owner of this site please check that MySQL is running properly and all tables are error free.' ) . '</p>';
     227    if ( ! $wpdb->get_var( "SHOW TABLES LIKE '$wpdb->site'" ) )
     228        $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>';
     229    else
     230        $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>';
     231    $msg .= '<h1>' . esc_html__( 'What do I do now?' ) . '</h1>';
     232    // @todo Update WPMU codex link.
     233    $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>';
     234    $msg .= '<p>' . __( "If you're still stuck with this message, then check that your database contains the following tables:" ) . '</p><ul>';
     235    foreach ( $wpdb->global_tables as $table ) {
     236        $msg .= '<li>' . $wpdb->prefix . $table . '</li>';
     237    }
     238    $msg .= '</ul>';
     239    // @todo Update WPMU codex link and support instructions.
     240    $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>';
     241
     242    // @todo This file no longer exists post-merge.
     243    if ( is_file( 'release-info.txt' ) ) {
     244        $msg .= '<p>' . __( 'Your bug report must include the following text:' ) . '</p>';
     245        $info = file( 'release-info.txt' );
     246        $msg .= $info[ 4 ] . '"';
     247    }
     248
     249    die( $msg );
    217250}
    218251
  • trunk/wp-includes/ms-settings.php

    r12901 r12921  
    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 ) {
     
    8282        $destination = 'http://' . $current_site->domain . $current_site->path . 'wp-signup.php?new=' . str_replace( '.' . $current_site->domain, '', $domain );
    8383    }
    84     wp_redirect( $destination );
     84    header( 'Location: ' . $destination );
    8585    die();
    8686}
     
    8989    if ( $current_site && ! $current_blog ) {
    9090        if ( $current_site->domain != $_SERVER[ 'HTTP_HOST' ] ) {
    91             wp_redirect( 'http://' . $current_site->domain . $current_site->path );
     91            header( 'Location: http://' . $current_site->domain . $current_site->path );
    9292            exit;
    9393        }
  • trunk/wp-settings.php

    r12885 r12921  
    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' );
    136 
    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' );
    143137
    144138// Load must-use plugins.
Note: See TracChangeset for help on using the changeset viewer.