swte

Clear user cache shortcode

Mar 19th, 2021 (edited)
314
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.70 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Plugin Name: Swift Performance Tweaks
  4.  */
  5.  
  6.  
  7. add_shortcode('swift_clear_user_cache', function(){
  8.     $current_page = site_url(str_replace(home_url(), '', 'http'.(isset($_SERVER['HTTPS']) ? 's' : '') . '://' . Swift_Performance::$http_host . $_SERVER['REQUEST_URI']));
  9.     return '<a href="' . wp_nonce_url($current_page, 'swift-clear-user-cache', 'swift-clear-user-cache') . '">Clear user cache</a>';
  10. });
  11.  
  12. add_action('init', function(){
  13.     if (isset($_REQUEST['swift-clear-user-cache']) && wp_verify_nonce($_REQUEST['swift-clear-user-cache'], 'swift-clear-user-cache') && class_exists('Swift_Performance_Cache')){
  14.         Swift_Performance_Cache::clear_user_cache(get_current_user_id());
  15.     }
  16. });
  17.  
  18. ?>
Add Comment
Please, Sign In to add comment