检索发布的删除帖子链接。

原型

get_delete_post_link( int|WP_Post $id, string $deprecated = '', bool $force_delete = false )

描述

可以在WordPress循环中使用,也可以在任何帖子类型之外使用。

参数

$id (int|WP_Post) (Optional)  帖子ID或帖子对象。默认是全球$ post。

$deprecated (string) (Optional) 不曾用过。

$force_delete (bool) (Optional)  是否绕过垃圾并强行删除。

返回值

(string|void)  给定帖子的删除帖子链接URL。

源文件

路径:wp-includes/link-template.php

<?php
...
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 );
}
...
?>

其他

英文文档:https://developer.wordpress.org/reference/functions/get_delete_post_link/