get_delete_post_link

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

WordPress Version: 6.1

/**
 * Retrieves the delete posts link for post.
 *
 * Can be used within the WordPress loop or outside of it, with any post type.
 *
 * @since 2.9.0
 *
 * @param int|WP_Post $post         Optional. Post ID or post object. Default is the global `$post`.
 * @param string      $deprecated   Not used.
 * @param bool        $force_delete Optional. Whether to bypass Trash and force deletion. Default false.
 * @return string|void The delete post link URL for the given post.
 */
function get_delete_post_link($post = 0, $deprecated = '', $force_delete = false)
{
    if (!empty($deprecated)) {
        _deprecated_argument(__FUNCTION__, '3.0.0');
    }
    $post = get_post($post);
    if (!$post) {
        return;
    }
    $post_type_object = get_post_type_object($post->post_type);
    if (!$post_type_object) {
        return;
    }
    if (!current_user_can('delete_post', $post->ID)) {
        return;
    }
    $action = ($force_delete || !EMPTY_TRASH_DAYS) ? 'delete' : 'trash';
    $delete_link = add_query_arg('action', $action, admin_url(sprintf($post_type_object->_edit_link, $post->ID)));
    /**
     * Filters the post delete link.
     *
     * @since 2.9.0
     *
     * @param string $link         The delete link.
     * @param int    $post_id      Post ID.
     * @param bool   $force_delete Whether to bypass the Trash and force deletion. Default false.
     */
    return apply_filters('get_delete_post_link', wp_nonce_url($delete_link, "{$action}-post_{$post->ID}"), $post->ID, $force_delete);
}

WordPress Version: 5.4

/**
 * Retrieves the delete posts link for post.
 *
 * Can be used within the WordPress loop or outside of it, with any post type.
 *
 * @since 2.9.0
 *
 * @param int|WP_Post $id           Optional. Post ID or post object. Default is the global `$post`.
 * @param string      $deprecated   Not used.
 * @param bool        $force_delete Optional. Whether to bypass Trash and force deletion. Default false.
 * @return string|void The delete post link URL for the given post.
 */
function get_delete_post_link($id = 0, $deprecated = '', $force_delete = false)
{
    if (!empty($deprecated)) {
        _deprecated_argument(__FUNCTION__, '3.0.0');
    }
    $post = get_post($id);
    if (!$post) {
        return;
    }
    $post_type_object = get_post_type_object($post->post_type);
    if (!$post_type_object) {
        return;
    }
    if (!current_user_can('delete_post', $post->ID)) {
        return;
    }
    $action = ($force_delete || !EMPTY_TRASH_DAYS) ? 'delete' : 'trash';
    $delete_link = add_query_arg('action', $action, admin_url(sprintf($post_type_object->_edit_link, $post->ID)));
    /**
     * Filters the post delete link.
     *
     * @since 2.9.0
     *
     * @param string $link         The delete link.
     * @param int    $post_id      Post ID.
     * @param bool   $force_delete Whether to bypass the Trash and force deletion. Default false.
     */
    return apply_filters('get_delete_post_link', wp_nonce_url($delete_link, "{$action}-post_{$post->ID}"), $post->ID, $force_delete);
}

WordPress Version: 5.3

/**
 * Retrieves the delete posts link for post.
 *
 * Can be used within the WordPress loop or outside of it, with any post type.
 *
 * @since 2.9.0
 *
 * @param int|WP_Post $id           Optional. Post ID or post object. Default is the global `$post`.
 * @param string      $deprecated   Not used.
 * @param bool        $force_delete Optional. Whether to bypass trash and force deletion. Default false.
 * @return string|void The delete post link URL for the given post.
 */
function get_delete_post_link($id = 0, $deprecated = '', $force_delete = false)
{
    if (!empty($deprecated)) {
        _deprecated_argument(__FUNCTION__, '3.0.0');
    }
    $post = get_post($id);
    if (!$post) {
        return;
    }
    $post_type_object = get_post_type_object($post->post_type);
    if (!$post_type_object) {
        return;
    }
    if (!current_user_can('delete_post', $post->ID)) {
        return;
    }
    $action = ($force_delete || !EMPTY_TRASH_DAYS) ? 'delete' : 'trash';
    $delete_link = add_query_arg('action', $action, admin_url(sprintf($post_type_object->_edit_link, $post->ID)));
    /**
     * Filters the post delete link.
     *
     * @since 2.9.0
     *
     * @param string $link         The delete link.
     * @param int    $post_id      Post ID.
     * @param bool   $force_delete Whether to bypass the trash and force deletion. Default false.
     */
    return apply_filters('get_delete_post_link', wp_nonce_url($delete_link, "{$action}-post_{$post->ID}"), $post->ID, $force_delete);
}

