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