Automattic\WooCommerce\Internal\OrderReviews

SubmissionHandler::moderate_edited_review │ private static │ WC 1.0

Approval status for an edited review, run through the same moderation an insert gets: the disallowed-keys list, moderation keywords and link limit, and the pre_comment_approved wp_update_comment() runs these itself.

Method of the class: SubmissionHandler{}

No Hooks.

Returns

int|string. 1 or 0 to approve/hold, or 'spam'/'trash' to reject.

Usage

$result = SubmissionHandler::moderate_edited_review( $existing, $content, $ip, $agent );
$existing(WP_Comment) (required)
The review being edited.
$content(string) (required)
The new content.
$ip(string) (required)
Comment author IP.
$agent(string) (required)
Comment author user agent.

SubmissionHandler::moderate_edited_review() code WC 11.1.2

private static function moderate_edited_review( \WP_Comment $existing, string $content, string $ip, string $agent ) {
	$comment_data = array(
		'comment_ID'           => (int) $existing->comment_ID,
		'comment_post_ID'      => (int) $existing->comment_post_ID,
		'comment_author'       => $existing->comment_author,
		'comment_author_email' => $existing->comment_author_email,
		'comment_author_url'   => $existing->comment_author_url,
		'comment_content'      => $content,
		'comment_author_IP'    => $ip,
		'comment_agent'        => $agent,
		'comment_type'         => 'review',
		// A deleted author would make wp_check_comment_data() call has_cap() on
		// a false user and fatal, so fall back to an unattributed 0.
		'user_id'              => get_userdata( (int) $existing->user_id ) ? (int) $existing->user_id : 0,
	);

	// Verified-purchase reviews are not held behind the "commenter must already
	// have an approved comment" gate, matching the insert path.
	add_filter( 'pre_option_comment_previously_approved', '__return_zero' );
	try {
		$approved = wp_check_comment_data( $comment_data );
	} finally {
		remove_filter( 'pre_option_comment_previously_approved', '__return_zero' );
	}

	// A filter may return WP_Error; fall back to holding for moderation.
	return is_wp_error( $approved ) ? 0 : $approved;
}