wp_set_comment_status()
Sets the status of a comment.
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.
Used By: wp_spam_comment()
Hooks from the function
Return
true|false|WP_Error
. True on success, false or WP_Error on failure.
Usage
wp_set_comment_status( $comment_id, $comment_status, $wp_error );
- $comment_id(int|WP_Comment) (required)
- Comment ID or WP_Comment object.
- $comment_status(string) (required)
- New comment status, either 'hold', 'approve', 'spam', or 'trash'.
- $wp_error(true|false)
- Whether to return a WP_Error object if there is a failure.
Default: false
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. |