Automattic\WooCommerce\Internal\VariationGallery

ClassicVariationGalleryAdmin::render_thumbnailprivateWC 1.0

Render a single thumbnail list item.

Метод класса: ClassicVariationGalleryAdmin{}

Хуков нет.

Возвращает

null. Ничего (null).

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

// private - только в коде основоного (родительского) класса
$result = $this->render_thumbnail( $image_id, $is_active ): void;
$image_id(int) (обязательный)
Attachment ID.
$is_active(true|false) (обязательный)
Whether this thumbnail is the active/primary one.

Код ClassicVariationGalleryAdmin::render_thumbnail() WC 10.9.1

<?php
private function render_thumbnail( int $image_id, bool $is_active ): void {
	$thumbnail = wp_get_attachment_image( $image_id, 'thumbnail' );
	$is_broken = '' === $thumbnail;
	$classes   = array( 'wc-variation-gallery-thumb' );

	if ( $is_active ) {
		$classes[] = 'is-active';
	}

	if ( $is_broken ) {
		$classes[] = 'is-broken';
	}

	/* translators: %d attachment ID */
	$thumb_label = sprintf( __( 'Show gallery image %d', 'woocommerce' ), $image_id );
	?>
	<li
		class="<?php echo esc_attr( implode( ' ', $classes ) ); ?>"
		data-attachment_id="<?php echo esc_attr( (string) $image_id ); ?>"
	>
		<button
			type="button"
			class="wc-variation-gallery-thumb__button"
			aria-label="<?php echo esc_attr( $thumb_label ); ?>"
		>
			<?php if ( $is_broken ) : ?>
				<span class="wc-variation-gallery-thumb__broken" aria-hidden="true">
					<span class="dashicons dashicons-format-image"></span>
				</span>
				<span class="screen-reader-text">
					<?php esc_html_e( 'Attachment file missing', 'woocommerce' ); ?>
				</span>
			<?php else : ?>
				<?php echo wp_kses_post( $thumbnail ); ?>
			<?php endif; ?>
		</button>
		<button
			type="button"
			class="wc-variation-gallery-thumb__remove"
			aria-label="<?php esc_attr_e( 'Remove image', 'woocommerce' ); ?>"
		>
			<span class="dashicons dashicons-no-alt" aria-hidden="true"></span>
		</button>
	</li>
	<?php
}