Automattic\WooCommerce\Internal\Admin\ProductReviews

ReviewsListTable::comments_bubble()protectedWC 1.0

Displays a review count bubble.

Based on WP_List_Table::comments_bubble(), but overridden, so we can customize the URL and text output.

{} Это метод класса: ReviewsListTable{}

Хуков нет.

Возвращает

null. Ничего.

Использование

// protected - в коде основоного (родительского) или дочернего класса
$result = $this->comments_bubble( $post_id, $pending_comments ) : void;
$post_id(int|разное) (обязательный)
The product ID.
$pending_comments(int|разное) (обязательный)
Number of pending reviews.

Код ReviewsListTable::comments_bubble() WC 6.8.0

protected function comments_bubble( $post_id, $pending_comments ) : void {
	$approved_review_count = get_comments_number();

	$approved_reviews_number = number_format_i18n( $approved_review_count );
	$pending_reviews_number  = number_format_i18n( $pending_comments );

	$approved_only_phrase = sprintf(
		/* translators: %s: Number of reviews. */
		_n( '%s review', '%s reviews', $approved_review_count, 'woocommerce' ),
		$approved_reviews_number
	);

	$approved_phrase = sprintf(
		/* translators: %s: Number of reviews. */
		_n( '%s approved review', '%s approved reviews', $approved_review_count, 'woocommerce' ),
		$approved_reviews_number
	);

	$pending_phrase = sprintf(
		/* translators: %s: Number of reviews. */
		_n( '%s pending review', '%s pending reviews', $pending_comments, 'woocommerce' ),
		$pending_reviews_number
	);

	if ( ! $approved_review_count && ! $pending_comments ) {
		// No reviews at all.
		printf(
			'<span aria-hidden="true">&#8212;</span><span class="screen-reader-text">%s</span>',
			esc_html__( 'No reviews', 'woocommerce' )
		);
	} elseif ( $approved_review_count && 'trash' === get_post_status( $post_id ) ) {
		// Don't link the comment bubble for a trashed product.
		printf(
			'<span class="post-com-count post-com-count-approved"><span class="comment-count-approved" aria-hidden="true">%s</span><span class="screen-reader-text">%s</span></span>',
			esc_html( $approved_reviews_number ),
			$pending_comments ? esc_html( $approved_phrase ) : esc_html( $approved_only_phrase )
		);
	} elseif ( $approved_review_count ) {
		// Link the comment bubble to approved reviews.
		printf(
			'<a href="%s" class="post-com-count post-com-count-approved"><span class="comment-count-approved" aria-hidden="true">%s</span><span class="screen-reader-text">%s</span></a>',
			esc_url(
				add_query_arg(
					[
						'product_id'     => urlencode( $post_id ),
						'comment_status' => 'approved',
					],
					Reviews::get_reviews_page_url()
				)
			),
			esc_html( $approved_reviews_number ),
			$pending_comments ? esc_html( $approved_phrase ) : esc_html( $approved_only_phrase )
		);
	} else {
		// Don't link the comment bubble when there are no approved reviews.
		printf(
			'<span class="post-com-count post-com-count-no-comments"><span class="comment-count comment-count-no-comments" aria-hidden="true">%s</span><span class="screen-reader-text">%s</span></span>',
			esc_html( $approved_reviews_number ),
			$pending_comments ? esc_html__( 'No approved reviews', 'woocommerce' ) : esc_html__( 'No reviews', 'woocommerce' )
		);
	}

	if ( $pending_comments ) {
		printf(
			'<a href="%s" class="post-com-count post-com-count-pending"><span class="comment-count-pending" aria-hidden="true">%s</span><span class="screen-reader-text">%s</span></a>',
			esc_url(
				add_query_arg(
					[
						'product_id'     => urlencode( $post_id ),
						'comment_status' => 'moderated',
					],
					Reviews::get_reviews_page_url()
				)
			),
			esc_html( $pending_reviews_number ),
			esc_html( $pending_phrase )
		);
	} else {
		printf(
			'<span class="post-com-count post-com-count-pending post-com-count-no-pending"><span class="comment-count comment-count-no-pending" aria-hidden="true">%s</span><span class="screen-reader-text">%s</span></span>',
			esc_html( $pending_reviews_number ),
			$approved_review_count ? esc_html__( 'No pending reviews', 'woocommerce' ) : esc_html__( 'No reviews', 'woocommerce' )
		);
	}
}