示例#1
0
/**
 * Delete the CRP cache.
 *
 * @param	array $meta_keys
 */
function crp_cache_delete($meta_keys = array())
{
    $default_meta_keys = crp_cache_get_keys();
    if (!empty($meta_keys)) {
        $meta_keys = array_intersect($default_meta_keys, (array) $meta_keys);
    } else {
        $meta_keys = $default_meta_keys;
    }
    foreach ($meta_keys as $meta_key) {
        delete_post_meta_by_key($meta_key);
    }
}
示例#2
0
/**
 * Function to clear the CRP Cache with Ajax.
 *
 * @since	1.8.10
 */
function crp_ajax_clearcache()
{
    global $wpdb;
    $meta_keys = crp_cache_get_keys();
    $error = false;
    foreach ($meta_keys as $meta_key) {
        $count = $wpdb->query($wpdb->prepare("\n\t\t\tDELETE FROM {$wpdb->postmeta}\n\t\t\tWHERE meta_key = %s\n\t\t", $meta_key));
        if (false === $count) {
            $error = true;
        } else {
            $counter[] = $count;
        }
    }
    /**** Did an error occur? ****/
    if ($error) {
        exit(json_encode(array('success' => 0, 'message' => __('An error occurred clearing the cache. Please contact your site administrator.\\n\\nError message:\\n', 'contextual-related-posts') . $wpdb->print_error())));
    } else {
        // No error, return the number of
        exit(json_encode(array('success' => 1, 'message' => array_sum($counter) . __(' cached row(s) cleared', 'contextual-related-posts'))));
    }
}