WordPress.org

Make WordPress Core

Ticket #11881: 11881.8.diff

File 11881.8.diff, 41.0 KB (added by nacin, 8 years ago)

Inline docs + return includes to global scope + return MS includes to global scope (last part untested)

  • wp-includes/load.php

     
    1414 * @return null Will return null if register_globals PHP directive was disabled
    1515 */
    1616function wp_unregister_GLOBALS() {
    17         if ( !ini_get('register_globals') )
     17        if ( !ini_get( 'register_globals' ) )
    1818                return;
    1919
    20         if ( isset($_REQUEST['GLOBALS']) )
    21                 die('GLOBALS overwrite attempt detected');
     20        if ( isset( $_REQUEST['GLOBALS'] ) )
     21                die( 'GLOBALS overwrite attempt detected' );
    2222
    2323        // Variables that shouldn't be unset
    24         $noUnset = array('GLOBALS', '_GET', '_POST', '_COOKIE', '_REQUEST', '_SERVER', '_ENV', '_FILES', 'table_prefix');
     24        $noUnset = array( 'GLOBALS', '_GET', '_POST', '_COOKIE', '_REQUEST', '_SERVER', '_ENV', '_FILES', 'table_prefix' );
    2525
    26         $input = array_merge($_GET, $_POST, $_COOKIE, $_SERVER, $_ENV, $_FILES, isset($_SESSION) && is_array($_SESSION) ? $_SESSION : array());
     26        $input = array_merge( $_GET, $_POST, $_COOKIE, $_SERVER, $_ENV, $_FILES, isset( $_SESSION ) && is_array( $_SESSION ) ? $_SESSION : array() );
    2727        foreach ( $input as $k => $v )
    28                 if ( !in_array($k, $noUnset) && isset($GLOBALS[$k]) ) {
     28                if ( !in_array( $k, $noUnset ) && isset( $GLOBALS[$k] ) ) {
    2929                        $GLOBALS[$k] = NULL;
    30                         unset($GLOBALS[$k]);
     30                        unset( $GLOBALS[$k] );
    3131                }
    3232}
    3333
     34/**
     35 * Fix $_SERVER variables for various setups.
     36 *
     37 * @access private
     38 * @since 3.0.0
     39 */
    3440function wp_fix_server_vars() {
    3541        global $PHP_SELF;
    3642        // Fix for IIS when running with PHP ISAPI
    3743        if ( empty( $_SERVER['REQUEST_URI'] ) || ( php_sapi_name() != 'cgi-fcgi' && preg_match( '/^Microsoft-IIS\//', $_SERVER['SERVER_SOFTWARE'] ) ) ) {
    3844
    3945                // IIS Mod-Rewrite
    40                 if (isset($_SERVER['HTTP_X_ORIGINAL_URL'])) {
     46                if ( isset( $_SERVER['HTTP_X_ORIGINAL_URL'] ) ) {
    4147                        $_SERVER['REQUEST_URI'] = $_SERVER['HTTP_X_ORIGINAL_URL'];
    4248                }
    4349                // IIS Isapi_Rewrite
    44                 else if (isset($_SERVER['HTTP_X_REWRITE_URL'])) {
     50                else if ( isset( $_SERVER['HTTP_X_REWRITE_URL'] ) ) {
    4551                        $_SERVER['REQUEST_URI'] = $_SERVER['HTTP_X_REWRITE_URL'];
    4652                }
    4753                else
    4854                {
    4955                        // Use ORIG_PATH_INFO if there is no PATH_INFO
    50                         if ( !isset($_SERVER['PATH_INFO']) && isset($_SERVER['ORIG_PATH_INFO']) )
     56                        if ( !isset( $_SERVER['PATH_INFO'] ) && isset( $_SERVER['ORIG_PATH_INFO'] ) )
    5157                                $_SERVER['PATH_INFO'] = $_SERVER['ORIG_PATH_INFO'];
    5258
    5359                        // Some IIS + PHP configurations puts the script-name in the path-info (No need to append it twice)
    54                         if ( isset($_SERVER['PATH_INFO']) ) {
     60                        if ( isset( $_SERVER['PATH_INFO'] ) ) {
    5561                                if ( $_SERVER['PATH_INFO'] == $_SERVER['SCRIPT_NAME'] )
    5662                                        $_SERVER['REQUEST_URI'] = $_SERVER['PATH_INFO'];
    5763                                else
     
    5965                        }
    6066
    6167                        // Append the query string if it exists and isn't null
    62                         if (isset($_SERVER['QUERY_STRING']) && !empty($_SERVER['QUERY_STRING'])) {
     68                        if ( isset( $_SERVER['QUERY_STRING'] ) && !empty( $_SERVER['QUERY_STRING'] ) ) {
    6369                                $_SERVER['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING'];
    6470                        }
    6571                }
    6672        }
    6773
    6874        // Fix for PHP as CGI hosts that set SCRIPT_FILENAME to something ending in php.cgi for all requests
    69         if ( isset($_SERVER['SCRIPT_FILENAME']) && ( strpos($_SERVER['SCRIPT_FILENAME'], 'php.cgi') == strlen($_SERVER['SCRIPT_FILENAME']) - 7 ) )
     75        if ( isset( $_SERVER['SCRIPT_FILENAME'] ) && ( strpos( $_SERVER['SCRIPT_FILENAME'], 'php.cgi' ) == strlen( $_SERVER['SCRIPT_FILENAME'] ) - 7 ) )
    7076                $_SERVER['SCRIPT_FILENAME'] = $_SERVER['PATH_TRANSLATED'];
    7177
    7278        // Fix for Dreamhost and other PHP as CGI hosts
    73         if (strpos($_SERVER['SCRIPT_NAME'], 'php.cgi') !== false)
    74                 unset($_SERVER['PATH_INFO']);
     79        if ( strpos( $_SERVER['SCRIPT_NAME'], 'php.cgi' ) !== false )
     80                unset( $_SERVER['PATH_INFO'] );
    7581
    7682        // Fix empty PHP_SELF
    7783        $PHP_SELF = $_SERVER['PHP_SELF'];
    78         if ( empty($PHP_SELF) )
    79                 $_SERVER['PHP_SELF'] = $PHP_SELF = preg_replace("/(\?.*)?$/",'',$_SERVER["REQUEST_URI"]);
     84        if ( empty( $PHP_SELF ) )
     85                $_SERVER['PHP_SELF'] = $PHP_SELF = preg_replace( "/(\?.*)?$/",'',$_SERVER["REQUEST_URI"] );
    8086}
    8187
     88/**
     89 * Check for the required PHP version, and the MySQL extension or a database drop-in.
     90 *
     91 * Dies if requirements are not met.
     92 *
     93 * @access private
     94 * @since 3.0.0
     95 */
    8296function wp_check_php_mysql_versions() {
    8397        // we can probably extend this function to check if wp_die() exists then use translated strings, and then use it in install.php etc.
    8498
     
    87101        if ( version_compare( $required_php_version, $php_version, '>' ) )
    88102                die( sprintf( /*WP_I18N_OLD_PHP*/'Your server is running PHP version %1$s but WordPress %2%s requires at least %2%s.'/*/WP_I18N_OLD_PHP*/, $php_version, $wp_version, $required_php_version ) );
    89103
    90         if ( !extension_loaded('mysql') && !file_exists(WP_CONTENT_DIR . '/db.php') )
     104        if ( !extension_loaded( 'mysql' ) && !file_exists( WP_CONTENT_DIR . '/db.php' ) )
    91105                die( /*WP_I18N_OLD_MYSQL*/'Your PHP installation appears to be missing the MySQL extension which is required by WordPress.'/*/WP_I18N_OLD_MYSQL*/ );
    92106}
    93107
     108/**
     109 * Dies with a maintenance message when conditions are met.
     110 *
     111 * Checks for a file in the WordPress root directory named ".maintenance".
     112 * This file will contain the variable $upgrading, set to the time the file
     113 * was created. If the file was created less than 10 minutes ago, WordPress
     114 * enters maintenance mode and displays a message.
     115 *
     116 * The default message can be replaced by using a drop-in (maintenance.php in
     117 * the wp-content directory).
     118 *
     119 * @access private
     120 * @since 3.0.0
     121 */
    94122function wp_maintenance() {
    95         if ( file_exists(ABSPATH . '.maintenance') && !defined('WP_INSTALLING') ) {
    96                 include(ABSPATH . '.maintenance');
    97                 // If the $upgrading timestamp is older than 10 minutes, don't die.
    98                 if ( ( time() - $upgrading ) < 600 ) {
    99                         if ( file_exists( WP_CONTENT_DIR . '/maintenance.php' ) ) {
    100                                 require_once( WP_CONTENT_DIR . '/maintenance.php' );
    101                                 die();
    102                         }
     123        if ( !file_exists( ABSPATH . '.maintenance' ) || defined( 'WP_INSTALLING' ) )
     124                return;
    103125
    104                         $protocol = $_SERVER["SERVER_PROTOCOL"];
    105                         if ( 'HTTP/1.1' != $protocol && 'HTTP/1.0' != $protocol )
    106                                 $protocol = 'HTTP/1.0';
    107                         header( "$protocol 503 Service Unavailable", true, 503 );
    108                         header( 'Content-Type: text/html; charset=utf-8' );
    109                         header( 'Retry-After: 600' );
    110         ?>
     126        include( ABSPATH . '.maintenance' );
     127        // If the $upgrading timestamp is older than 10 minutes, don't die.
     128        if ( ( time() - $upgrading ) >= 600 )
     129                return;
     130
     131        if ( file_exists( WP_CONTENT_DIR . '/maintenance.php' ) ) {
     132                require_once( WP_CONTENT_DIR . '/maintenance.php' );
     133                die();
     134        }
     135
     136        $protocol = $_SERVER["SERVER_PROTOCOL"];
     137        if ( 'HTTP/1.1' != $protocol && 'HTTP/1.0' != $protocol )
     138                $protocol = 'HTTP/1.0';
     139        header( "$protocol 503 Service Unavailable", true, 503 );
     140        header( 'Content-Type: text/html; charset=utf-8' );
     141        header( 'Retry-After: 600' );
     142?>
    111143        <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    112144        <html xmlns="http://www.w3.org/1999/xhtml">
    113145        <head>
     
    119151                <h1>Briefly unavailable for scheduled maintenance. Check back in a minute.</h1>
    120152        </body>
    121153        </html>
    122         <?php
    123                         die();
    124                 }
    125         }
     154<?php
     155        die();
    126156}
    127157
    128158/**
     
    135165 */
    136166function timer_start() {
    137167        global $timestart;
    138         $mtime = explode(' ', microtime() );
     168        $mtime = explode( ' ', microtime() );
    139169        $mtime = $mtime[1] + $mtime[0];
    140170        $timestart = $mtime;
    141171        return true;
     
    165195 * @param int $precision The amount of digits from the right of the decimal to display. Default is 3.
    166196 * @return float The "second.microsecond" finished time calculation
    167197 */
    168 function timer_stop($display = 0, $precision = 3) { //if called like timer_stop(1), will echo $timetotal
     198function timer_stop( $display = 0, $precision = 3 ) { // if called like timer_stop(1), will echo $timetotal
    169199        global $timestart, $timeend;
    170200        $mtime = microtime();
    171         $mtime = explode(' ',$mtime);
     201        $mtime = explode( ' ',$mtime );
    172202        $mtime = $mtime[1] + $mtime[0];
    173203        $timeend = $mtime;
    174204        $timetotal = $timeend-$timestart;
    175         $r = ( function_exists('number_format_i18n') ) ? number_format_i18n($timetotal, $precision) : number_format($timetotal, $precision);
     205        $r = ( function_exists( 'number_format_i18n' ) ) ? number_format_i18n( $timetotal, $precision ) : number_format( $timetotal, $precision );
    176206        if ( $display )
    177207                echo $r;
    178208        return $r;
    179209}
    180210
     211/**
     212 * Sets PHP error handling.
     213 *
     214 * Add <code>define('WP_DEBUG', true);</code> to wp-config.php to enable
     215 * the reporting of notices during development.
     216 *
     217 * Add <code>define('WP_DEBUG_DISPLAY', false);</code> to wp-config.php to
     218 * disable the display of errors.
     219 *
     220 * Add <code>define('WP_DEBUG_LOG', true);</code> to wp-config.php to log
     221 * eerrors to debug.log in the wp-content directory.
     222 *
     223 * @access private
     224 * @since 3.0.0
     225 */
    181226function wp_debug_mode() {
    182227        if ( WP_DEBUG ) {
    183                 if ( defined('E_DEPRECATED') )
    184                         error_reporting(E_ALL & ~E_DEPRECATED & ~E_STRICT);
     228                if ( defined( 'E_DEPRECATED' ) )
     229                        error_reporting( E_ALL & ~E_DEPRECATED & ~E_STRICT );
    185230                else
    186                         error_reporting(E_ALL);
     231                        error_reporting( E_ALL );
    187232
    188233                if ( WP_DEBUG_DISPLAY )
    189                         ini_set('display_errors', 1);
     234                        ini_set( 'display_errors', 1 );
    190235
    191236                if ( WP_DEBUG_LOG ) {
    192                         ini_set('log_errors', 1);
    193                         ini_set('error_log', WP_CONTENT_DIR . '/debug.log');
     237                        ini_set( 'log_errors', 1 );
     238                        ini_set( 'error_log', WP_CONTENT_DIR . '/debug.log' );
    194239                }
    195240        } else {
    196                 if ( defined('E_RECOVERABLE_ERROR') )
    197                         error_reporting(E_ERROR | E_WARNING | E_PARSE | E_USER_ERROR | E_USER_WARNING | E_RECOVERABLE_ERROR);
     241                if ( defined( 'E_RECOVERABLE_ERROR' ) )
     242                        error_reporting( E_ERROR | E_WARNING | E_PARSE | E_USER_ERROR | E_USER_WARNING | E_RECOVERABLE_ERROR );
    198243                else
    199                         error_reporting(E_ERROR | E_WARNING | E_PARSE | E_USER_ERROR | E_USER_WARNING);
     244                        error_reporting( E_ERROR | E_WARNING | E_PARSE | E_USER_ERROR | E_USER_WARNING );
    200245        }
    201246}
    202247
     248/**
     249 * Sets the location of the language directory.
     250 *
     251 * To set directory manually, define <code>WP_LANG_DIR</code> in wp-config.php.
     252 *
     253 * First looks for language folder in WP_CONTENT_DIR and uses that folder if it
     254 * exists. Or it uses the "languages" folder in WPINC.
     255 *
     256 * The WP_LANG_DIR constant was introduced in 2.1.0.
     257 *
     258 * @access private
     259 * @since 3.0.0
     260 */
    203261function wp_set_lang_dir() {
    204         if ( !defined('WP_LANG_DIR') ) {
    205                 /**
    206                  * Stores the location of the language directory. First looks for language folder in WP_CONTENT_DIR
    207                  * and uses that folder if it exists. Or it uses the "languages" folder in WPINC.
    208                  *
    209                  * @since 2.1.0
    210                  */
    211                 if ( file_exists(WP_CONTENT_DIR . '/languages') && @is_dir(WP_CONTENT_DIR . '/languages') ) {
    212                         define('WP_LANG_DIR', WP_CONTENT_DIR . '/languages'); // no leading slash, no trailing slash, full path, not relative to ABSPATH
    213                         if (!defined('LANGDIR')) {
     262        if ( !defined( 'WP_LANG_DIR' ) ) {
     263                if ( file_exists( WP_CONTENT_DIR . '/languages' ) && @is_dir( WP_CONTENT_DIR . '/languages' ) ) {
     264                        define( 'WP_LANG_DIR', WP_CONTENT_DIR . '/languages' ); // no leading slash, no trailing slash, full path, not relative to ABSPATH
     265                        if ( !defined( 'LANGDIR' ) ) {
    214266                                // Old static relative path maintained for limited backwards compatibility - won't work in some cases
    215                                 define('LANGDIR', 'wp-content/languages');
     267                                define( 'LANGDIR', 'wp-content/languages' );
    216268                        }
    217269                } else {
    218                         define('WP_LANG_DIR', ABSPATH . WPINC . '/languages'); // no leading slash, no trailing slash, full path, not relative to ABSPATH
    219                         if (!defined('LANGDIR')) {
     270                        define( 'WP_LANG_DIR', ABSPATH . WPINC . '/languages' ); // no leading slash, no trailing slash, full path, not relative to ABSPATH
     271                        if ( !defined( 'LANGDIR' ) ) {
    220272                                // Old relative path maintained for backwards compatibility
    221                                 define('LANGDIR', WPINC . '/languages');
     273                                define( 'LANGDIR', WPINC . '/languages' );
    222274                        }
    223275                }
    224276        }
    225277}
    226278
     279/**
     280 * Sets the database table prefix and the format specifiers for database table columns.
     281 *
     282 * Columns not listed here default to %s.
     283 *
     284 * @see wpdb::$field_types Since 2.8.0
     285 * @see wpdb::prepare()
     286 * @see wpdb::insert()
     287 * @see wpdb::update()
     288 * @see wpdb::set_prefix()
     289 *
     290 * @access private
     291 * @since 3.0.0
     292 */
    227293function wp_set_wpdb_vars() {
    228294        global $wpdb, $table_prefix;
    229         if ( !empty($wpdb->error) )
     295        if ( !empty( $wpdb->error ) )
    230296                dead_db();
    231297
    232         /**
    233          * Format specifiers for DB columns. Columns not listed here default to %s.
    234          * @since 2.8.0
    235          * @see wpdb:$field_types
    236          * @see wpdb:prepare()
    237          * @see wpdb:insert()
    238          * @see wpdb:update()
    239          */
    240298        $wpdb->field_types = array( 'post_author' => '%d', 'post_parent' => '%d', 'menu_order' => '%d', 'term_id' => '%d', 'term_group' => '%d', 'term_taxonomy_id' => '%d',
    241299                'parent' => '%d', 'count' => '%d','object_id' => '%d', 'term_order' => '%d', 'ID' => '%d', 'commment_ID' => '%d', 'comment_post_ID' => '%d', 'comment_parent' => '%d',
    242300                'user_id' => '%d', 'link_id' => '%d', 'link_owner' => '%d', 'link_rating' => '%d', 'option_id' => '%d', 'blog_id' => '%d', 'meta_id' => '%d', 'post_id' => '%d',
    243                 'user_status' => '%d', 'umeta_id' => '%d', 'comment_karma' => '%d', 'comment_count' => '%d');
     301                'user_status' => '%d', 'umeta_id' => '%d', 'comment_karma' => '%d', 'comment_count' => '%d' );
    244302
    245         $prefix = $wpdb->set_prefix($table_prefix);
     303        $prefix = $wpdb->set_prefix( $table_prefix );
    246304
    247         if ( is_wp_error($prefix) )
    248                 wp_die(/*WP_I18N_BAD_PREFIX*/'<strong>ERROR</strong>: <code>$table_prefix</code> in <code>wp-config.php</code> can only contain numbers, letters, and underscores.'/*/WP_I18N_BAD_PREFIX*/);
    249 
     305        if ( is_wp_error( $prefix ) )
     306                wp_die( /*WP_I18N_BAD_PREFIX*/'<strong>ERROR</strong>: <code>$table_prefix</code> in <code>wp-config.php</code> can only contain numbers, letters, and underscores.'/*/WP_I18N_BAD_PREFIX*/ );
    250307}
    251308
     309/**
     310 * Starts the WordPress object cache.
     311 *
     312 * If an object-cache.php file exists in the wp-content directory,
     313 * it uses that drop-in as an external object cache.
     314 *
     315 * @access private
     316 * @since 3.0.0
     317 */
    252318function wp_start_object_cache() {
    253319        global $_wp_using_ext_object_cache;
    254         if ( file_exists(WP_CONTENT_DIR . '/object-cache.php') ) {
    255                 require_once (WP_CONTENT_DIR . '/object-cache.php');
     320        if ( file_exists( WP_CONTENT_DIR . '/object-cache.php' ) ) {
     321                require_once ( WP_CONTENT_DIR . '/object-cache.php' );
    256322                $_wp_using_ext_object_cache = true;
    257323        } else {
    258                 require_once (ABSPATH . WPINC . '/cache.php');
     324                require_once ( ABSPATH . WPINC . '/cache.php' );
    259325                $_wp_using_ext_object_cache = false;
    260326        }
    261327
    262328        wp_cache_init();
    263         if ( function_exists('wp_cache_add_global_groups') ) {
     329        if ( function_exists( 'wp_cache_add_global_groups' ) ) {
    264330                        if( is_multisite() ) {
    265                                         wp_cache_add_global_groups(array ('users', 'userlogins', 'usermeta', 'site-transient', 'site-options', 'site-lookup', 'blog-lookup', 'blog-details', 'rss'));
     331                                        wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'site-transient', 'site-options', 'site-lookup', 'blog-lookup', 'blog-details', 'rss' ) );
    266332                        } else {
    267                                 wp_cache_add_global_groups(array ('users', 'userlogins', 'usermeta', 'site-transient'));
     333                                wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'site-transient' ) );
    268334                        }
    269                 wp_cache_add_non_persistent_groups(array( 'comment', 'counts', 'plugins' ));
     335                wp_cache_add_non_persistent_groups( array( 'comment', 'counts', 'plugins' ) );
    270336        }
    271337}
    272338
     339/**
     340 * Redirects to the installer if WordPress is not installed.
     341 *
     342 * Dies with an error message when multisite is enabled.
     343 *
     344 * @access private
     345 * @since 3.0.0
     346 */
    273347function wp_not_installed() {
    274348        if ( is_multisite() ) {
    275                         if ( !is_blog_installed() && !defined('WP_INSTALLING') )
    276                                         die( __( 'The blog you have requested is not installed properly. Please contact the system administrator.' ) ); // have to die here ~ Mark
    277         } elseif ( !is_blog_installed() && (strpos($_SERVER['PHP_SELF'], 'install.php') === false && !defined('WP_INSTALLING')) ) {
    278                 if ( defined('WP_SITEURL') )
     349                        if ( !is_blog_installed() && !defined( 'WP_INSTALLING' ) )
     350                                        wp_die( __( 'The blog you have requested is not installed properly. Please contact the system administrator.' ) );
     351        } elseif ( !is_blog_installed() && ( strpos( $_SERVER['PHP_SELF'], 'install.php' ) === false && !defined( 'WP_INSTALLING' ) ) ) {
     352                if ( defined( 'WP_SITEURL' ) )
    279353                        $link = WP_SITEURL . '/wp-admin/install.php';
    280                 elseif (strpos($_SERVER['PHP_SELF'], 'wp-admin') !== false)
    281                         $link = preg_replace('|/wp-admin/?.*?$|', '/', $_SERVER['PHP_SELF']) . 'wp-admin/install.php';
     354                elseif ( strpos( $_SERVER['PHP_SELF'], 'wp-admin' ) !== false )
     355                        $link = preg_replace( '|/wp-admin/?.*?$|', '/', $_SERVER['PHP_SELF'] ) . 'wp-admin/install.php';
    282356                else
    283                         $link = preg_replace('|/[^/]+?$|', '/', $_SERVER['PHP_SELF']) . 'wp-admin/install.php';
    284                 require_once(ABSPATH . WPINC . '/kses.php');
    285                 require_once(ABSPATH . WPINC . '/pluggable.php');
    286                 require_once(ABSPATH . WPINC . '/formatting.php');
    287                 wp_redirect($link);
     357                        $link = preg_replace( '|/[^/]+?$|', '/', $_SERVER['PHP_SELF'] ) . 'wp-admin/install.php';
     358                require_once( ABSPATH . WPINC . '/kses.php' );
     359                require_once( ABSPATH . WPINC . '/pluggable.php' );
     360                require_once( ABSPATH . WPINC . '/formatting.php' );
     361                wp_redirect( $link );
    288362                die();
    289363        }
    290364}
    291365
    292 function wp_load_mu_plugins() {
    293         if ( is_dir( WPMU_PLUGIN_DIR ) ) {
    294                 if ( $dh = opendir( WPMU_PLUGIN_DIR ) ) {
    295                         $mu_plugins = array ();
    296                         while ( ( $plugin = readdir( $dh ) ) !== false )
    297                                 if ( substr( $plugin, -4 ) == '.php' )
    298                                         $mu_plugins[] = $plugin;
    299                         closedir( $dh );
    300                                         if( is_multisite() )
    301                                         sort( $mu_plugins );
    302                         foreach( $mu_plugins as $mu_plugin )
    303                                 include_once( WPMU_PLUGIN_DIR . '/' . $mu_plugin );
    304                 }
    305         }
     366/**
     367 * Returns array of must-use plugin files to be included in global scope.
     368 *
     369 * The default directory is wp-content/mu-plugins. To change the default directory
     370 * manually, define <code>WPMU_PLUGIN_DIR</code> and <code>WPMU_PLUGIN_URL</code>
     371 * in wp-config.php.
     372 *
     373 * @access private
     374 * @since 3.0.0
     375 * @return array Files to include
     376 */
     377function wp_muplugins_to_load() {
     378        $mu_plugins = array();
     379        if ( !is_dir( WPMU_PLUGIN_DIR ) )
     380                return $mu_plugins;
     381        if ( ! $dh = opendir( WPMU_PLUGIN_DIR ) )
     382                return $mu_plugins;
     383        while ( ( $plugin = readdir( $dh ) ) !== false )
     384                if ( substr( $plugin, -4 ) == '.php' )
     385                        $mu_plugins[] = WPMU_PLUGIN_DIR . '/' . $plugin;
     386        closedir( $dh );
     387        if( is_multisite() )
     388                sort( $mu_plugins );
     389        return $mu_plugins;
    306390}
    307391
    308 function wp_load_plugins() {
     392/**
     393 * Returns array of plugin files to be included in global scope.
     394 *
     395 * The default directory is wp-content/plugins. To change the default directory
     396 * manually, define <code>WP_PLUGIN_DIR</code> and <code>WP_PLUGIN_URL</code>
     397 * in wp-config.php.
     398 *
     399 * @access private
     400 * @since 3.0.0
     401 * @return array Files to include
     402 */
     403function wp_plugins_to_load() {
     404        $plugins = array();
     405
    309406        // Check for hacks file if the option is enabled
    310         if ( get_option('hack_file') ) {
    311                 if ( file_exists(ABSPATH . 'my-hacks.php') )
    312                         require(ABSPATH . 'my-hacks.php');
    313         }
     407        if ( get_option( 'hack_file' ) && file_exists( ABSPATH . 'my-hacks.php' ) )
     408                        $plugins[] = ABSPATH . 'my-hacks.php';
    314409
    315         $current_plugins = apply_filters( 'active_plugins', get_option( 'active_plugins' ) );
    316         if ( is_array($current_plugins) && !defined('WP_INSTALLING') ) {
    317                 foreach ( $current_plugins as $plugin ) {
    318                         // check the $plugin filename
    319                         // Validate plugin filename
    320                         if ( validate_file($plugin) // $plugin must validate as file
    321                                 || '.php' != substr($plugin, -4) // $plugin must end with '.php'
    322                                 || !file_exists(WP_PLUGIN_DIR . '/' . $plugin)  // $plugin must exist
    323                                 )
    324                                 continue;
    325 
    326                         include_once(WP_PLUGIN_DIR . '/' . $plugin);
    327                 }
    328                 unset($plugin);
     410        $active_plugins = apply_filters( 'active_plugins', get_option( 'active_plugins' ) );
     411        if ( !is_array( $active_plugins ) || defined( 'WP_INSTALLING' ) )
     412                return $plugins;
     413        foreach ( $active_plugins as $plugin ) {
     414                if ( validate_file( $plugin ) // $plugin must validate as file
     415                        || '.php' != substr( $plugin, -4 ) // $plugin must end with '.php'
     416                        || !file_exists( WP_PLUGIN_DIR . '/' . $plugin ) // $plugin must exist
     417                        )
     418                        continue;
     419                $plugins[] = WP_PLUGIN_DIR . '/' . $plugin;
    329420        }
    330         unset($current_plugins);
     421        return $plugins;
    331422}
    332423
     424/**
     425 * Sets internal encoding using mb_internal_encoding().
     426 *
     427 * In most cases the default internal encoding is latin1, which is of no use,
     428 * since we want to use the mb_ functions for utf-8 strings.
     429 *
     430 * @access private
     431 * @since 3.0.0
     432 */
    333433function wp_set_internal_encoding() {
    334         /*
    335          * In most cases the default internal encoding is latin1, which is of no use,
    336          * since we want to use the mb_ functions for utf-8 strings
    337          */
    338         if (function_exists('mb_internal_encoding')) {
    339                 if (!@mb_internal_encoding(get_option('blog_charset')))
    340                         mb_internal_encoding('UTF-8');
     434        if ( function_exists( 'mb_internal_encoding' ) ) {
     435                if ( !@mb_internal_encoding( get_option( 'blog_charset' ) ) )
     436                        mb_internal_encoding( 'UTF-8' );
    341437        }
    342438}
    343439
     440/**
     441 * Add magic quotes to $_GET, $_POST, $_COOKIE, and $_SERVER.
     442 *
     443 * Also forces $_REQUEST to be $_GET + $_POST. If $_SERVER, $_COOKIE,
     444 * or $_ENV are needed, use those superglobals directly.
     445 *
     446 * @access private
     447 * @since 3.0.0
     448 */
    344449function wp_magic_quotes() {
    345450        // If already slashed, strip.
    346451        if ( get_magic_quotes_gpc() ) {
    347                 $_GET    = stripslashes_deep($_GET   );
    348                 $_POST   = stripslashes_deep($_POST  );
    349                 $_COOKIE = stripslashes_deep($_COOKIE);
     452                $_GET    = stripslashes_deep( $_GET    );
     453                $_POST   = stripslashes_deep( $_POST   );
     454                $_COOKIE = stripslashes_deep( $_COOKIE );
    350455        }
    351456
    352457        // Escape with wpdb.
    353         $_GET    = add_magic_quotes($_GET   );
    354         $_POST   = add_magic_quotes($_POST  );
    355         $_COOKIE = add_magic_quotes($_COOKIE);
    356         $_SERVER = add_magic_quotes($_SERVER);
     458        $_GET    = add_magic_quotes( $_GET    );
     459        $_POST   = add_magic_quotes( $_POST   );
     460        $_COOKIE = add_magic_quotes( $_COOKIE );
     461        $_SERVER = add_magic_quotes( $_SERVER );
    357462
    358         // Force REQUEST to be GET + POST.  If SERVER, COOKIE, or ENV are needed, use those superglobals directly.
    359         $_REQUEST = array_merge($_GET, $_POST);
     463        // Force REQUEST to be GET + POST.
     464        $_REQUEST = array_merge( $_GET, $_POST );
    360465}
    361466
    362 function wp_find_locale() {
    363         global $locale, $locale_file;
    364         /**
    365          * The locale of the blog
    366          * @since 1.5.0
    367          */
    368         $locale = get_locale();
    369         $locale_file = WP_LANG_DIR . "/$locale.php";
    370         if ( is_readable($locale_file) )
    371                 require_once($locale_file);
    372 
    373         // Pull in locale data after loading text domain.
    374         require_once(ABSPATH . WPINC . '/locale.php');
    375 }
    376 
    377 function wp_load_theme_functions() {
    378         // Load functions for active theme.
    379         if ( TEMPLATEPATH !== STYLESHEETPATH && file_exists(STYLESHEETPATH . '/functions.php') )
    380                 include(STYLESHEETPATH . '/functions.php');
    381         if ( file_exists(TEMPLATEPATH . '/functions.php') )
    382                 include(TEMPLATEPATH . '/functions.php');
    383 
    384         // Load in support for template functions which the theme supports
    385         require_if_theme_supports( 'post-thumbnails', ABSPATH . WPINC . '/post-thumbnail-template.php' );
    386 }
    387 
    388467/**
    389468 * Runs just before PHP shuts down execution.
    390469 *
     
    392471 * @since 1.2.0
    393472 */
    394473function shutdown_action_hook() {
    395         do_action('shutdown');
     474        do_action( 'shutdown' );
    396475        wp_cache_close();
    397476}
    398477
     
    425504 * @return bool True if inside WordPress administration pages.
    426505 */
    427506function is_admin() {
    428         if ( defined('WP_ADMIN') )
     507        if ( defined( 'WP_ADMIN' ) )
    429508                return WP_ADMIN;
    430509        return false;
    431510}
     
    438517 * @return bool True if multisite is enabled, false otherwise.
    439518 */
    440519function is_multisite() {
    441         if ( ( defined('MULTISITE') && MULTISITE ) || defined('VHOST') || defined('SUNRISE') )
     520        if ( ( defined( 'MULTISITE' ) && MULTISITE ) || defined( 'VHOST' ) || defined( 'SUNRISE' ) )
    442521                return true;
    443522
    444523        return false;
  • wp-includes/ms-load.php

     
    1313if( defined( 'SUNRISE' ) )
    1414        include_once( WP_CONTENT_DIR . '/sunrise.php' );
    1515
    16     require (ABSPATH . WPINC . '/ms-settings.php');
    17 $wpdb->blogid           = $current_blog->blog_id;
    18 $wpdb->siteid           = $current_blog->site_id;
     16    require( ABSPATH . WPINC . '/ms-settings.php' );
     17$wpdb->blogid = $current_blog->blog_id;
     18$wpdb->siteid = $current_blog->site_id;
    1919$wpdb->set_prefix($table_prefix); // set up blog tables
    2020$table_prefix = $wpdb->get_blog_prefix();
    2121
     
    4040        define( "BLOGUPLOADDIR", WP_CONTENT_DIR . "/blogs.dir/{$wpdb->blogid}/files/" );
    4141
    4242function ms_network_settings() {
    43         global $wpdb, $current_site, $cookiehash;
     43        global $wpdb, $current_site, $cookiehash;
    4444
    45         if( !isset($current_site->site_name) )
    46                 $current_site->site_name = get_site_option('site_name');
     45        if( !isset($current_site->site_name) )
     46                $current_site->site_name = get_site_option('site_name');
    4747
    48         if( $current_site->site_name == false )
    49                 $current_site->site_name = ucfirst( $current_site->domain );
     48        if( $current_site->site_name == false )
     49                $current_site->site_name = ucfirst( $current_site->domain );
    5050
    51         if ( ! defined('WP_INSTALLING') ) {
    52                 // Used to guarantee unique hash cookies
    53                 if ( !isset($cookiehash) )
    54                         $cookiehash = '';
     51        if ( ! defined('WP_INSTALLING') ) {
     52                if ( !isset($cookiehash) )
     53                        $cookiehash = '';
    5554
    56                 /**
    57                 * Used to guarantee unique hash cookies
    58                 * @since 1.5
    59                 */
    60                 if ( !defined('COOKIEHASH') )
    61                         define( 'COOKIEHASH', $cookiehash );
    62         }
     55                /**
     56                * Used to guarantee unique hash cookies
     57                * @since 1.5
     58                */
     59                if ( !defined('COOKIEHASH') )
     60                                define( 'COOKIEHASH', $cookiehash );
     61        }
    6362
    64         $wpdb->hide_errors();
     63        $wpdb->hide_errors();
    6564}
    6665
    6766function ms_network_plugins() {
    68         $wpmu_sitewide_plugins = (array) maybe_unserialize( get_site_option( 'wpmu_sitewide_plugins' ) );
    69         foreach( $wpmu_sitewide_plugins as $plugin_file => $activation_time ) {
    70                 if ( !$plugin_file )
    71                         continue;
     67        $network_plugins = array();
     68        $wpmu_sitewide_plugins = (array) maybe_unserialize( get_site_option( 'wpmu_sitewide_plugins' ) );
     69        foreach( $wpmu_sitewide_plugins as $plugin_file => $activation_time ) {
     70                if ( !$plugin_file )
     71                        continue;
    7272
    73                 if ( !file_exists( WP_PLUGIN_DIR . '/' . $plugin_file ) ) {
    74                         $deleted_sitewide_plugins[] = $plugin_file;
    75                 } else {
    76                         include_once( WP_PLUGIN_DIR . '/' . $plugin_file );
    77                 }
    78         }
     73                if ( !file_exists( WP_PLUGIN_DIR . '/' . $plugin_file ) ) {
     74                        $deleted_sitewide_plugins[] = $plugin_file;
     75                } else {
     76                        $network_plugins = WP_PLUGIN_DIR . '/' . $plugin_file;
     77                }
     78        }
    7979
    80         if ( isset( $deleted_sitewide_plugins ) ) {
    81                 $active_sitewide_plugins = maybe_unserialize( get_site_option( 'active_sitewide_plugins' ) );
     80        if ( isset( $deleted_sitewide_plugins ) ) {
     81                $active_sitewide_plugins = maybe_unserialize( get_site_option( 'active_sitewide_plugins' ) );
    8282
    83                 /* Remove any deleted plugins from the wpmu_sitewide_plugins array */
    84                 foreach( $deleted_sitewide_plugins as $plugin_file ) {
    85                         unset( $wpmu_sitewide_plugins[$plugin_file] );
    86                         unset( $active_sitewide_plugins[$plugin_file] );
    87                 }
     83                /* Remove any deleted plugins from the wpmu_sitewide_plugins array */
     84                foreach( $deleted_sitewide_plugins as $plugin_file ) {
     85                        unset( $wpmu_sitewide_plugins[$plugin_file] );
     86                        unset( $active_sitewide_plugins[$plugin_file] );
     87                }
    8888
    89                 update_site_option( 'wpmu_sitewide_plugins', $wpmu_sitewide_plugins );
    90                 update_site_option( 'active_sitewide_plugins', $wpmu_sitewide_plugins );
    91         }
     89                update_site_option( 'wpmu_sitewide_plugins', $wpmu_sitewide_plugins );
     90                update_site_option( 'active_sitewide_plugins', $wpmu_sitewide_plugins );
     91        }
    9292
     93        return $network_plugins;
    9394}
    9495
    9596function ms_site_check() {
     
    99100
    100101        if ( '1' == $current_blog->deleted ) {
    101102                if ( file_exists( WP_CONTENT_DIR . '/blog-deleted.php' ) ) {
    102                         require_once( WP_CONTENT_DIR . '/blog-deleted.php' );
    103                         die();
     103                        return WP_CONTENT_DIR . '/blog-deleted.php';
    104104                } else {
    105105                        header('HTTP/1.1 410 Gone');
    106106                        graceful_fail(__('This user has elected to delete their account and the content is no longer available.'));
     
    109109
    110110        if ( '2' == $current_blog->deleted ) {
    111111                if ( file_exists( WP_CONTENT_DIR . '/blog-inactive.php' ) ) {
    112                         require_once( WP_CONTENT_DIR . '/blog-inactive.php' );
    113                         die();
     112                        return WP_CONTENT_DIR . '/blog-inactive.php';
    114113                } else {
    115114                        graceful_fail( 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}" ) ) ) );
    116115                }
     
    118117
    119118        if( $current_blog->archived == '1' || $current_blog->spam == '1' ) {
    120119                if ( file_exists( WP_CONTENT_DIR . '/blog-suspended.php' ) ) {
    121                         require_once( WP_CONTENT_DIR . '/blog-suspended.php' );
    122                         die();
     120                        return WP_CONTENT_DIR . '/blog-suspended.php';
    123121                } else {
    124122                        header('HTTP/1.1 410 Gone');
    125123                        graceful_fail(__('This blog has been archived or suspended.'));
    126124                }
    127125        }
     126                return true;
    128127}
    129128
    130129function ms_network_cookies() {
  • wp-settings.php

     
    1313 *
    1414 * @since 1.0.0
    1515 */
    16 define('WPINC', 'wp-includes');
     16define( 'WPINC', 'wp-includes' );
    1717
    18 require (ABSPATH . WPINC . '/load.php');
    19 require (ABSPATH . WPINC . '/default-constants.php');
    20 require (ABSPATH . WPINC . '/version.php');
     18// Include files required for initialization.
     19require( ABSPATH . WPINC . '/load.php' );
     20require( ABSPATH . WPINC . '/default-constants.php' );
     21require( ABSPATH . WPINC . '/version.php' );
    2122
    22 wp_default_constants('init');
     23// Set initial default constants including WP_MEMORY_LIMIT, WP_DEBUG, WP_CONTENT_DIR and WP_CACHE.
     24wp_default_constants( 'init' );
    2325
    24 set_magic_quotes_runtime(0);
    25 @ini_set('magic_quotes_sybase', 0);
     26// Disable magic quotes at runtime. Magic quotes are added using wpdb later in wp-settings.php.
     27set_magic_quotes_runtime( 0 );
     28@ini_set( 'magic_quotes_sybase', 0 );
    2629
    27 if ( function_exists('date_default_timezone_set') )
    28         date_default_timezone_set('UTC');
     30// Set default timezone in PHP 5.
     31if ( function_exists( 'date_default_timezone_set' ) )
     32        date_default_timezone_set( 'UTC' );
    2933
     34// Turn register_globals off.
    3035wp_unregister_GLOBALS();
    3136
     37// Ensure these global variables do not exist so they do not interfere with WordPress.
    3238unset( $wp_filter, $cache_lastcommentmodified, $cache_lastpostdate );
    3339
     40// Standardize $_SERVER variables across setups.
    3441wp_fix_server_vars();
    3542
     43// Check for the required PHP version and for the MySQL extension or a database drop-in.
    3644wp_check_php_mysql_versions();
    3745
     46// Check if we're in maintenance mode.
    3847wp_maintenance();
    3948
     49// Start loading timer.
    4050timer_start();
    4151
     52// Check if we're in WP_DEBUG mode.
    4253wp_debug_mode();
    4354
    44 // For an advanced caching plugin to use, static because you would only want one
     55// For an advanced caching plugin to use. Uses a static drop-in because you would only want one.
    4556if ( WP_CACHE )
    4657        @include WP_CONTENT_DIR . '/advanced-cache.php';
    4758
     59// Define WP_LANG_DIR if not set.
    4860wp_set_lang_dir();
    4961
    50 require (ABSPATH . WPINC . '/compat.php');
    51 require (ABSPATH . WPINC . '/functions.php');
    52 require (ABSPATH . WPINC . '/classes.php');
     62// Include early WordPress files.
     63require( ABSPATH . WPINC . '/compat.php' );
     64require( ABSPATH . WPINC . '/functions.php' );
     65require( ABSPATH . WPINC . '/classes.php' );
    5366
     67// Include the wpdb class, or a db.php database drop-in if present.
    5468require_wp_db();
    5569
     70// Set the database table prefix and the format specifiers for database table columns.
    5671wp_set_wpdb_vars();
    5772
     73// Start the WordPress object cache, or an external object cache if the drop-in is present.
    5874wp_start_object_cache();
    5975
     76// Initialize multisite if enabled.
    6077if ( is_multisite() )
    61     require (ABSPATH . WPINC . '/ms-load.php');
     78        require( ABSPATH . WPINC . '/ms-load.php' );
    6279
    63 require (ABSPATH . WPINC . '/plugin.php');
    64 require (ABSPATH . WPINC . '/default-filters.php');
    65 include_once(ABSPATH . WPINC . '/pomo/mo.php');
     80// Load early WordPress files.
     81require( ABSPATH . WPINC . '/plugin.php' );
     82require( ABSPATH . WPINC . '/default-filters.php' );
     83include_once( ABSPATH . WPINC . '/pomo/mo.php' );
    6684
    67 if ( SHORTINIT ) // stop most of WP being loaded, we just want the basics
     85// Stop most of WordPress from being loaded if we just want the basics.
     86if ( SHORTINIT )
    6887        return false;
    6988
    70 require_once (ABSPATH . WPINC . '/l10n.php');
     89// Load the l18n library.
     90require_once ( ABSPATH . WPINC . '/l10n.php' );
    7191
     92// Run the installer if WordPress is not installed.
    7293wp_not_installed();
    7394
    74 require (ABSPATH . WPINC . '/formatting.php');
    75 require (ABSPATH . WPINC . '/capabilities.php');
    76 require (ABSPATH . WPINC . '/query.php');
    77 require (ABSPATH . WPINC . '/theme.php');
    78 require (ABSPATH . WPINC . '/user.php');
    79 require (ABSPATH . WPINC . '/meta.php');
    80 require (ABSPATH . WPINC . '/general-template.php');
    81 require (ABSPATH . WPINC . '/link-template.php');
    82 require (ABSPATH . WPINC . '/author-template.php');
    83 require (ABSPATH . WPINC . '/post.php');
    84 require (ABSPATH . WPINC . '/post-template.php');
    85 require (ABSPATH . WPINC . '/category.php');
    86 require (ABSPATH . WPINC . '/category-template.php');
    87 require (ABSPATH . WPINC . '/comment.php');
    88 require (ABSPATH . WPINC . '/comment-template.php');
    89 require (ABSPATH . WPINC . '/rewrite.php');
    90 require (ABSPATH . WPINC . '/feed.php');
    91 require (ABSPATH . WPINC . '/bookmark.php');
    92 require (ABSPATH . WPINC . '/bookmark-template.php');
    93 require (ABSPATH . WPINC . '/kses.php');
    94 require (ABSPATH . WPINC . '/cron.php');
    95 require (ABSPATH . WPINC . '/deprecated.php');
    96 require (ABSPATH . WPINC . '/script-loader.php');
    97 require (ABSPATH . WPINC . '/taxonomy.php');
    98 require (ABSPATH . WPINC . '/update.php');
    99 require (ABSPATH . WPINC . '/canonical.php');
    100 require (ABSPATH . WPINC . '/shortcodes.php');
    101 require (ABSPATH . WPINC . '/media.php');
    102 require (ABSPATH . WPINC . '/http.php');
    103 require (ABSPATH . WPINC . '/widgets.php');
     95// Load most of WordPress.
     96require( ABSPATH . WPINC . '/formatting.php' );
     97require( ABSPATH . WPINC . '/capabilities.php' );
     98require( ABSPATH . WPINC . '/query.php' );
     99require( ABSPATH . WPINC . '/theme.php' );
     100require( ABSPATH . WPINC . '/user.php' );
     101require( ABSPATH . WPINC . '/meta.php' );
     102require( ABSPATH . WPINC . '/general-template.php' );
     103require( ABSPATH . WPINC . '/link-template.php' );
     104require( ABSPATH . WPINC . '/author-template.php' );
     105require( ABSPATH . WPINC . '/post.php' );
     106require( ABSPATH . WPINC . '/post-template.php' );
     107require( ABSPATH . WPINC . '/category.php' );
     108require( ABSPATH . WPINC . '/category-template.php' );
     109require( ABSPATH . WPINC . '/comment.php' );
     110require( ABSPATH . WPINC . '/comment-template.php' );
     111require( ABSPATH . WPINC . '/rewrite.php' );
     112require( ABSPATH . WPINC . '/feed.php' );
     113require( ABSPATH . WPINC . '/bookmark.php' );
     114require( ABSPATH . WPINC . '/bookmark-template.php' );
     115require( ABSPATH . WPINC . '/kses.php' );
     116require( ABSPATH . WPINC . '/cron.php' );
     117require( ABSPATH . WPINC . '/deprecated.php' );
     118require( ABSPATH . WPINC . '/script-loader.php' );
     119require( ABSPATH . WPINC . '/taxonomy.php' );
     120require( ABSPATH . WPINC . '/update.php' );
     121require( ABSPATH . WPINC . '/canonical.php' );
     122require( ABSPATH . WPINC . '/shortcodes.php' );
     123require( ABSPATH . WPINC . '/media.php' );
     124require( ABSPATH . WPINC . '/http.php' );
     125require( ABSPATH . WPINC . '/widgets.php' );
    104126
     127// Load multisite-specific files.
    105128if ( is_multisite() ) {
    106129        require_once( ABSPATH . WPINC . '/ms-functions.php' );
    107130        require_once( ABSPATH . WPINC . '/ms-default-filters.php' );
    108131        require_once( ABSPATH . WPINC . '/ms-deprecated.php' );
    109132}
    110133
    111 wp_default_constants('wp_included');
     134// Define constants that rely on the API to obtain the default value.
     135wp_default_constants( 'wp_included' );
    112136
     137// Set up multisite if enabled.
    113138if ( is_multisite() )
    114     ms_network_settings();
     139        ms_network_settings();
    115140
    116 wp_default_constants('ms_network_settings_loaded');
     141// Define must-use plugin directory constants, which may be overridden in the sunrise.php drop-in.
     142wp_default_constants( 'ms_network_settings_loaded' );
    117143
    118 wp_load_mu_plugins();
     144// Load must-use plugins.
     145foreach( wp_muplugins_to_load() as $mu_plugin )
     146        include_once( $mu_plugin );
     147unset( $mu_plugin );
    119148
    120 /**
    121  * Used to load network wide plugins
    122  * @since 3.0
    123  */
    124 if ( is_multisite() )
    125         ms_network_plugins();
     149// Load network-wide plugins if multisite.
     150if ( is_multisite() ) {
     151        foreach ( ms_network_plugins() as $plugin_file )
     152                include_once( $plugin_file );
     153        unset( $plugin_file );
     154}
    126155
    127 do_action('muplugins_loaded');
     156do_action( 'muplugins_loaded' );
    128157
    129 /**
    130  * Used to check site status
    131  * @since 3.0
    132  */
     158// Check site status if multisite.
    133159if ( is_multisite() ) {
    134         ms_site_check();
     160        if ( true !== ( $file = ms_site_check() ) ) {
     161                require_once( $file );
     162                die();
     163        }
    135164        ms_network_cookies();
    136165}
    137166
    138 wp_default_constants('ms_loaded');
     167// Define constants after multisite is loaded. Cookie-related constants may be overridden in ms_network_cookies().
     168wp_default_constants( 'ms_loaded' );
    139169
    140 require (ABSPATH . WPINC . '/vars.php');
     170// Create common globals.
     171require( ABSPATH . WPINC . '/vars.php' );
    141172
    142 // make taxonomies available to plugins and themes
    143 // @plugin authors: warning: this gets registered again on the init hook
     173// Make taxonomies available to plugins and themes.
     174// @plugin authors: warning: this gets registered again on the init hook.
    144175create_initial_taxonomies();
    145176
    146 wp_load_plugins();
     177// Load active plugins.
     178foreach( wp_plugins_to_load() as $plugin )
     179        include_once( $plugin );
     180unset( $plugin );
    147181
    148 require (ABSPATH . WPINC . '/pluggable.php');
     182// Load pluggable functions.
     183require( ABSPATH . WPINC . '/pluggable.php' );
    149184
     185// Set internal encoding.
    150186wp_set_internal_encoding();
    151187
    152 if ( WP_CACHE && function_exists('wp_cache_postload') )
     188// Run wp_cache_postload() if object cache is enabled and the function exists.
     189if ( WP_CACHE && function_exists( 'wp_cache_postload' ) )
    153190        wp_cache_postload();
    154191
    155 do_action('plugins_loaded');
     192do_action( 'plugins_loaded' );
    156193
    157 wp_default_constants('plugins_loaded');
     194// Define WP_POST_REVISIONS if not already defined.
     195wp_default_constants( 'plugins_loaded' );
    158196
     197// Add magic quotes and set up $_REQUEST ( $_GET + $_POST )
    159198wp_magic_quotes();
    160199
    161 do_action('sanitize_comment_cookies');
     200do_action( 'sanitize_comment_cookies' );
    162201
    163202/**
    164203 * WordPress Query object
     
    173212 * @global object $wp_query
    174213 * @since 1.5.0
    175214 */
    176 $wp_query     =& $wp_the_query;
     215$wp_query =& $wp_the_query;
    177216
    178217/**
    179218 * Holds the WordPress Rewrite object for creating pretty URLs
    180219 * @global object $wp_rewrite
    181220 * @since 1.5.0
    182221 */
    183 $wp_rewrite   =& new WP_Rewrite();
     222$wp_rewrite =& new WP_Rewrite();
    184223
    185224/**
    186225 * WordPress Object
    187226 * @global object $wp
    188227 * @since 2.0.0
    189228 */
    190 $wp           =& new WP();
     229$wp =& new WP();
    191230
    192231/**
    193232 * WordPress Widget Factory Object
     
    196235 */
    197236$wp_widget_factory =& new WP_Widget_Factory();
    198237
    199 do_action('setup_theme');
     238do_action( 'setup_theme' );
    200239
    201 wp_default_constants('setup_theme');
     240// Define the TEMPLATEPATH and STYLESHEETPATH constants.
     241wp_default_constants( 'setup_theme' );
    202242
    203243// Load the default text localization domain.
    204244load_default_textdomain();
    205245
    206 wp_find_locale();
     246// Find the blog locale.
     247$locale = get_locale();
     248$locale_file = WP_LANG_DIR . "/$locale.php";
     249if ( is_readable( $locale_file ) )
     250        require_once( $locale_file );
    207251
     252// Pull in locale data after loading text domain.
     253require_once( ABSPATH . WPINC . '/locale.php' );
     254
    208255/**
    209256 * WordPress Locale object for loading locale domain date and various strings.
    210257 * @global object $wp_locale
     
    212259 */
    213260$wp_locale =& new WP_Locale();
    214261
    215 wp_load_theme_functions();
     262// Load the functions for the active theme, for both parent and child theme if applicable.
     263if ( TEMPLATEPATH !== STYLESHEETPATH && file_exists( STYLESHEETPATH . '/functions.php' ) )
     264        include( STYLESHEETPATH . '/functions.php' );
     265if ( file_exists( TEMPLATEPATH . '/functions.php' ) )
     266        include( TEMPLATEPATH . '/functions.php' );
    216267
    217 register_shutdown_function('shutdown_action_hook');
     268// Load any template functions the theme supports.
     269require_if_theme_supports( 'post-thumbnails', ABSPATH . WPINC . '/post-thumbnail-template.php' );
    218270
    219 $wp->init();  // Sets up current user.
     271register_shutdown_function( 'shutdown_action_hook' );
    220272
     273// Set up current user.
     274$wp->init();
     275
    221276// Everything is loaded and initialized.
    222 do_action('init');
     277do_action( 'init' );
    223278
    224279?>
     280 No newline at end of file