Guest User

Untitled

a guest
May 2nd, 2021
72
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. if( defined('DOING_AJAX') && DOING_AJAX && strcasecmp($_SERVER['REQUEST_METHOD'], "POST") == 0 && !empty($_POST['action']) && $_POST['action'] == "{your_action}") {
  2.     $ajax_cache_path = WP_CONTENT_DIR . "/custom-cache/{$_SERVER['HTTP_HOST']}/cache_ajax/";
  3.     $cache_key = ajax_cache_key(); //Generates a unique filename with sha1 based on information from the POST request (GET information is always the same in this case)
  4.  
  5.     if( file_exists($ajax_cache_path . $cache_key) ) {
  6.         header('content-type: application/json; charset=UTF-8');
  7.         header('AJAX-Cache: HIT');
  8.         die( file_get_contents($ajax_cache_path . $cache_key));
  9.     }
  10.  
  11.     ob_start( 'ajax_cache_end' );
  12. }
RAW Paste Data