wp_set_comment_status

Advertisement

Summery Summery

Sets the status of a comment.

Syntax Syntax

wp_set_comment_status( int|WP_Comment $comment_id, string $comment_status, bool $wp_error = false )

Description Description

The ‘wp_set_comment_status’ action is called after the comment is handled. If the comment status is not in the list, then false is returned.

Parameters Parameters

$comment_id

(Required) Comment ID or WP_Comment object.

$comment_status

(Required) New comment status, either 'hold', 'approve', 'spam', or 'trash'.

$wp_error

(Optional) Whether to return a WP_Error object if there is a failure. Default is false.

Default value: false

Return Return

(bool|WP_Error) True on success, false or WP_Error on failure.

Source Source

File: wp-includes/comment.php

		$commentdata = wp_filter_comment( $commentdata );

		$commentdata['comment_approved'] = wp_allow_comment( $commentdata, $wp_error );
		if ( is_wp_error( $commentdata['comment_approved'] ) ) {
			return $commentdata['comment_approved'];
		}

		$comment_ID = wp_insert_comment( $commentdata );
		if ( ! $comment_ID ) {
			return false;
		}
	}

	/**
	 * Fires immediately after a comment is inserted into the database.
	 *
	 * @since 1.2.0
	 * @since 4.5.0 The `$commentdata` parameter was added.
	 *
	 * @param int        $comment_ID       The comment ID.
	 * @param int|string $comment_approved 1 if the comment is approved, 0 if not, 'spam' if spam.
	 * @param array      $commentdata      Comment data.
	 */
	do_action( 'comment_post', $comment_ID, $commentdata['comment_approved'], $commentdata );

	return $comment_ID;
}

/**
 * Send a comment moderation notification to the comment moderator.
 *
 * @since 4.4.0
 *
 * @param int $comment_ID ID of the comment.
 * @return bool True on success, false on failure.
 */
function wp_new_comment_notify_moderator( $comment_ID ) {
	$comment = get_comment( $comment_ID );

	// Only send notifications for pending comments.
	$maybe_notify = ( '0' == $comment->comment_approved );

	/** This filter is documented in wp-includes/comment.php */
	$maybe_notify = apply_filters( 'notify_moderator', $maybe_notify, $comment_ID );

	if ( ! $maybe_notify ) {
		return false;
	}

	return wp_notify_moderator( $comment_ID );
}

/**
 * Send a notification of a new comment to the post author.

Advertisement

Changelog Changelog

Changelog
Version Description
1.0.0 Introduced.

Advertisement

Leave a Reply