Skip to content

Instantly share code, notes, and snippets.

@kodie
Created December 20, 2019 20:00
Show Gist options
  • Save kodie/eaaab2014ffc2cf2077e67370f67f2ae to your computer and use it in GitHub Desktop.
Save kodie/eaaab2014ffc2cf2077e67370f67f2ae to your computer and use it in GitHub Desktop.
A function that allows you to clear all transients either by running the function, calling it via AJAX, or by calling it via CURL
<?php
// Clears all transients, can be ran via the function, via AJAX or by manually running:
// curl -d "action=hm_clear_transients" https://website.com/wordpress/wp-admin/admin-ajax.php
add_action('wp_ajax_hm_clear_transients', 'hm_clear_transients');
add_action('wp_ajax_nopriv_hm_clear_transients', 'hm_clear_transients');
function hm_clear_transients() {
global $wpdb;
$rows = $wpdb->query("DELETE FROM $wpdb->options WHERE option_name LIKE '%_transient_%'");
if (wp_doing_ajax()) wp_send_json_success($rows);
return $rows;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment