Automattic\WooCommerce\EmailEditor\Integrations\Core\Renderer\Blocks

Gallery::get_cell_width │ private │ WC 1.0

Estimate the rendered width (in px) of the gallery cell that holds a given image.

The gallery packs images into rows of $columns. A complete row splits the layout width evenly, but an incomplete final row is distributed across only its remaining images — a lone trailing image spans the full width (see {@see build_gallery_row_table()}). Sizing the crop to the actual cell keeps an image CDN from serving an undersized file for such images.

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

Хуков нет.

Возвращает

int. Cell width in px (at least 1).

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

// private - только в коде основоного (родительского) класса
$result = $this->get_cell_width( $index, $image_count, $columns, $layout_width ): int;
$index(int) (обязательный)
Zero-based index of the image among the rendered images.
$image_count(int) (обязательный)
Total number of rendered images.
$columns(int) (обязательный)
Number of gallery columns.
$layout_width(int) (обязательный)
Available layout width in px.

Код Gallery::get_cell_width() WC 11.2.2

private function get_cell_width( int $index, int $image_count, int $columns, int $layout_width ): int {
	$columns       = max( 1, $columns );
	$row_start     = intdiv( $index, $columns ) * $columns;
	$images_in_row = max( 1, min( $columns, $image_count - $row_start ) );

	return (int) max( 1, floor( $layout_width / $images_in_row ) );
}