WordPress Version: 4.9

/**
 * Retrieves the delete posts link for post.
 *
 * Can be used within the WordPress loop or outside of it, with any post type.
 *
 * @since 2.9.0
 *
 * @param int|WP_Post $id           Optional. Post ID or post object. Default is the global `$post`.
 * @param string      $deprecated   Not used.
 * @param bool        $force_delete Optional. Whether to bypass trash and force deletion. Default false.
 * @return string|void The delete post link URL for the given post.
 */
function get_delete_post_link($id = 0, $deprecated = '', $force_delete = false)
{
    if (!empty($deprecated)) {
        _deprecated_argument(__FUNCTION__, '3.0.0');
    }
    if (!$post = get_post($id)) {
        return;
    }
    $post_type_object = get_post_type_object($post->post_type);
    if (!$post_type_object) {
        return;
    }
    if (!current_user_can('delete_post', $post->ID)) {
        return;
    }
    $action = ($force_delete || !EMPTY_TRASH_DAYS) ? 'delete' : 'trash';
    $delete_link = add_query_arg('action', $action, admin_url(sprintf($post_type_object->_edit_link, $post->ID)));
    /**
     * Filters the post delete link.
     *
     * @since 2.9.0
     *
     * @param string $link         The delete link.
     * @param int    $post_id      Post ID.
     * @param bool   $force_delete Whether to bypass the trash and force deletion. Default false.
     */
    return apply_filters('get_delete_post_link', wp_nonce_url($delete_link, "{$action}-post_{$post->ID}"), $post->ID, $force_delete);
}

WordPress Version: 4.6

/**
 * Retrieves the delete posts link for post.
 *
 * Can be used within the WordPress loop or outside of it, with any post type.
 *
 * @since 2.9.0
 *
 * @param int    $id           Optional. Post ID. Default is the ID of the global `$post`.
 * @param string $deprecated   Not used.
 * @param bool   $force_delete Optional. Whether to bypass trash and force deletion. Default false.
 * @return string|void The delete post link URL for the given post.
 */
function get_delete_post_link($id = 0, $deprecated = '', $force_delete = false)
{
    if (!empty($deprecated)) {
        _deprecated_argument(__FUNCTION__, '3.0.0');
    }
    if (!$post = get_post($id)) {
        return;
    }
    $post_type_object = get_post_type_object($post->post_type);
    if (!$post_type_object) {
        return;
    }
    if (!current_user_can('delete_post', $post->ID)) {
        return;
    }
    $action = ($force_delete || !EMPTY_TRASH_DAYS) ? 'delete' : 'trash';
    $delete_link = add_query_arg('action', $action, admin_url(sprintf($post_type_object->_edit_link, $post->ID)));
    /**
     * Filters the post delete link.
     *
     * @since 2.9.0
     *
     * @param string $link         The delete link.
     * @param int    $post_id      Post ID.
     * @param bool   $force_delete Whether to bypass the trash and force deletion. Default false.
     */
    return apply_filters('get_delete_post_link', wp_nonce_url($delete_link, "{$action}-post_{$post->ID}"), $post->ID, $force_delete);
}

WordPress Version: 4.3

/**
 * Retrieve delete posts link for post.
 *
 * Can be used within the WordPress loop or outside of it, with any post type.
 *
 * @since 2.9.0
 *
 * @param int    $id           Optional. Post ID.
 * @param string $deprecated   Not used.
 * @param bool   $force_delete Whether to bypass trash and force deletion. Default is false.
 * @return string|void The delete post link URL for the given post.
 */
function get_delete_post_link($id = 0, $deprecated = '', $force_delete = false)
{
    if (!empty($deprecated)) {
        _deprecated_argument(__FUNCTION__, '3.0');
    }
    if (!$post = get_post($id)) {
        return;
    }
    $post_type_object = get_post_type_object($post->post_type);
    if (!$post_type_object) {
        return;
    }
    if (!current_user_can('delete_post', $post->ID)) {
        return;
    }
    $action = ($force_delete || !EMPTY_TRASH_DAYS) ? 'delete' : 'trash';
    $delete_link = add_query_arg('action', $action, admin_url(sprintf($post_type_object->_edit_link, $post->ID)));
    /**
     * Filter the post delete link.
     *
     * @since 2.9.0
     *
     * @param string $link         The delete link.
     * @param int    $post_id      Post ID.
     * @param bool   $force_delete Whether to bypass the trash and force deletion. Default false.
     */
    return apply_filters('get_delete_post_link', wp_nonce_url($delete_link, "{$action}-post_{$post->ID}"), $post->ID, $force_delete);
}

