get_delete_post_link

函数
get_delete_post_link ( $post = 0, $deprecated = '', $force_delete = false )
参数
  • (int|WP_Post) $post Optional. Post ID or post object. Default is the global `$post`.
    Required:
  • (string) $deprecated Not used.
    Required:
    Default: (empty)
  • (bool) $force_delete Optional. Whether to bypass Trash and force deletion. Default false.
    Required:
    Default: false
返回值
  • (string|void) The delete post link URL for the given post.
定义位置
相关方法
get_next_post_linkget_edit_post_linkget_next_posts_linkget_adjacent_post_linkget_preview_post_link
引入
2.9.0
弃用
-

get_delete_post_link: 这个函数返回给定文章ID的”删除文章”操作的URL。它可以用来创建链接或按钮,从网站的前端删除文章。

检索文章的删除链接。

可以在WordPress循环内或循环外使用,适用于任何文章类型。

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 );
}

常见问题

FAQs
查看更多 >