wp_delete_comment

Advertisement

Summery Summery

Trashes or deletes a comment.

Syntax Syntax

wp_delete_comment( int|WP_Comment $comment_id, bool $force_delete = false )

Description Description

The comment is moved to Trash instead of permanently deleted unless Trash is disabled, item is already in the Trash, or $force_delete is true.

The post comment count will be updated if the comment was approved and has a post ID available.

Parameters Parameters

$comment_id

(int|WP_Comment) (Required) Comment ID or WP_Comment object.

$force_delete

(bool) (Optional) Whether to bypass Trash and force deletion. Default is false.

Default value: false

Return Return

(bool) True on success, false on failure.

Source Source

File: wp-includes/comment.php

		$pattern = "#$word#i";
		if ( preg_match( $pattern, $author )
			|| preg_match( $pattern, $email )
			|| preg_match( $pattern, $url )
			|| preg_match( $pattern, $comment )
			|| preg_match( $pattern, $comment_without_html )
			|| preg_match( $pattern, $user_ip )
			|| preg_match( $pattern, $user_agent )
		) {
			return true;
		}
	}
	return false;
}

/**
 * Retrieves the total comment counts for the whole site or a single post.
 *
 * The comment stats are cached and then retrieved, if they already exist in the
 * cache.
 *
 * @see get_comment_count() Which handles fetching the live comment counts.
 *
 * @since 2.5.0
 *
 * @param int $post_id Optional. Restrict the comment counts to the given post. Default 0, which indicates that
 *                     comment counts for the whole site will be retrieved.
 * @return stdClass {
 *     The number of comments keyed by their status.
 *
 *     @type int $approved       The number of approved comments.
 *     @type int $moderated      The number of comments awaiting moderation (a.k.a. pending).
 *     @type int $spam           The number of spam comments.
 *     @type int $trash          The number of trashed comments.
 *     @type int $post-trashed   The number of comments for posts that are in the trash.
 *     @type int $total_comments The total number of non-trashed comments, including spam.
 *     @type int $all            The total number of pending or approved comments.
 * }
 */
function wp_count_comments( $post_id = 0 ) {
	$post_id = (int) $post_id;

	/**
	 * Filters the comments count for a given post or the whole site.
	 *
	 * @since 2.7.0
	 *
	 * @param array|stdClass $count   An empty array or an object containing comment counts.
	 * @param int            $post_id The post ID. Can be 0 to represent the whole site.
	 */
	$filtered = apply_filters( 'wp_count_comments', array(), $post_id );
	if ( ! empty( $filtered ) ) {
		return $filtered;
	}

	$count = wp_cache_get( "comments-{$post_id}", 'counts' );
	if ( false !== $count ) {
		return $count;
	}

	$stats              = get_comment_count( $post_id );
	$stats['moderated'] = $stats['awaiting_moderation'];

Advertisement

Changelog Changelog

Changelog
Version Description
2.0.0 Introduced.

Advertisement

Leave a Reply

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