On this page
WP_REST_Comments_Controller::handle_status_param( string|int $new_status, int $comment_id ): bool
Sets the comment_status of a given comment object when creating or updating a comment.
Parameters
$new_statusstring|int Required-
New comment status.
$comment_idint Required-
Comment ID.
Return
bool Whether the status was changed.
Source
File: wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php. View all references
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;
}
Related
Uses
| Uses | Description |
|---|---|
| wp_set_comment_status() wp-includes/comment.php | Sets the status of a comment. |
| wp_get_comment_status() wp-includes/comment.php | Retrieves the status of a comment by comment ID. |
| wp_spam_comment() wp-includes/comment.php | Marks a comment as Spam. |
| wp_unspam_comment() wp-includes/comment.php | Removes a comment from the Spam. |
| wp_trash_comment() wp-includes/comment.php | Moves a comment to the Trash |
| wp_untrash_comment() wp-includes/comment.php | Removes a comment from the Trash |
Used By
| Used By | Description |
|---|---|
| WP_REST_Comments_Controller::update_item() wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php | Updates a comment. |
| WP_REST_Comments_Controller::create_item() wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php | Creates a comment. |
Changelog
| Version | Description |
|---|---|
| 4.7.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/classes/wp_rest_comments_controller/handle_status_param