wp_ajax_delete_post

The timeline below displays how wordpress function wp_ajax_delete_post has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.3

/**
 * Handles deleting a post via AJAX.
 *
 * @since 3.1.0
 *
 * @param string $action Action to perform.
 */
function wp_ajax_delete_post($action)
{
    if (empty($action)) {
        $action = 'delete-post';
    }
    $id = isset($_POST['id']) ? (int) $_POST['id'] : 0;
    check_ajax_referer("{$action}_{$id}");
    if (!current_user_can('delete_post', $id)) {
        wp_die(-1);
    }
    if (!get_post($id)) {
        wp_die(1);
    }
    if (wp_delete_post($id)) {
        wp_die(1);
    } else {
        wp_die(0);
    }
}

WordPress Version: 4.0

/**
 * Ajax handler for deleting a post.
 *
 * @since 3.1.0
 *
 * @param string $action Action to perform.
 */
function wp_ajax_delete_post($action)
{
    if (empty($action)) {
        $action = 'delete-post';
    }
    $id = isset($_POST['id']) ? (int) $_POST['id'] : 0;
    check_ajax_referer("{$action}_{$id}");
    if (!current_user_can('delete_post', $id)) {
        wp_die(-1);
    }
    if (!get_post($id)) {
        wp_die(1);
    }
    if (wp_delete_post($id)) {
        wp_die(1);
    } else {
        wp_die(0);
    }
}

WordPress Version: 3.7

function wp_ajax_delete_post($action)
{
    if (empty($action)) {
        $action = 'delete-post';
    }
    $id = isset($_POST['id']) ? (int) $_POST['id'] : 0;
    check_ajax_referer("{$action}_{$id}");
    if (!current_user_can('delete_post', $id)) {
        wp_die(-1);
    }
    if (!get_post($id)) {
        wp_die(1);
    }
    if (wp_delete_post($id)) {
        wp_die(1);
    } else {
        wp_die(0);
    }
}