Definition:
function wp_set_comment_status($comment_id, $comment_status, $wp_error = false) {}
Sets the status of a comment.
The ‘wp_set_comment_status’ action is called after the comment is handled and will only be called, if the comment status is either ‘hold’, ‘approve’, or ‘spam’. If the comment status is not in the list, then false is returned and if the status is ‘delete’, then the comment is deleted without calling the action.
Parameters
- int $comment_id: Comment ID.
- string $comment_status: New comment status, either ‘hold’, ‘approve’, ‘spam’, or ‘delete’.
- bool $wp_error: Whether to return a WP_Error object if there is a failure. Default is false.
Return values
returns:False on failure or deletion and true on success.
Defined actions
- wp_set_comment_status
do_action('wp_set_comment_status', $comment_id, $comment_status);
Source code
function wp_set_comment_status($comment_id, $comment_status, $wp_error = false) { global $wpdb; $status = '0'; switch ( $comment_status ) { case 'hold': case '0': $status = '0'; break; case 'approve': case '1': $status = '1'; if ( get_option('comments_notify') ) { $comment = get_comment($comment_id); wp_notify_postauthor($comment_id, $comment->comment_type); } break; case 'spam': $status = 'spam'; break; case 'trash': $status = 'trash'; break; default: return false; } $comment_old = clone get_comment($comment_id); if ( !$wpdb->update( $wpdb->comments, array('comment_approved' => $status), array('comment_ID' => $comment_id) ) ) { if ( $wp_error ) return new WP_Error('db_update_error', __('Could not update comment status'), $wpdb->last_error); else return false; } clean_comment_cache($comment_id); $comment = get_comment($comment_id); do_action('wp_set_comment_status', $comment_id, $comment_status); wp_transition_comment_status($comment_status, $comment_old->comment_approved, $comment); wp_update_comment_count($comment->comment_post_ID); return true; }
4101
No comments yet... Be the first to leave a reply!