WordPress.org

Make WordPress Core

Ticket #21401: 21401.2.diff

File 21401.2.diff, 7.9 KB (added by wonderboymusic, 8 years ago)
  • src/wp-includes/load.php

     
    370370}
    371371
    372372/**
     373 * Access/Modify private global variable $_wp_using_ext_object_cache
     374 *
     375 * Toggle $_wp_using_ext_object_cache on and off without directly touching global
     376 *
     377 * @since 3.7.0
     378 *
     379 * @param bool $using Whether external object cache is being used
     380 * @return bool The current 'using' setting
     381 */
     382function wp_using_ext_object_cache( $using = null ) {
     383        global $_wp_using_ext_object_cache;
     384        $current_using = $_wp_using_ext_object_cache;
     385        if ( null !== $using )
     386                $_wp_using_ext_object_cache = $using;
     387        return $current_using;
     388}
     389
     390/**
    373391 * Starts the WordPress object cache.
    374392 *
    375393 * If an object-cache.php file exists in the wp-content directory,
     
    379397 * @since 3.0.0
    380398 */
    381399function wp_start_object_cache() {
    382         global $_wp_using_ext_object_cache, $blog_id;
     400        global $blog_id;
    383401
    384402        $first_init = false;
    385403        if ( ! function_exists( 'wp_cache_init' ) ) {
    386404                if ( file_exists( WP_CONTENT_DIR . '/object-cache.php' ) ) {
    387405                        require_once ( WP_CONTENT_DIR . '/object-cache.php' );
    388                         $_wp_using_ext_object_cache = true;
    389                 } else {
    390                         require_once ( ABSPATH . WPINC . '/cache.php' );
    391                         $_wp_using_ext_object_cache = false;
     406                        if ( function_exists( 'wp_cache_init' ) )
     407                                wp_using_ext_object_cache( true );
    392408                }
     409
    393410                $first_init = true;
    394         } else if ( !$_wp_using_ext_object_cache && file_exists( WP_CONTENT_DIR . '/object-cache.php' ) ) {
     411        } else if ( ! wp_using_ext_object_cache() && file_exists( WP_CONTENT_DIR . '/object-cache.php' ) ) {
    395412                // Sometimes advanced-cache.php can load object-cache.php before it is loaded here.
    396413                // This breaks the function_exists check above and can result in $_wp_using_ext_object_cache
    397414                // being set incorrectly. Double check if an external cache exists.
    398                 $_wp_using_ext_object_cache = true;
     415                wp_using_ext_object_cache( true );
    399416        }
    400417
     418        if ( ! wp_using_ext_object_cache() )
     419                require_once ( ABSPATH . WPINC . '/cache.php' );
     420
    401421        // If cache supports reset, reset instead of init if already initialized.
    402422        // Reset signals to the cache that global IDs have changed and it may need to update keys
    403423        // and cleanup caches.
    404424        if ( ! $first_init && function_exists( 'wp_cache_switch_to_blog' ) )
    405425                wp_cache_switch_to_blog( $blog_id );
    406         else
     426        elseif ( function_exists( 'wp_cache_init' ) )
    407427                wp_cache_init();
    408428
    409429        if ( function_exists( 'wp_cache_add_global_groups' ) ) {
  • src/wp-includes/query.php

     
    19461946         * @return array List of posts.
    19471947         */
    19481948        function get_posts() {
    1949                 global $wpdb, $user_ID, $_wp_using_ext_object_cache;
     1949                global $wpdb, $user_ID;
    19501950
    19511951                $this->parse_query();
    19521952
     
    19961996                        $q['suppress_filters'] = false;
    19971997
    19981998                if ( !isset($q['cache_results']) ) {
    1999                         if ( $_wp_using_ext_object_cache )
     1999                        if ( wp_using_ext_object_cache() )
    20002000                                $q['cache_results'] = false;
    20012001                        else
    20022002                                $q['cache_results'] = true;
  • src/wp-includes/option.php

     
    165165 * @param int $site_id Optional site ID for which to query the options. Defaults to the current site.
    166166 */
    167167function wp_load_core_site_options( $site_id = null ) {
    168         global $wpdb, $_wp_using_ext_object_cache;
     168        global $wpdb;
    169169
    170         if ( !is_multisite() || $_wp_using_ext_object_cache || defined( 'WP_INSTALLING' ) )
     170        if ( !is_multisite() || wp_using_ext_object_cache() || defined( 'WP_INSTALLING' ) )
    171171                return;
    172172
    173173        if ( empty($site_id) )
     
    404404 * @return bool true if successful, false otherwise
    405405 */
    406406function delete_transient( $transient ) {
    407         global $_wp_using_ext_object_cache;
    408 
    409407        do_action( 'delete_transient_' . $transient, $transient );
    410408
    411         if ( $_wp_using_ext_object_cache ) {
     409        if ( wp_using_ext_object_cache() ) {
    412410                $result = wp_cache_delete( $transient, 'transient' );
    413411        } else {
    414412                $option_timeout = '_transient_timeout_' . $transient;
     
    443441 * @return mixed Value of transient
    444442 */
    445443function get_transient( $transient ) {
    446         global $_wp_using_ext_object_cache;
    447 
    448444        $pre = apply_filters( 'pre_transient_' . $transient, false );
    449445        if ( false !== $pre )
    450446                return $pre;
    451447
    452         if ( $_wp_using_ext_object_cache ) {
     448        if ( wp_using_ext_object_cache() ) {
    453449                $value = wp_cache_get( $transient, 'transient' );
    454450        } else {
    455451                $transient_option = '_transient_' . $transient;
     
    493489 * @return bool False if value was not set and true if value was set.
    494490 */
    495491function set_transient( $transient, $value, $expiration = 0 ) {
    496         global $_wp_using_ext_object_cache;
    497 
    498492        $value = apply_filters( 'pre_set_transient_' . $transient, $value );
    499493
    500         if ( $_wp_using_ext_object_cache ) {
     494        if ( wp_using_ext_object_cache() ) {
    501495                $result = wp_cache_set( $transient, $value, 'transient', $expiration );
    502496        } else {
    503497                $transient_timeout = '_transient_timeout_' . $transient;
     
    970964 * @return bool True if successful, false otherwise
    971965 */
    972966function delete_site_transient( $transient ) {
    973         global $_wp_using_ext_object_cache;
    974 
    975967        do_action( 'delete_site_transient_' . $transient, $transient );
    976         if ( $_wp_using_ext_object_cache ) {
     968        if ( wp_using_ext_object_cache() ) {
    977969                $result = wp_cache_delete( $transient, 'site-transient' );
    978970        } else {
    979971                $option_timeout = '_site_transient_timeout_' . $transient;
     
    10081000 * @return mixed Value of transient
    10091001 */
    10101002function get_site_transient( $transient ) {
    1011         global $_wp_using_ext_object_cache;
    1012 
    10131003        $pre = apply_filters( 'pre_site_transient_' . $transient, false );
    10141004        if ( false !== $pre )
    10151005                return $pre;
    10161006
    1017         if ( $_wp_using_ext_object_cache ) {
     1007        if ( wp_using_ext_object_cache() ) {
    10181008                $value = wp_cache_get( $transient, 'site-transient' );
    10191009        } else {
    10201010                // Core transients that do not have a timeout. Listed here so querying timeouts can be avoided.
     
    10581048 * @return bool False if value was not set and true if value was set.
    10591049 */
    10601050function set_site_transient( $transient, $value, $expiration = 0 ) {
    1061         global $_wp_using_ext_object_cache;
    1062 
    10631051        $value = apply_filters( 'pre_set_site_transient_' . $transient, $value );
    10641052
    1065         if ( $_wp_using_ext_object_cache ) {
     1053        if ( wp_using_ext_object_cache() ) {
    10661054                $result = wp_cache_set( $transient, $value, 'site-transient', $expiration );
    10671055        } else {
    10681056                $transient_timeout = '_site_transient_timeout_' . $transient;
  • src/wp-includes/nav-menu.php

     
    476476 * @return mixed $items array of menu items, else false.
    477477 */
    478478function wp_get_nav_menu_items( $menu, $args = array() ) {
    479         global $_wp_using_ext_object_cache;
    480 
    481479        $menu = wp_get_nav_menu_object( $menu );
    482480
    483481        if ( ! $menu )
     
    504502                return false;
    505503
    506504        // Get all posts and terms at once to prime the caches
    507         if ( empty( $fetched[$menu->term_id] ) || $_wp_using_ext_object_cache ) {
     505        if ( empty( $fetched[$menu->term_id] ) || wp_using_ext_object_cache() ) {
    508506                $fetched[$menu->term_id] = true;
    509507                $posts = array();
    510508                $terms = array();
  • src/wp-cron.php

     
    2828
    2929// Uncached doing_cron transient fetch
    3030function _get_cron_lock() {
    31         global $_wp_using_ext_object_cache, $wpdb;
     31        global $wpdb;
    3232
    3333        $value = 0;
    34         if ( $_wp_using_ext_object_cache ) {
     34        if ( wp_using_ext_object_cache() ) {
    3535                // Skip local cache and force refetch of doing_cron transient in case
    3636                // another processs updated the cache
    3737                $value = wp_cache_get( 'doing_cron', 'transient', true );