Make WordPress Core

Ticket #21401: 21401-r1.diff

File 21401-r1.diff, 8.3 KB (added by devesine, 12 years ago)

Refreshed patch against r23698.

  • 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, $blog_id;
     402        global $blog_id;
    385403
    386404        $first_init = false;
    387405        if ( ! function_exists( 'wp_cache_init' ) ) {
    388406                if ( file_exists( WP_CONTENT_DIR . '/object-cache.php' ) ) {
    389407                        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;
     408                        if ( function_exists( 'wp_cache_init' ) )
     409                                wp_using_ext_object_cache( true );
    394410                }
     411               
    395412                $first_init = true;
    396         } else if ( !$_wp_using_ext_object_cache && file_exists( WP_CONTENT_DIR . '/object-cache.php' ) ) {
     413        } else if ( !wp_using_ext_object_cache() && file_exists( WP_CONTENT_DIR . '/object-cache.php' ) ) {
    397414                // Sometimes advanced-cache.php can load object-cache.php before it is loaded here.
    398415                // This breaks the function_exists check above and can result in $_wp_using_ext_object_cache
    399416                // being set incorrectly. Double check if an external cache exists.
    400                 $_wp_using_ext_object_cache = true;
     417                wp_using_ext_object_cache( true );
    401418        }
    402419
     420        if ( ! wp_using_ext_object_cache() )
     421                require_once ( ABSPATH . WPINC . '/cache.php' );
     422       
    403423        // If cache supports reset, reset instead of init if already initialized.
    404424        // Reset signals to the cache that global IDs have changed and it may need to update keys
    405425        // and cleanup caches.
    406426        if ( ! $first_init && function_exists( 'wp_cache_switch_to_blog' ) )
    407427                wp_cache_switch_to_blog( $blog_id );
    408         else
     428        elseif ( function_exists( 'wp_cache_init' ) )
    409429                wp_cache_init();
    410430
    411431        if ( function_exists( 'wp_cache_add_global_groups' ) ) {
  • wp-includes/query.php

     
    19171917         * @return array List of posts.
    19181918         */
    19191919        function get_posts() {
    1920                 global $wpdb, $user_ID, $_wp_using_ext_object_cache;
     1920                global $wpdb, $user_ID;
    19211921
    19221922                $this->parse_query();
    19231923
     
    19671967                        $q['suppress_filters'] = false;
    19681968
    19691969                if ( !isset($q['cache_results']) ) {
    1970                         if ( $_wp_using_ext_object_cache )
     1970                        if ( wp_using_ext_object_cache() )
    19711971                                $q['cache_results'] = false;
    19721972                        else
    19731973                                $q['cache_results'] = true;
  • 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;
     
    492488 * @return bool False if value was not set and true if value was set.
    493489 */
    494490function set_transient( $transient, $value, $expiration = 0 ) {
    495         global $_wp_using_ext_object_cache;
    496 
    497491        $value = apply_filters( 'pre_set_transient_' . $transient, $value );
    498492
    499         if ( $_wp_using_ext_object_cache ) {
     493        if ( wp_using_ext_object_cache() ) {
    500494                $result = wp_cache_set( $transient, $value, 'transient', $expiration );
    501495        } else {
    502496                $transient_timeout = '_transient_timeout_' . $transient;
     
    945939 * @return bool True if successful, false otherwise
    946940 */
    947941function delete_site_transient( $transient ) {
    948         global $_wp_using_ext_object_cache;
    949 
    950942        do_action( 'delete_site_transient_' . $transient, $transient );
    951         if ( $_wp_using_ext_object_cache ) {
     943        if ( wp_using_ext_object_cache() ) {
    952944                $result = wp_cache_delete( $transient, 'site-transient' );
    953945        } else {
    954946                $option_timeout = '_site_transient_timeout_' . $transient;
     
    983975 * @return mixed Value of transient
    984976 */
    985977function get_site_transient( $transient ) {
    986         global $_wp_using_ext_object_cache;
    987 
    988978        $pre = apply_filters( 'pre_site_transient_' . $transient, false );
    989979        if ( false !== $pre )
    990980                return $pre;
    991981
    992         if ( $_wp_using_ext_object_cache ) {
     982        if ( wp_using_ext_object_cache() ) {
    993983                $value = wp_cache_get( $transient, 'site-transient' );
    994984        } else {
    995985                // Core transients that do not have a timeout. Listed here so querying timeouts can be avoided.
     
    10321022 * @return bool False if value was not set and true if value was set.
    10331023 */
    10341024function set_site_transient( $transient, $value, $expiration = 0 ) {
    1035         global $_wp_using_ext_object_cache;
    1036 
    10371025        $value = apply_filters( 'pre_set_site_transient_' . $transient, $value );
    10381026
    1039         if ( $_wp_using_ext_object_cache ) {
     1027        if ( wp_using_ext_object_cache() ) {
    10401028                $result = wp_cache_set( $transient, $value, 'site-transient', $expiration );
    10411029        } else {
    10421030                $transient_timeout = '_site_transient_timeout_' . $transient;
  • wp-includes/nav-menu.php

     
    469469 * @return mixed $items array of menu items, else false.
    470470 */
    471471function wp_get_nav_menu_items( $menu, $args = array() ) {
    472         global $_wp_using_ext_object_cache;
    473 
    474472        $menu = wp_get_nav_menu_object( $menu );
    475473
    476474        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

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