wp_get_comment_status() WordPress Function

The wp_get_comment_status() function can be used to get the status of a comment. This is useful for checking if a comment is approved or not.

wp_get_comment_status( int|WP_Comment $comment_id ) #

Retrieves the status of a comment by comment ID.


Parameters

$comment_id

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


Top ↑

Return

(string|false) Status might be 'trash', 'approved', 'unapproved', 'spam'. False on failure.


Top ↑

Source

File: wp-includes/comment.php

function wp_get_comment_status( $comment_id ) {
	$comment = get_comment( $comment_id );
	if ( ! $comment ) {
		return false;
	}

	$approved = $comment->comment_approved;

	if ( null == $approved ) {
		return false;
	} elseif ( '1' == $approved ) {
		return 'approved';
	} elseif ( '0' == $approved ) {
		return 'unapproved';
	} elseif ( 'spam' === $approved ) {
		return 'spam';
	} elseif ( 'trash' === $approved ) {
		return 'trash';
	} else {
		return false;
	}
}


Top ↑

Changelog

Changelog
VersionDescription
1.0.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.

Show More
Show More