Comment_Delete::logged_in()

Description #

Handle ajax for logged in users.

Source #

File: ajax/comment-delete.php

	public function logged_in() {
		$comment_id = $this->req( 'comment_id' );
		$_comment   = get_comment( $comment_id );

		// Check if deleting comment is locked.
		if ( ap_comment_delete_locked( $_comment->comment_ID ) && ! is_super_admin() ) {
			$this->set_fail();

			$this->snackbar(
				sprintf(
					// Translators: %s contain comment created date. i.e. 10 hours.
					__( 'The comment is locked and cannot be deleted. Any comments posted before %s cannot be deleted.', 'anspress-question-answer' ),
					human_time_diff( ap_get_current_timestamp() + ap_opt( 'disable_delete_after' ) )
				)
			);

			$this->send();
		}

		$delete = wp_delete_comment( (int) $_comment->comment_ID, true );

		if ( $delete ) {
			do_action( 'ap_unpublish_comment', $_comment );
			do_action( 'ap_after_deleting_comment', $_comment );

			$count = get_comment_count( $_comment->comment_post_ID );

			$this->set_success();
			$this->snackbar( __( 'Comment successfully deleted', 'anspress-question-answer' ) );
			$this->add_res( 'cb', 'commentDeleted' );
			$this->add_res( 'post_ID', $_comment->comment_post_ID );
			$this->add_res(
				'commentsCount',
				array(
					'text'       => sprintf(
						// Translators: %d contain comment count.
						_n( '%d Comment', '%d Comments', $count['all'], 'anspress-question-answer' ),
						$count['all']
					),
					'number'     => $count['all'],
					'unapproved' => $count['awaiting_moderation'],
				)
			);
		}
	}

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Add your comment