/** * disable_static() * * @return void **/ static function disable_static() { update_site_option('static_cache', 0); update_site_option('memory_cache', 0); wp_clear_scheduled_hook('cache_timeout'); wp_clear_scheduled_hook('static_cache_timeout'); # Prevent WP from adding new pages $file = ABSPATH . 'wp-config.php'; if (defined('WP_CACHE')) { $contents = file_get_contents($file); $contents = preg_replace("/\n\t\t\t\t(?!(?:\\/\\/|\\#)\\s*)\n\t\t\t\tdefine\\s*\\(\\s*\n\t\t\t\t\t(['\"])WP_CACHE\\1\n\t\t\t\t\t.*?;\n\t\t\t\t\t\\s*\n\t\t\t\t/x", PHP_EOL, $contents); if (!$contents || !file_put_contents($file, $contents)) { echo '<div class="error">' . '<p>' . __('Error: Failed to override the WP_CACHE define in wp-config.php.', 'sem-cache') . '</p>' . '</div>' . "\n"; } } if (file_exists(WP_CONTENT_DIR . '/advanced-cache.php') && !unlink(WP_CONTENT_DIR . '/advanced-cache.php')) { echo '<div class="error">' . '<p>' . sprintf(__('Error: Failed to delete %s.', 'sem-cache'), 'wp-content/advanced-cache.php') . '</p>' . '</div>' . "\n"; } # Prevent WP from serving cached pages if (!function_exists('save_mod_rewrite_rules') || !function_exists('get_home_path')) { include_once ABSPATH . 'wp-admin/includes/admin.php'; } if (!isset($GLOBALS['wp_rewrite'])) { $GLOBALS['wp_rewrite'] = new WP_Rewrite(); } # prevent mass-flushing when the permalink structure hasn't changed remove_action('generate_rewrite_rules', array('sem_cache', 'flush_cache')); global $wp_rewrite; $wp_rewrite->flush_rules(); # Flush the cache sem_cache::flush_static(); }