| 1 |
<?php |
| 2 |
|
| 3 |
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
| 4 |
|
| 5 |
if ( is_admin() ) { |
| 6 |
add_action( 'wp_ajax_dfrapi_delete_cached_api_data', 'dfrapi_delete_cached_api_data' ); |
| 7 |
} |
| 8 |
|
| 9 |
/** |
| 10 |
* Delete cached API data. |
| 11 |
*/ |
| 12 |
function dfrapi_delete_cached_api_data() { |
| 13 |
check_ajax_referer( 'dfrapi_ajax_nonce', 'dfrapi_security' ); |
| 14 |
// Only delete if user has API requests remaining. This is because we'll need to make 1 request to rebuild 'dfrapi_account'. |
| 15 |
$status = dfrapi_api_get_status(); |
| 16 |
if ( !array_key_exists( 'dfrapi_api_error', $status ) ) { |
| 17 |
delete_option( 'dfrapi_account' ); |
| 18 |
$transient_options = get_option( 'dfrapi_transient_whitelist' ); |
| 19 |
if ( !empty( $transient_options ) ) { |
| 20 |
foreach ( $transient_options as $name ) { |
| 21 |
$use_cache = wp_using_ext_object_cache( false ); |
| 22 |
delete_transient( $name ); |
| 23 |
wp_using_ext_object_cache( $use_cache ); |
| 24 |
} |
| 25 |
} |
| 26 |
// Update account status immediately in case there are not enough API |
| 27 |
// requests remaining in order to do so later. |
| 28 |
$status = dfrapi_api_get_status(); |
| 29 |
update_option( 'dfrapi_account', $status ); |
| 30 |
} |
| 31 |
_e( 'Cached API data deleted successfully.', DFRAPI_DOMAIN ); |
| 32 |
die; |
| 33 |
} |
| 34 |
|
| 35 |
|