Automattic\WooCommerce\Internal\OrderReviews
SubmissionHandler::update_review_in_place
Update a review row in place: re-moderate changed content, write the rating, and move the row to the resulting status. Shared by the normal edit path and by resubmitting after an automatic rejection, so a rejected row is corrected rather than a new one stored.
Method of the class: SubmissionHandler{}
No Hooks.
Returns
array{comment_id?:int, status?:string, error?:string}.
Usage
$result = SubmissionHandler::update_review_in_place( $existing, $content, $rating, $ip, $agent ): array;
- $existing(WP_Comment) (required)
- The review being updated.
- $content(string) (required)
- The new content (already run through comment kses).
- $rating(int) (required)
- Rating value 1-5.
- $ip(string) (required)
- Comment author IP.
- $agent(string) (required)
- Comment author user agent.
SubmissionHandler::update_review_in_place() SubmissionHandler::update review in place code WC 11.1.2
private static function update_review_in_place( \WP_Comment $existing, string $content, int $rating, string $ip, string $agent ): array {
$existing_id = (int) $existing->comment_ID;
// Compare against the stored content run back through comment kses so that
// filters core adds on save (e.g. rel="nofollow ugc" on links) don't read
// as a content change. Only re-moderate when the text actually changed; a
// rating-only edit keeps the row's current moderation state.
$stored_content = trim( wp_kses( (string) $existing->comment_content, 'pre_comment_content' ) );
$approved = $content === $stored_content
? $existing->comment_approved
: self::moderate_edited_review( $existing, $content, $ip, $agent );
$update_ok = wp_update_comment(
wp_slash(
array(
'comment_ID' => $existing_id,
'comment_content' => $content,
)
)
);
if ( false === $update_ok || is_wp_error( $update_ok ) ) {
return array( 'error' => 'update_failed' );
}
update_comment_meta( $existing_id, 'rating', $rating );
// Drive the status explicitly so a previously auto-rejected row is untrashed
// when it now approves or holds. Only when it actually changes, so an
// unchanged status doesn't fire a redundant transition (or approval notice).
// clear_auto_rejected_flag() drops the tag on a real transition; re-tag only
// when the row stays rejected.
$target = in_array( $approved, array( 'spam', 'trash' ), true )
? (string) $approved
: ( 1 === (int) $approved ? 'approve' : 'hold' );
$status_vocab = array(
'approved' => 'approve',
'unapproved' => 'hold',
'spam' => 'spam',
'trash' => 'trash',
);
$current_status = $status_vocab[ wp_get_comment_status( $existing_id ) ] ?? '';
if ( $target !== $current_status ) {
wp_set_comment_status( $existing_id, $target );
}
if ( in_array( $approved, array( 'spam', 'trash' ), true ) ) {
update_comment_meta( $existing_id, self::AUTO_REJECTED_META_KEY, 1 );
}
return array(
'comment_id' => $existing_id,
'status' => 'approved' === wp_get_comment_status( $existing_id ) ? 'ok' : 'pending_moderation',
);
}