WordPress Version: 4.1

/**
 * Retrieve delete posts link for post.
 *
 * Can be used within the WordPress loop or outside of it, with any post type.
 *
 * @since 2.9.0
 *
 * @param int $id Optional. Post ID.
 * @param string $deprecated Not used.
 * @param bool $force_delete Whether to bypass trash and force deletion. Default is false.
 * @return string The delete post link URL for the given post.
 */
function get_delete_post_link($id = 0, $deprecated = '', $force_delete = false)
{
    if (!empty($deprecated)) {
        _deprecated_argument(__FUNCTION__, '3.0');
    }
    if (!$post = get_post($id)) {
        return;
    }
    $post_type_object = get_post_type_object($post->post_type);
    if (!$post_type_object) {
        return;
    }
    if (!current_user_can('delete_post', $post->ID)) {
        return;
    }
    $action = ($force_delete || !EMPTY_TRASH_DAYS) ? 'delete' : 'trash';
    $delete_link = add_query_arg('action', $action, admin_url(sprintf($post_type_object->_edit_link, $post->ID)));
    /**
     * Filter the post delete link.
     *
     * @since 2.9.0
     *
     * @param string $link         The delete link.
     * @param int    $post_id      Post ID.
     * @param bool   $force_delete Whether to bypass the trash and force deletion. Default false.
     */
    return apply_filters('get_delete_post_link', wp_nonce_url($delete_link, "{$action}-post_{$post->ID}"), $post->ID, $force_delete);
}

WordPress Version: 3.9

/**
 * Retrieve delete posts link for post.
 *
 * Can be used within the WordPress loop or outside of it, with any post type.
 *
 * @since 2.9.0
 *
 * @param int $id Optional. Post ID.
 * @param string $deprecated Not used.
 * @param bool $force_delete Whether to bypass trash and force deletion. Default is false.
 * @return string
 */
function get_delete_post_link($id = 0, $deprecated = '', $force_delete = false)
{
    if (!empty($deprecated)) {
        _deprecated_argument(__FUNCTION__, '3.0');
    }
    if (!$post = get_post($id)) {
        return;
    }
    $post_type_object = get_post_type_object($post->post_type);
    if (!$post_type_object) {
        return;
    }
    if (!current_user_can('delete_post', $post->ID)) {
        return;
    }
    $action = ($force_delete || !EMPTY_TRASH_DAYS) ? 'delete' : 'trash';
    $delete_link = add_query_arg('action', $action, admin_url(sprintf($post_type_object->_edit_link, $post->ID)));
    /**
     * Filter the post delete link.
     *
     * @since 2.9.0
     *
     * @param string $link         The delete link.
     * @param int    $post_id      Post ID.
     * @param bool   $force_delete Whether to bypass the trash and force deletion. Default false.
     */
    return apply_filters('get_delete_post_link', wp_nonce_url($delete_link, "{$action}-post_{$post->ID}"), $post->ID, $force_delete);
}

WordPress Version: 3.7

/**
 * Retrieve delete posts link for post.
 *
 * Can be used within the WordPress loop or outside of it, with any post type.
 *
 * @since 2.9.0
 *
 * @param int $id Optional. Post ID.
 * @param string $deprecated Not used.
 * @param bool $force_delete Whether to bypass trash and force deletion. Default is false.
 * @return string
 */
function get_delete_post_link($id = 0, $deprecated = '', $force_delete = false)
{
    if (!empty($deprecated)) {
        _deprecated_argument(__FUNCTION__, '3.0');
    }
    if (!$post = get_post($id)) {
        return;
    }
    $post_type_object = get_post_type_object($post->post_type);
    if (!$post_type_object) {
        return;
    }
    if (!current_user_can('delete_post', $post->ID)) {
        return;
    }
    $action = ($force_delete || !EMPTY_TRASH_DAYS) ? 'delete' : 'trash';
    $delete_link = add_query_arg('action', $action, admin_url(sprintf($post_type_object->_edit_link, $post->ID)));
    return apply_filters('get_delete_post_link', wp_nonce_url($delete_link, "{$action}-post_{$post->ID}"), $post->ID, $force_delete);
}