WC_Comments::maybe_adjust_products_reviews_pending_moderation_counterpublic staticWC 1.0

Handles transition_comment_status processing and actualizes the counter.

Method of the class: WC_Comments{}

No Hooks.

Returns

null. Nothing (null).

Usage

$result = WC_Comments::maybe_adjust_products_reviews_pending_moderation_counter( $new_status, $old_status, $comment ): void;
$new_status(int|string) (required)
New status.
$old_status(int|string) (required)
Old status.
$comment(WP_Comment) (required)
Comment object.

WC_Comments::maybe_adjust_products_reviews_pending_moderation_counter() code WC 10.5.0

public static function maybe_adjust_products_reviews_pending_moderation_counter( $new_status, $old_status, $comment ): void {
	$needs_adjustments = 'unapproved' === $new_status || 'unapproved' === $old_status;
	if ( $needs_adjustments && in_array( $comment->comment_type, array( 'review', 'comment', '' ), true ) ) {
		$is_product = 'product' === get_post_type( $comment->comment_post_ID );
		if ( $is_product ) {
			if ( '0' === $comment->comment_approved ) {
				wp_cache_incr( self::PRODUCT_REVIEWS_PENDING_COUNT_CACHE_KEY, 1, self::COMMENT_COUNT_CACHE_GROUP );
			} else {
				wp_cache_decr( self::PRODUCT_REVIEWS_PENDING_COUNT_CACHE_KEY, 1, self::COMMENT_COUNT_CACHE_GROUP );
			}
		}
	}
}