wp_ajax_delete_comment() - WordPress 函数参考中文文档

返回介绍

wp_ajax_delete_comment()

发布于 2017-09-11 字数2874 浏览 945 评论 0

wp_ajax_delete_comment()

Ajax handler for deleting a comment.


描述


源代码

File: wp-admin/includes/ajax-actions.php

function wp_ajax_delete_comment() {
	$id = isset( $_POST['id'] ) ? (int) $_POST['id'] : 0;

	if ( !$comment = get_comment( $id ) )
		wp_die( time() );
	if ( ! current_user_can( 'edit_comment', $comment->comment_ID ) )
		wp_die( -1 );

	check_ajax_referer( "delete-comment_$id" );
	$status = wp_get_comment_status( $comment );

	$delta = -1;
	if ( isset($_POST['trash']) && 1 == $_POST['trash'] ) {
		if ( 'trash' == $status )
			wp_die( time() );
		$r = wp_trash_comment( $comment );
	} elseif ( isset($_POST['untrash']) && 1 == $_POST['untrash'] ) {
		if ( 'trash' != $status )
			wp_die( time() );
		$r = wp_untrash_comment( $comment );
		if ( ! isset( $_POST['comment_status'] ) || $_POST['comment_status'] != 'trash' ) // undo trash, not in trash
			$delta = 1;
	} elseif ( isset($_POST['spam']) && 1 == $_POST['spam'] ) {
		if ( 'spam' == $status )
			wp_die( time() );
		$r = wp_spam_comment( $comment );
	} elseif ( isset($_POST['unspam']) && 1 == $_POST['unspam'] ) {
		if ( 'spam' != $status )
			wp_die( time() );
		$r = wp_unspam_comment( $comment );
		if ( ! isset( $_POST['comment_status'] ) || $_POST['comment_status'] != 'spam' ) // undo spam, not in spam
			$delta = 1;
	} elseif ( isset($_POST['delete']) && 1 == $_POST['delete'] ) {
		$r = wp_delete_comment( $comment );
	} else {
		wp_die( -1 );
	}

	if ( $r ) // Decide if we need to send back '1' or a more complicated response including page links and comment counts
		_wp_ajax_delete_comment_response( $comment->comment_ID, $delta );
	wp_die( 0 );
}

更新日志

Version 描述
3.1.0 Introduced.

相关函数

Uses

  • wp-admin/includes/ajax-actions.php:
    _wp_ajax_delete_comment_response()
  • wp-includes/capabilities.php:
    current_user_can()
  • wp-includes/pluggable.php:
    check_ajax_referer()
  • wp-includes/functions.php:
    wp_die()
  • wp-includes/comment.php:
    wp_get_comment_status()
  • wp-includes/comment.php:
    wp_spam_comment()
  • wp-includes/comment.php:
    wp_unspam_comment()
  • wp-includes/comment.php:
    wp_trash_comment()
  • wp-includes/comment.php:
    wp_untrash_comment()
  • wp-includes/comment.php:
    wp_delete_comment()
  • wp-includes/comment.php:
    get_comment()
  • Show 6 more uses
    Hide more uses


User Contributed Notes

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

目前还没有任何评论,快来抢沙发吧!