function delete()
 {
     global $wpdb;
     // extract
     extract($_POST);
     // get file name
     $filename = $wpdb->get_var($wpdb->prepare("SELECT `filename` FROM `" . TBL_MGM_DOWNLOAD . "` WHERE id = %d", $id));
     // check s3
     if (!mgm_is_s3_file($filename)) {
         // delete file if locally stored
         mgm_delete_file(MGM_FILES_DOWNLOAD_DIR . basename($filename));
     }
     // delete
     $wpdb->query($wpdb->prepare('DELETE FROM `' . TBL_MGM_DOWNLOAD . '`	WHERE id = %d', $id));
     $wpdb->query($wpdb->prepare('DELETE FROM `' . TBL_MGM_DOWNLOAD_POST_ASSOC . '` WHERE `download_id` = %d', $id));
     $wpdb->query($wpdb->prepare('DELETE FROM `' . TBL_MGM_DOWNLOAD_LIMIT_ASSOC . '` WHERE `download_id` = %d', $id));
     // return response
     echo json_encode(array('status' => 'success', 'message' => __('Download deleted successfully', 'mgm')));
     exit;
 }
/**
 * get abs path
 */
function mgm_get_abs_file($fileurl)
{
    // check s3 file
    if (mgm_is_s3_file($fileurl)) {
        return $fileurl = mgm_download_s3file($fileurl);
    }
    // return
    return str_replace(trailingslashit(get_option('siteurl')), str_replace('\\', '/', ABSPATH), $fileurl);
}