示例#1
0
 function flush()
 {
     static $done = false;
     if ($done) {
         return false;
     }
     # can't flush if WP isn't loaded
     if (!function_exists('get_option')) {
         return false;
     }
     $done = true;
     global $wpdb;
     $this->flush = true;
     if (method_exists('static_cache', 'disable')) {
         static_cache::disable();
     }
     # flush posts
     $posts = $wpdb->get_results("SELECT ID, post_title, post_name, post_date, post_type, post_status, post_author, post_parent FROM {$wpdb->posts} WHERE post_status IN ('publish', 'private') OR post_type = 'attachment'");
     # force WP widgets to flush
     wp_cache_delete('widget_recent_posts', 'widget');
     wp_cache_delete('recent_comments', 'widget');
     wp_cache_delete('get_calendar', 'calendar');
     wp_cache_delete('wp_get_archives', 'general');
     wp_cache_delete('all_page_ids', 'posts');
     wp_cache_delete('get_pages', 'posts');
     $post_ids = array();
     foreach ($posts as $post) {
         $post_ids[] = $post->ID;
         $this->delete($post->ID, 'posts');
         $this->delete($post->ID, 'post_meta');
         clean_object_term_cache($post->ID, 'post');
         do_action('clean_post_cache', $post->ID);
         # fill a temporary bucket so as to handle permalinks
         $key = $this->key($post->ID, 'posts');
         $this->cache[$key] = $post;
         if (class_exists('sem_cache') && $post->post_type == 'post') {
             sem_cache::do_flush_author($post->post_author);
             sem_cache::do_flush_date($post->post_date);
         }
     }
     unset($posts);
     if (class_exists('sem_cache')) {
         # flush get_permalink() intensive stuff before flushing terms
         foreach ($post_ids as $post_id) {
             sem_cache::do_flush_post($post_id);
         }
         # flush home
         sem_cache::do_flush_home();
     }
     # flush terms
     $terms = $wpdb->get_results("SELECT term_id, taxonomy FROM {$wpdb->term_taxonomy} WHERE count > 0");
     $taxonomies = array();
     $term_ids = array();
     if (class_exists('sem_cache')) {
         foreach ($terms as $term) {
             sem_cache::do_flush_term($term->term_id, $term->taxonomy);
         }
     }
     foreach ($terms as $term) {
         $taxonomies[] = $term->taxonomy;
         $term_ids[] = $term->term_id;
         $this->delete($term->term_id, $term->taxonomy);
     }
     $taxonomies = array_unique($taxonomies);
     foreach ($taxonomies as $taxonomy) {
         $this->delete('all_ids', $taxonomy);
         $this->delete('get', $taxonomy);
         delete_option("{$taxonomy}_children");
         do_action('clean_term_cache', $term_ids, $taxonomy);
     }
     $this->delete('last_changed', 'terms');
     unset($terms);
     # flush users
     $user_ids = $wpdb->get_col("SELECT ID FROM {$wpdb->users}");
     foreach ($user_ids as $user_id) {
         $this->delete($user_id, 'users');
     }
     unset($user_ids);
     # backup key transients
     $transients = array('update_core', 'update_plugins', 'update_themes', 'sem_memberships', 'sem_update_plugins', 'sem_update_themes');
     $extra = array('feed_220431e2eb0959fa9c7fcb07c6e22632', 'feed_mod_220431e2eb0959fa9c7fcb07c6e22632');
     foreach (array_merge($transients, $extra) as $var) {
         ${$var} = get_transient($var);
     }
     # flush options
     $options = $wpdb->get_col("SELECT option_name FROM {$wpdb->options}");
     foreach ($options as $option) {
         if (!in_array($option, array_merge($transients, $extra))) {
             if (preg_match("/^_transient_/", $option)) {
                 delete_option($option);
             } else {
                 $this->delete($option, 'options');
             }
         }
     }
     $this->delete('notoptions', 'options');
     $this->delete('alloptions', 'options');
     unset($options);
     # restore key transients
     foreach ($transients as $var) {
         if (${$var} !== false) {
             set_transient($var, ${$var});
         }
     }
     if ($feed_220431e2eb0959fa9c7fcb07c6e22632 !== false) {
         $var = 'feed_220431e2eb0959fa9c7fcb07c6e22632';
         set_transient($var, ${$var}, min(3600, cache_timeout));
         $var = 'feed_mod_220431e2eb0959fa9c7fcb07c6e22632';
         set_transient($var, time(), min(3600, cache_timeout));
     }
     return true;
 }