Make WordPress Core

Ticket #31130: 31130.diff

File 31130.diff, 21.0 KB (added by jeremyfelt, 10 years ago)
  • src/wp-admin/admin.php

     
    8484auth_redirect();
    8585
    8686// Schedule trash collection
    87 if ( !wp_next_scheduled('wp_scheduled_delete') && !defined('WP_INSTALLING') )
     87if ( ! wp_next_scheduled( 'wp_scheduled_delete' ) && ! wp_defined( 'WP_INSTALLING' ) )
    8888        wp_schedule_event(time(), 'daily', 'wp_scheduled_delete');
    8989
    9090set_screen_options();
  • src/wp-admin/includes/class-wp-upgrader.php

     
    23752375                if ( defined( 'DISALLOW_FILE_MODS' ) && DISALLOW_FILE_MODS )
    23762376                        return true;
    23772377
    2378                 if ( defined( 'WP_INSTALLING' ) )
     2378                if ( wp_defined( 'WP_INSTALLING' ) )
    23792379                        return true;
    23802380
    23812381                // More fine grained control can be done through the WP_AUTO_UPDATE_CORE constant and filters.
  • src/wp-admin/includes/file.php

     
    10561056                        $stored_credentials['hostname'] .= ':' . $stored_credentials['port'];
    10571057
    10581058                unset($stored_credentials['password'], $stored_credentials['port'], $stored_credentials['private_key'], $stored_credentials['public_key']);
    1059                 if ( ! defined( 'WP_INSTALLING' ) ) {
     1059                if ( ! wp_defined( 'WP_INSTALLING' ) ) {
    10601060                        update_option( 'ftp_credentials', $stored_credentials );
    10611061                }
    10621062                return $credentials;
  • src/wp-admin/includes/misc.php

     
    237237 * @param string $value
    238238 */
    239239function update_home_siteurl( $old_value, $value ) {
    240         if ( defined( "WP_INSTALLING" ) )
     240        if ( wp_defined( 'WP_INSTALLING' ) )
    241241                return;
    242242
    243243        // If home changed, write rewrite rules to new location.
  • src/wp-admin/includes/translation-install.php

     
    9494 *               in an error, an empty array will be returned.
    9595 */
    9696function wp_get_available_translations() {
    97         if ( ! defined( 'WP_INSTALLING' ) && false !== ( $translations = get_site_transient( 'available_translations' ) ) ) {
     97        if ( ! wp_defined( 'WP_INSTALLING' ) && false !== ( $translations = get_site_transient( 'available_translations' ) ) ) {
    9898                return $translations;
    9999        }
    100100
     
    112112                $translations[ $translation['language'] ] = $translation;
    113113        }
    114114
    115         if ( ! defined( 'WP_INSTALLING' ) ) {
     115        if ( ! wp_defined( 'WP_INSTALLING' ) ) {
    116116                set_site_transient( 'available_translations', $translations, 3 * HOUR_IN_SECONDS );
    117117        }
    118118
  • src/wp-includes/default-constants.php

     
    66 */
    77
    88/**
     9 * Check if a constant is defined. If running unit tests, check the `$wp_config`
     10 * object for the constant's corresponding property.
     11 *
     12 * @since 4.2.0
     13 * @param string $constant Constant name to check.
     14 *
     15 * @return bool True if the constant is defined. False if not.
     16 */
     17function wp_defined( $constant ) {
     18        global $wp_config;
     19
     20        // If unit tests are running, use the global `$wp_config` object instead of constants.
     21        if ( defined( 'WP_RUN_CORE_TESTS' ) ) {
     22                if ( isset( $wp_config->$constant ) ) {
     23                        return true;
     24                }
     25
     26                return false;
     27        }
     28
     29        if ( defined( $constant ) ) {
     30                return true;
     31        }
     32
     33        return false;
     34}
     35
     36/**
     37 * Define a constant. If running unit tests, set the corresponding property in
     38 * the `$wp_config` object.
     39 *
     40 * @since 4.2.0
     41 * @param string $constant Constant name to define.
     42 * @param mixed  $value    Value to assign to the constant.
     43 *
     44 * @return bool True if constant was set.
     45 */
     46function wp_define( $constant, $value ) {
     47        global $wp_config;
     48
     49        // If unit tests are running, use the global `$wp_config` object instead of constants.
     50        if ( defined( 'WP_RUN_CORE_TESTS' ) ) {
     51                if ( isset( $wp_config->$constant ) && $value !== $wp_config->$constant ) {
     52                        // temp
     53                        wp_die( 'unit test constant already defined with a different value' );
     54                } elseif( isset( $wp_config->$constant ) && $value === $wp_config->$constant ) {
     55                        return true;
     56                }
     57
     58                $wp_config->$constant = $value;
     59
     60                return true;
     61        }
     62
     63        if ( defined( $constant ) && $value !== constant( $constant ) ) {
     64                // temp
     65                wp_die( 'constant already defined with a different value' );
     66        } elseif ( defined( $constant ) && $value === constant( $constant ) ) {
     67                return true;
     68        }
     69
     70        define( $constant, $value );
     71
     72        return true;
     73}
     74
     75/**
    976 * Defines initial WordPress constants
    1077 *
    1178 * @see wp_debug_mode()
  • src/wp-includes/functions.php

     
    12711271                return true;
    12721272
    12731273        $suppress = $wpdb->suppress_errors();
    1274         if ( ! defined( 'WP_INSTALLING' ) ) {
     1274        if ( ! wp_defined( 'WP_INSTALLING' ) ) {
    12751275                $alloptions = wp_load_alloptions();
    12761276        }
    12771277        // If siteurl is not set to autoload, check it specifically
     
    33023302        }
    33033303
    33043304        // If installing or in the admin, provide the verbose message.
    3305         if ( defined('WP_INSTALLING') || defined('WP_ADMIN') )
     3305        if ( wp_defined('WP_INSTALLING') || defined('WP_ADMIN') )
    33063306                wp_die($wpdb->error);
    33073307
    33083308        // Otherwise, be terse.
  • src/wp-includes/general-template.php

     
    28192819 * @param string $file file relative to wp-admin/ without its ".css" extension.
    28202820 */
    28212821function wp_admin_css_uri( $file = 'wp-admin' ) {
    2822         if ( defined('WP_INSTALLING') ) {
     2822        if ( wp_defined( 'WP_INSTALLING' ) ) {
    28232823                $_file = "./$file.css";
    28242824        } else {
    28252825                $_file = admin_url("$file.css");
  • src/wp-includes/l10n.php

     
    4949        // If multisite, check options.
    5050        if ( is_multisite() ) {
    5151                // Don't check blog option when installing.
    52                 if ( defined( 'WP_INSTALLING' ) || ( false === $ms_locale = get_option( 'WPLANG' ) ) ) {
     52                if ( wp_defined( 'WP_INSTALLING' ) || ( false === $ms_locale = get_option( 'WPLANG' ) ) ) {
    5353                        $ms_locale = get_site_option( 'WPLANG' );
    5454                }
    5555
     
    555555                return $return;
    556556        }
    557557
    558         if ( is_admin() || defined( 'WP_INSTALLING' ) || ( defined( 'WP_REPAIRING' ) && WP_REPAIRING ) ) {
     558        if ( is_admin() || wp_defined( 'WP_INSTALLING' ) || ( defined( 'WP_REPAIRING' ) && WP_REPAIRING ) ) {
    559559                load_textdomain( 'default', WP_LANG_DIR . "/admin-$locale.mo" );
    560560        }
    561561
  • src/wp-includes/load.php

     
    156156 * @global int $upgrading the unix timestamp marking when upgrading WordPress began.
    157157 */
    158158function wp_maintenance() {
    159         if ( !file_exists( ABSPATH . '.maintenance' ) || defined( 'WP_INSTALLING' ) )
     159        if ( !file_exists( ABSPATH . '.maintenance' ) || wp_defined( 'WP_INSTALLING' ) )
    160160                return;
    161161
    162162        global $upgrading;
     
    466466 */
    467467function wp_not_installed() {
    468468        if ( is_multisite() ) {
    469                 if ( ! is_blog_installed() && ! defined( 'WP_INSTALLING' ) ) {
     469                if ( ! is_blog_installed() && ! wp_defined( 'WP_INSTALLING' ) ) {
    470470                        nocache_headers();
    471471
    472472                        wp_die( __( 'The site you have requested is not installed properly. Please contact the system administrator.' ) );
    473473                }
    474         } elseif ( ! is_blog_installed() && ! defined( 'WP_INSTALLING' ) ) {
     474        } elseif ( ! is_blog_installed() && ! wp_defined( 'WP_INSTALLING' ) ) {
    475475                nocache_headers();
    476476
    477477                require( ABSPATH . WPINC . '/kses.php' );
     
    537537                array_unshift( $plugins, ABSPATH . 'my-hacks.php' );
    538538        }
    539539
    540         if ( empty( $active_plugins ) || defined( 'WP_INSTALLING' ) )
     540        if ( empty( $active_plugins ) || wp_defined( 'WP_INSTALLING' ) )
    541541                return $plugins;
    542542
    543543        $network_plugins = is_multisite() ? wp_get_active_network_plugins() : false;
  • src/wp-includes/ms-blogs.php

     
    635635        }
    636636
    637637        if ( did_action( 'init' ) ) {
     638                /* @var WP_ROLES $wp_roles */
    638639                $wp_roles->reinit();
    639640                $current_user = wp_get_current_user();
    640641                $current_user->for_blog( $new_blog );
  • src/wp-includes/ms-functions.php

     
    11261126        if ( domain_exists($domain, $path, $site_id) )
    11271127                return new WP_Error( 'blog_taken', __( 'Sorry, that site already exists!' ) );
    11281128
    1129         if ( !defined('WP_INSTALLING') )
    1130                 define( 'WP_INSTALLING', true );
     1129        if ( ! wp_defined( 'WP_INSTALLING' ) )
     1130                wp_define( 'WP_INSTALLING', true );
    11311131
    11321132        if ( ! $blog_id = insert_blog($domain, $path, $site_id) )
    11331133                return new WP_Error('insert_blog', __('Could not create site.'));
     
    21462146        if ( !is_main_site() )
    21472147                return;
    21482148
    2149         if ( !wp_next_scheduled('update_network_counts') && !defined('WP_INSTALLING') )
     2149        if ( ! wp_next_scheduled( 'update_network_counts' ) && ! wp_defined( 'WP_INSTALLING' ) )
    21502150                wp_schedule_event(time(), 'twicedaily', 'update_network_counts');
    21512151}
    21522152
  • src/wp-includes/ms-settings.php

     
    115115        }
    116116
    117117        // @todo Investigate when exactly this can occur.
    118         if ( empty( $current_blog ) && defined( 'WP_INSTALLING' ) ) {
     118        if ( empty( $current_blog ) && wp_defined( 'WP_INSTALLING' ) ) {
    119119                $current_blog = new stdClass;
    120120                $current_blog->blog_id = $blog_id = 1;
    121121        }
  • src/wp-includes/option.php

     
    4949        if ( defined( 'WP_SETUP_CONFIG' ) )
    5050                return false;
    5151
    52         if ( ! defined( 'WP_INSTALLING' ) ) {
     52        if ( ! wp_defined( 'WP_INSTALLING' ) ) {
    5353                // prevent non-existent options from triggering multiple queries
    5454                $notoptions = wp_cache_get( 'notoptions', 'options' );
    5555                if ( isset( $notoptions[ $option ] ) ) {
     
    158158function wp_load_alloptions() {
    159159        global $wpdb;
    160160
    161         if ( !defined( 'WP_INSTALLING' ) || !is_multisite() )
     161        if ( ! wp_defined( 'WP_INSTALLING' ) || ! is_multisite() )
    162162                $alloptions = wp_cache_get( 'alloptions', 'options' );
    163163        else
    164164                $alloptions = false;
     
    172172                foreach ( (array) $alloptions_db as $o ) {
    173173                        $alloptions[$o->option_name] = $o->option_value;
    174174                }
    175                 if ( !defined( 'WP_INSTALLING' ) || !is_multisite() )
     175                if ( ! wp_defined( 'WP_INSTALLING' ) || !is_multisite() )
    176176                        wp_cache_add( 'alloptions', $alloptions, 'options' );
    177177        }
    178178
     
    189189function wp_load_core_site_options( $site_id = null ) {
    190190        global $wpdb;
    191191
    192         if ( !is_multisite() || wp_using_ext_object_cache() || defined( 'WP_INSTALLING' ) )
     192        if ( ! is_multisite() || wp_using_ext_object_cache() || wp_defined( 'WP_INSTALLING' ) )
    193193                return;
    194194
    195195        if ( empty($site_id) )
     
    294294                wp_cache_set( 'notoptions', $notoptions, 'options' );
    295295        }
    296296
    297         if ( ! defined( 'WP_INSTALLING' ) ) {
     297        if ( ! wp_defined( 'WP_INSTALLING' ) ) {
    298298                $alloptions = wp_load_alloptions();
    299299                if ( isset( $alloptions[$option] ) ) {
    300300                        $alloptions[ $option ] = $serialized_value;
     
    390390        if ( ! $result )
    391391                return false;
    392392
    393         if ( ! defined( 'WP_INSTALLING' ) ) {
     393        if ( ! wp_defined( 'WP_INSTALLING' ) ) {
    394394                if ( 'yes' == $autoload ) {
    395395                        $alloptions = wp_load_alloptions();
    396396                        $alloptions[ $option ] = $serialized_value;
     
    464464        do_action( 'delete_option', $option );
    465465
    466466        $result = $wpdb->delete( $wpdb->options, array( 'option_name' => $option ) );
    467         if ( ! defined( 'WP_INSTALLING' ) ) {
     467        if ( ! wp_defined( 'WP_INSTALLING' ) ) {
    468468                if ( 'yes' == $row->autoload ) {
    469469                        $alloptions = wp_load_alloptions();
    470470                        if ( is_array( $alloptions ) && isset( $alloptions[$option] ) ) {
     
    582582                $value = wp_cache_get( $transient, 'transient' );
    583583        } else {
    584584                $transient_option = '_transient_' . $transient;
    585                 if ( ! defined( 'WP_INSTALLING' ) ) {
     585                if ( ! wp_defined( 'WP_INSTALLING' ) ) {
    586586                        // If option is not in alloptions, it is not autoloaded and thus has a timeout
    587587                        $alloptions = wp_load_alloptions();
    588588                        if ( !isset( $alloptions[$transient_option] ) ) {
  • src/wp-includes/script-loader.php

     
    744744function wp_style_loader_src( $src, $handle ) {
    745745        global $_wp_admin_css_colors;
    746746
    747         if ( defined('WP_INSTALLING') )
     747        if ( wp_defined('WP_INSTALLING') )
    748748                return preg_replace( '#^wp-admin/#', './', $src );
    749749
    750750        if ( 'colors' == $handle ) {
  • src/wp-includes/theme.php

     
    845845         *
    846846         * @param bool true Validation flag to check the current theme.
    847847         */
    848         if ( defined('WP_INSTALLING') || ! apply_filters( 'validate_current_theme', true ) )
     848        if ( wp_defined('WP_INSTALLING') || ! apply_filters( 'validate_current_theme', true ) )
    849849                return true;
    850850
    851851        if ( get_template() != WP_DEFAULT_THEME && !file_exists(get_template_directory() . '/index.php') ) {
  • src/wp-includes/update.php

     
    2121 * @return null|false Returns null if update is unsupported. Returns false if check is too soon.
    2222 */
    2323function wp_version_check( $extra_stats = array(), $force_check = false ) {
    24         if ( defined('WP_INSTALLING') )
     24        if ( wp_defined( 'WP_INSTALLING' ) )
    2525                return;
    2626
    2727        global $wpdb, $wp_local_package;
     
    185185function wp_update_plugins( $extra_stats = array() ) {
    186186        include( ABSPATH . WPINC . '/version.php' ); // include an unmodified $wp_version
    187187
    188         if ( defined('WP_INSTALLING') )
     188        if ( wp_defined( 'WP_INSTALLING' ) )
    189189                return false;
    190190
    191191        // If running blog-side, bail unless we've not checked in the last 12 hours
     
    339339function wp_update_themes( $extra_stats = array() ) {
    340340        include( ABSPATH . WPINC . '/version.php' ); // include an unmodified $wp_version
    341341
    342         if ( defined( 'WP_INSTALLING' ) )
     342        if ( wp_defined( 'WP_INSTALLING' ) )
    343343                return false;
    344344
    345345        $installed_themes = wp_get_themes();
     
    626626 * @since 3.1.0
    627627 */
    628628function wp_schedule_update_checks() {
    629         if ( !wp_next_scheduled('wp_version_check') && !defined('WP_INSTALLING') )
     629        if ( ! wp_next_scheduled( 'wp_version_check' ) && ! wp_defined( 'WP_INSTALLING' ) )
    630630                wp_schedule_event(time(), 'twicedaily', 'wp_version_check');
    631631
    632         if ( !wp_next_scheduled('wp_update_plugins') && !defined('WP_INSTALLING') )
     632        if ( ! wp_next_scheduled( 'wp_update_plugins' ) && ! wp_defined( 'WP_INSTALLING' ) )
    633633                wp_schedule_event(time(), 'twicedaily', 'wp_update_plugins');
    634634
    635         if ( !wp_next_scheduled('wp_update_themes') && !defined('WP_INSTALLING') )
     635        if ( ! wp_next_scheduled( 'wp_update_themes' ) && ! wp_defined( 'WP_INSTALLING' ) )
    636636                wp_schedule_event(time(), 'twicedaily', 'wp_update_themes');
    637637
    638         if ( ! wp_next_scheduled( 'wp_maybe_auto_update' ) && ! defined( 'WP_INSTALLING' ) ) {
     638        if ( ! wp_next_scheduled( 'wp_maybe_auto_update' ) && ! wp_defined( 'WP_INSTALLING' ) ) {
    639639                // Schedule auto updates for 7 a.m. and 7 p.m. in the timezone of the site.
    640640                $next = strtotime( 'today 7am' );
    641641                $now = time();
  • src/wp-settings.php

     
    1717 */
    1818define( 'WPINC', 'wp-includes' );
    1919
     20$wp_config = new stdClass();
     21
    2022// Include files required for initialization.
    2123require( ABSPATH . WPINC . '/load.php' );
    2224require( ABSPATH . WPINC . '/default-constants.php' );
     
    322324$GLOBALS['wp_locale'] = new WP_Locale();
    323325
    324326// Load the functions for the active theme, for both parent and child theme if applicable.
    325 if ( ! defined( 'WP_INSTALLING' ) || 'wp-activate.php' === $pagenow ) {
     327if ( ! wp_defined( 'WP_INSTALLING' ) || 'wp-activate.php' === $pagenow ) {
    326328        if ( TEMPLATEPATH !== STYLESHEETPATH && file_exists( STYLESHEETPATH . '/functions.php' ) )
    327329                include( STYLESHEETPATH . '/functions.php' );
    328330        if ( file_exists( TEMPLATEPATH . '/functions.php' ) )
  • tests/phpunit/includes/testcase.php

     
    5656        }
    5757
    5858        function tearDown() {
    59                 global $wpdb, $wp_query, $post;
     59                global $wpdb, $wp_query, $post, $wp_config;
    6060                $this->expectedDeprecated();
    6161                $wpdb->query( 'ROLLBACK' );
    6262                if ( is_multisite() ) {
     
    6666                }
    6767                $wp_query = new WP_Query();
    6868                $post = null;
     69                $wp_config = new stdClass();
    6970                remove_theme_support( 'html5' );
    7071                remove_filter( 'query', array( $this, '_create_temporary_tables' ) );
    7172                remove_filter( 'query', array( $this, '_drop_temporary_tables' ) );
  • tests/phpunit/tests/multisite/network.php

     
    170170                $this->assertFalse(wp_next_scheduled('update_network_counts'));
    171171
    172172                // We can't use wp_schedule_update_network_counts() because WP_INSTALLING is set
    173                 wp_schedule_event(time(), 'twicedaily', 'update_network_counts');
     173                wp_schedule_update_network_counts();
    174174
    175175                $this->assertInternalType('int', wp_next_scheduled('update_network_counts'));
    176176        }
  • tests/phpunit/tests/option/transient.php

     
    3838         * @ticket 22807
    3939         */
    4040        function test_transient_data_with_timeout() {
    41                 if ( is_multisite() ) {
    42                         $this->markTestSkipped( 'Not testable in MS: wpmu_create_blog() defines WP_INSTALLING.' );
    43                 }
    44 
    4541                $key = rand_str();
    4642                $value = rand_str();
    4743
     
    6359         * @ticket 22807
    6460         */
    6561        function test_transient_add_timeout() {
    66                 if ( is_multisite() ) {
    67                         $this->markTestSkipped( 'Not testable in MS: wpmu_create_blog() defines WP_INSTALLING.' );
    68                 }
    69 
    7062                $key = rand_str();
    7163                $value = rand_str();
    7264                $value2 = rand_str();
  • tests/phpunit/tests/post/getPostClass.php

     
    5050        public function test_taxonomy_classes_hit_cache() {
    5151                global $wpdb;
    5252
    53                 if ( is_multisite() ) {
    54                         $this->markTestSkipped( 'Not testable in MS: wpmu_create_blog() defines WP_INSTALLING, which causes cache misses.' );
    55                 }
    56 
    5753                register_taxonomy( 'wptests_tax', 'post' );
    5854                wp_set_post_terms( $this->post_id, array( 'foo', 'bar' ), 'wptests_tax' );
    5955                wp_set_post_terms( $this->post_id, array( 'footag', 'bartag' ), 'post_tag' );
  • tests/phpunit/tests/term/getTerms.php

     
    382382        public function test_child_of_should_skip_query_when_specified_parent_is_not_found_in_hierarchy_cache() {
    383383                global $wpdb;
    384384
    385                 if ( is_multisite() ) {
    386                         $this->markTestSkipped( 'Not testable in MS: wpmu_create_blog() defines WP_INSTALLING, which causes cache misses.' );
    387                 }
    388 
    389385                register_taxonomy( 'wptests_tax', 'post', array( 'hierarchical' => true, ) );
    390386
    391387                $terms = $this->factory->term->create_many( 3, array( 'taxonomy' => 'wptests_tax' ) );
     
    12491245        public function test_parent_should_skip_query_when_specified_parent_is_not_found_in_hierarchy_cache() {
    12501246                global $wpdb;
    12511247
    1252                 if ( is_multisite() ) {
    1253                         $this->markTestSkipped( 'Not testable in MS: wpmu_create_blog() defines WP_INSTALLING, which causes cache misses.' );
    1254                 }
    1255 
    12561248                register_taxonomy( 'wptests_tax', 'post', array( 'hierarchical' => true, ) );
    12571249
    12581250                $terms = $this->factory->term->create_many( 3, array( 'taxonomy' => 'wptests_tax' ) );