Advertisement
Guest User

wp_start_object_cache

a guest
Apr 3rd, 2018
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.09 KB | None | 0 0
  1. /**
  2.  * Start the WordPress object cache.
  3.  *
  4.  * If an object-cache.php file exists in the wp-content directory,
  5.  * it uses that drop-in as an external object cache.
  6.  *
  7.  * @since 3.0.0
  8.  * @access private
  9.  *
  10.  * @global array $wp_filter Stores all of the filters.
  11.  */
  12. function wp_start_object_cache() {
  13.     global $wp_filter;
  14.  
  15.     $first_init = false;
  16.     if ( ! function_exists( 'wp_cache_init' ) ) {
  17.         if ( file_exists( WP_CONTENT_DIR . '/object-cache.php' ) ) {
  18.             require_once ( WP_CONTENT_DIR . '/object-cache.php' );
  19.             if ( function_exists( 'wp_cache_init' ) ) {
  20.                 wp_using_ext_object_cache( true );
  21.             }
  22.  
  23.             // Re-initialize any hooks added manually by object-cache.php
  24.             if ( $wp_filter ) {
  25.                 $wp_filter = WP_Hook::build_preinitialized_hooks( $wp_filter );
  26.             }
  27.         }
  28.  
  29.         $first_init = true;
  30.     } elseif ( ! wp_using_ext_object_cache() && file_exists( WP_CONTENT_DIR . '/object-cache.php' ) ) {
  31.         /*
  32.          * Sometimes advanced-cache.php can load object-cache.php before
  33.          * it is loaded here. This breaks the function_exists check above
  34.          * and can result in `$_wp_using_ext_object_cache` being set
  35.          * incorrectly. Double check if an external cache exists.
  36.          */
  37.         wp_using_ext_object_cache( true );
  38.     }
  39.  
  40.     if ( ! wp_using_ext_object_cache() ) {
  41.         require_once ( ABSPATH . WPINC . '/cache.php' );
  42.     }
  43.  
  44.     /*
  45.      * If cache supports reset, reset instead of init if already
  46.      * initialized. Reset signals to the cache that global IDs
  47.      * have changed and it may need to update keys and cleanup caches.
  48.      */
  49.     if ( ! $first_init && function_exists( 'wp_cache_switch_to_blog' ) ) {
  50.         wp_cache_switch_to_blog( get_current_blog_id() );
  51.     } elseif ( function_exists( 'wp_cache_init' ) ) {
  52.         wp_cache_init();
  53.     }
  54.  
  55.     if ( function_exists( 'wp_cache_add_global_groups' ) ) {
  56.         wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'user_meta', 'useremail', 'userslugs', 'site-transient', 'site-options', 'blog-lookup', 'blog-details', 'site-details', 'rss', 'global-posts', 'blog-id-cache', 'networks', 'sites' ) );
  57.         wp_cache_add_non_persistent_groups( array( 'counts', 'plugins' ) );
  58.     }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement