WordPress.org

Make WordPress Core

Ticket #21401: using-ext-function.diff

File using-ext-function.diff, 8.3 KB (added by wonderboymusic, 9 years ago)
  • wp-includes/load.php

     
    372372}
    373373
    374374/**
     375 * Access/Modify private global variable $_wp_using_ext_object_cache
     376 *
     377 * Toggle $_wp_using_ext_object_cache on and off without directly touching global
     378 *
     379 * @since 3.5.0
     380 *
     381 * @param bool $using Whether external object cache is being used
     382 * @return bool The current 'using' setting
     383 */
     384function wp_using_ext_object_cache( $using = null ) {
     385        global $_wp_using_ext_object_cache;
     386        $current_using = $_wp_using_ext_object_cache;
     387        if ( null !== $using )
     388                $_wp_using_ext_object_cache = $using;
     389        return $current_using;
     390}
     391
     392/**
    375393 * Starts the WordPress object cache.
    376394 *
    377395 * If an object-cache.php file exists in the wp-content directory,
     
    381399 * @since 3.0.0
    382400 */
    383401function wp_start_object_cache() {
    384         global $_wp_using_ext_object_cache;
    385 
    386402        $first_init = false;
    387403        if ( ! function_exists( 'wp_cache_init' ) ) {
    388404                if ( file_exists( WP_CONTENT_DIR . '/object-cache.php' ) ) {
    389405                        require_once ( WP_CONTENT_DIR . '/object-cache.php' );
    390                         $_wp_using_ext_object_cache = true;
    391                 } else {
    392                         require_once ( ABSPATH . WPINC . '/cache.php' );
    393                         $_wp_using_ext_object_cache = false;
     406                        if ( function_exists( 'wp_cache_init' ) )
     407                                wp_using_ext_object_cache( true );
    394408                }
     409               
    395410                $first_init = true;
    396         } 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' ) ) {
    397412                // Sometimes advanced-cache.php can load object-cache.php before it is loaded here.
    398413                // This breaks the function_exists check above and can result in $_wp_using_ext_object_cache
    399414                // being set incorrectly. Double check if an external cache exists.
    400                 $_wp_using_ext_object_cache = true;
     415                wp_using_ext_object_cache( true );
    401416        }
    402417
     418        if ( ! wp_using_ext_object_cache() )
     419                require_once ( ABSPATH . WPINC . '/cache.php' );
     420       
    403421        // If cache supports reset, reset instead of init if already initialized.
    404422        // Reset signals to the cache that global IDs have changed and it may need to update keys
    405423        // and cleanup caches.
    406         if ( !$first_init && function_exists('wp_cache_reset') )
     424        if ( !$first_init && function_exists( 'wp_cache_reset' ) )
    407425                wp_cache_reset();
    408         else
     426        elseif ( function_exists( 'wp_cache_init' ) )
    409427                wp_cache_init();
    410428
    411429        if ( function_exists( 'wp_cache_add_global_groups' ) ) {
  • wp-includes/query.php

     
    19151915         * @return array List of posts.
    19161916         */
    19171917        function &get_posts() {
    1918                 global $wpdb, $user_ID, $_wp_using_ext_object_cache;
     1918                global $wpdb, $user_ID;
    19191919
    19201920                $this->parse_query();
    19211921
     
    19651965                        $q['suppress_filters'] = false;
    19661966
    19671967                if ( !isset($q['cache_results']) ) {
    1968                         if ( $_wp_using_ext_object_cache )
     1968                        if ( wp_using_ext_object_cache() )
    19691969                                $q['cache_results'] = false;
    19701970                        else
    19711971                                $q['cache_results'] = true;
  • wp-includes/option.php

     
    166166 * @param int $site_id Optional site ID for which to query the options. Defaults to the current site.
    167167 */
    168168function wp_load_core_site_options( $site_id = null ) {
    169         global $wpdb, $_wp_using_ext_object_cache;
     169        global $wpdb;
    170170
    171         if ( !is_multisite() || $_wp_using_ext_object_cache || defined( 'WP_INSTALLING' ) )
     171        if ( !is_multisite() || wp_using_ext_object_cache() || defined( 'WP_INSTALLING' ) )
    172172                return;
    173173
    174174        if ( empty($site_id) )
     
    401401 * @return bool true if successful, false otherwise
    402402 */
    403403function delete_transient( $transient ) {
    404         global $_wp_using_ext_object_cache;
    405 
    406404        do_action( 'delete_transient_' . $transient, $transient );
    407405
    408         if ( $_wp_using_ext_object_cache ) {
     406        if ( wp_using_ext_object_cache() ) {
    409407                $result = wp_cache_delete( $transient, 'transient' );
    410408        } else {
    411409                $option_timeout = '_transient_timeout_' . $transient;
     
    440438 * @return mixed Value of transient
    441439 */
    442440function get_transient( $transient ) {
    443         global $_wp_using_ext_object_cache;
    444 
    445441        $pre = apply_filters( 'pre_transient_' . $transient, false );
    446442        if ( false !== $pre )
    447443                return $pre;
    448444
    449         if ( $_wp_using_ext_object_cache ) {
     445        if ( wp_using_ext_object_cache() ) {
    450446                $value = wp_cache_get( $transient, 'transient' );
    451447        } else {
    452448                $transient_option = '_transient_' . $transient;
     
    489485 * @return bool False if value was not set and true if value was set.
    490486 */
    491487function set_transient( $transient, $value, $expiration = 0 ) {
    492         global $_wp_using_ext_object_cache;
    493 
    494488        $value = apply_filters( 'pre_set_transient_' . $transient, $value );
    495489
    496         if ( $_wp_using_ext_object_cache ) {
     490        if ( wp_using_ext_object_cache() ) {
    497491                $result = wp_cache_set( $transient, $value, 'transient', $expiration );
    498492        } else {
    499493                $transient_timeout = '_transient_timeout_' . $transient;
     
    932926 * @return bool True if successful, false otherwise
    933927 */
    934928function delete_site_transient( $transient ) {
    935         global $_wp_using_ext_object_cache;
    936 
    937929        do_action( 'delete_site_transient_' . $transient, $transient );
    938         if ( $_wp_using_ext_object_cache ) {
     930        if ( wp_using_ext_object_cache() ) {
    939931                $result = wp_cache_delete( $transient, 'site-transient' );
    940932        } else {
    941933                $option_timeout = '_site_transient_timeout_' . $transient;
     
    970962 * @return mixed Value of transient
    971963 */
    972964function get_site_transient( $transient ) {
    973         global $_wp_using_ext_object_cache;
    974 
    975965        $pre = apply_filters( 'pre_site_transient_' . $transient, false );
    976966        if ( false !== $pre )
    977967                return $pre;
    978968
    979         if ( $_wp_using_ext_object_cache ) {
     969        if ( wp_using_ext_object_cache() ) {
    980970                $value = wp_cache_get( $transient, 'site-transient' );
    981971        } else {
    982972                // Core transients that do not have a timeout. Listed here so querying timeouts can be avoided.
     
    10191009 * @return bool False if value was not set and true if value was set.
    10201010 */
    10211011function set_site_transient( $transient, $value, $expiration = 0 ) {
    1022         global $_wp_using_ext_object_cache;
    1023 
    10241012        $value = apply_filters( 'pre_set_site_transient_' . $transient, $value );
    10251013
    1026         if ( $_wp_using_ext_object_cache ) {
     1014        if ( wp_using_ext_object_cache() ) {
    10271015                $result = wp_cache_set( $transient, $value, 'site-transient', $expiration );
    10281016        } else {
    10291017                $transient_timeout = '_site_transient_timeout_' . $transient;
  • wp-includes/nav-menu.php

     
    468468 * @return mixed $items array of menu items, else false.
    469469 */
    470470function wp_get_nav_menu_items( $menu, $args = array() ) {
    471         global $_wp_using_ext_object_cache;
    472 
    473471        $menu = wp_get_nav_menu_object( $menu );
    474472
    475473        if ( ! $menu )
     
    497495                return false;
    498496
    499497        // Get all posts and terms at once to prime the caches
    500         if ( empty( $fetched[$menu->term_id] ) || $_wp_using_ext_object_cache ) {
     498        if ( empty( $fetched[$menu->term_id] ) || wp_using_ext_object_cache() ) {
    501499                $fetched[$menu->term_id] = true;
    502500                $posts = array();
    503501                $terms = array();
  • wp-settings.php

     
    5555wp_debug_mode();
    5656
    5757// For an advanced caching plugin to use. Uses a static drop-in because you would only want one.
    58 if ( WP_CACHE )
     58if ( WP_CACHE && file_exists( WP_CONTENT_DIR . '/advanced-cache.php' ) )
    5959        WP_DEBUG ? include( WP_CONTENT_DIR . '/advanced-cache.php' ) : @include( WP_CONTENT_DIR . '/advanced-cache.php' );
    6060
    6161// Define WP_LANG_DIR if not set.
  • 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 );