Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_action('admin_bar_menu', function ($admin_bar){
- if (current_user_can('edit_posts')){
- $current_page = site_url(str_replace(site_url(), '', 'http'.(isset($_SERVER['HTTPS']) ? 's' : '') . '://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']));
- list($current_page_nq,) = explode('?',$current_page);
- $admin_bar->add_menu(array(
- 'id' => 'swift-performance',
- 'title' => SWIFT_PERFORMANCE_PLUGIN_NAME,
- 'href' => '#'
- ));
- if(Swift_Performance::check_option('enable-caching', 1)){
- $admin_bar->add_menu(array(
- 'id' => 'clear-swift-cache',
- 'parent' => 'swift-performance',
- 'title' => esc_html__('Clear All Cache', 'swift-performance'),
- 'href' => esc_url(wp_nonce_url(add_query_arg('swift-performance-action', 'clear-all-cache', $current_page), 'clear-swift-cache')),
- ));
- if (!is_admin() && Swift_Performance_Cache::is_cached($current_page_nq)){
- $admin_bar->add_menu(array(
- 'id' => 'swift-cache-single',
- 'parent' => 'swift-performance',
- 'title' => esc_html__('Clear Page Cache', 'swift-performance'),
- 'href' => esc_url(wp_nonce_url(add_query_arg(array('swift-performance-action' => 'clear-page-cache', 'permalink' => urlencode($current_page_nq)), $current_page), 'clear-swift-cache')),
- ));
- $admin_bar->add_menu(array(
- 'id' => 'swift-view-cached',
- 'parent' => 'swift-performance',
- 'title' => esc_html__('View Cached', 'swift-performance'),
- 'href' => esc_url(add_query_arg('force-cached', '1', $current_page_nq)),
- ));
- }
- }
- if(Swift_Performance::check_option('enable-caching', 1, '!=') && (Swift_Performance::check_option('merge-scripts', 1) || Swift_Performance::check_option('merge-styles', 1))){
- $admin_bar->add_menu(array(
- 'id' => 'clear-swift-assets-cache',
- 'parent' => 'swift-performance',
- 'title' => esc_html__('Clear Assets Cache', 'swift-performance'),
- 'href' => esc_url(wp_nonce_url(add_query_arg('swift-performance-action', 'clear-assets-cache', $current_page), 'clear-swift-assets-cache')),
- ));
- }
- if (Swift_Performance::check_option('enable-cdn',1) && Swift_Performance::check_option('maxcdn-key','','!=') && Swift_Performance::check_option('maxcdn-secret','','!=')){
- $admin_bar->add_menu(array(
- 'id' => 'purge-swift-cdn',
- 'parent' => 'swift-performance',
- 'title' => esc_html__('Purge CDN (All zones)', 'swift-performance'),
- 'href' => esc_url(wp_nonce_url(add_query_arg('swift-performance-action', 'purge-cdn', $current_page), 'purge-swift-cdn')),
- ));
- }
- }
- },100);
- // Clear caches
- add_action('init', function(){
- if (!isset($_GET['swift-performance-action'])){
- return;
- }
- if ($_GET['swift-performance-action'] == 'clear-all-cache' && current_user_can('edit_posts') && isset($_GET['_wpnonce']) && wp_verify_nonce($_GET['_wpnonce'], 'clear-swift-cache')){
- Swift_Performance_Cache::clear_all_cache();
- Swift_Performance::add_notice(esc_html__('All cache cleared', 'swift-performance'), 'success');
- }
- if ($_GET['swift-performance-action'] == 'clear-assets-cache' && current_user_can('edit_posts') && isset($_GET['_wpnonce']) && wp_verify_nonce($_GET['_wpnonce'], 'clear-swift-assets-cache')){
- Swift_Performance_Asset_Manager::clear_assets_cache();
- Swift_Performance::add_notice(esc_html__('Assets cache cleared', 'swift-performance'), 'success');
- }
- if ($_GET['swift-performance-action'] == 'purge-cdn' && current_user_can('edit_posts') && isset($_GET['_wpnonce']) && wp_verify_nonce($_GET['_wpnonce'], 'purge-swift-cdn')){
- if (Swift_Performance::check_option('enable-caching', 1)){
- Swift_Performance_Cache::clear_all_cache();
- }
- else if (Swift_Performance::check_option('merge-scripts',1) || Swift_Performance::check_option('merge-styles',1)){
- Swift_Performance_Asset_Manager::clear_assets_cache();
- }
- else {
- Swift_Performance_CDN_Manager::purge_cdn();
- }
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement