目录
描述
Returns URL to move a post to the trash as string value.
Can be used within the WordPress loop or outside of it. Can be used with pages, posts, attachments, and revisions.
用法
<?php echo get_delete_post_link( $id ); ?>
参数
id
(integer) (可选) The post ID
默认值: None
deprecated
(string) (可选) Not used.
默认值:
force_delete
(bool) (可选) Whether to bypass trash and force deletion.
默认值: false
源文件
get_delete_post_link() 函数的代码位于 wp-includes/link-template.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
/* ---------------------------------- * wordpress之魂 © http://wphun.com * ---------------------------------- */ /** * 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 ); } |
- 原文:http://codex.wordpress.org/Function_Reference/get_delete_post_link
- 翻译:黄聪@WordPress之魂