wp_set_comment_status()
Sets the comment status: hold, approve, spam.
After setting the status, the hook wp_set_comment_status is triggered.
The status is set in the comment_approved field of the comments table.
Possible values for this field:
0- hold1- approvespamtrash
Used By: wp_spam_comment()
Hooks from the function
Returns
true|false|WP_Error. true — the status was successfully set. false — the status could not be set.
Usage
wp_set_comment_status( $comment_id, $comment_status );
- $comment_id(integer) (required)
- ID of the comment.
- $comment_status(string) (required)
The status of the comment to be set. Can be:
- hold / 0
- approve / 1
- spam
- trash
Examples
#1 Allow a comment with ID = 9 that is on approvement
wp_set_comment_status( 9, '1' );
Put it back to the approve status:
wp_set_comment_status( 9, '0' );
#2 How do we get comment status for a post
$get_post = get_post( 123 );
$status = $get_post->comment_status;
// do something only when comments are open
if ( $status === 'open' ) {
// do ...
}
Notes
- Global. wpdb. $wpdb WordPress database abstraction object.
Changelog
| Since 1.0.0 | Introduced. |