WP_REST_Comments_Controller::handle_status_param()
Sets the comment_status of a given comment object when creating or updating a comment.
Method of the class: WP_REST_Comments_Controller{}
No Hooks.
Return
true|false
. Whether the status was changed.
Usage
// protected - for code of main (parent) or child class $result = $this->handle_status_param( $new_status, $comment_id );
- $new_status(string|int) (required)
- New comment status.
- $comment_id(int) (required)
- Comment ID.
Changelog
Since 4.7.0 | Introduced. |
WP_REST_Comments_Controller::handle_status_param() WP REST Comments Controller::handle status param code WP 6.7.1
protected function handle_status_param( $new_status, $comment_id ) { $old_status = wp_get_comment_status( $comment_id ); if ( $new_status === $old_status ) { return false; } switch ( $new_status ) { case 'approved': case 'approve': case '1': $changed = wp_set_comment_status( $comment_id, 'approve' ); break; case 'hold': case '0': $changed = wp_set_comment_status( $comment_id, 'hold' ); break; case 'spam': $changed = wp_spam_comment( $comment_id ); break; case 'unspam': $changed = wp_unspam_comment( $comment_id ); break; case 'trash': $changed = wp_trash_comment( $comment_id ); break; case 'untrash': $changed = wp_untrash_comment( $comment_id ); break; default: $changed = false; break; } return $changed; }