WordPress开发者和主题制作者的搜索引擎



wp_ajax_delete_post ›

Since3.1.0
已弃用n/a
wp_ajax_delete_post ( $action )
参数:
  • (string) $action Action to perform.
    Required: Yes
定义在:
文档:

Ajax handler for deleting a post.



源码

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