Automattic\WooCommerce\Internal\ProductGallery

ProductMediaGallery::normalize_video_gallery_item │ private static │ WC 1.0

Normalize one video gallery item.

Method of the class: ProductMediaGallery{}

No Hooks.

Returns

array.

Usage

$result = ProductMediaGallery::normalize_video_gallery_item( $item, $fallback_position ): array;
$item(array) (required)
Video gallery item.
$fallback_position(int) (required)
Position used when item has no position.

ProductMediaGallery::normalize_video_gallery_item() code WC 11.1.2

private static function normalize_video_gallery_item( array $item, int $fallback_position ): array {
	$media_type    = isset( $item['media_type'] ) ? sanitize_key( $item['media_type'] ) : 'video';
	$source_type   = isset( $item['source_type'] ) ? sanitize_key( $item['source_type'] ) : 'attachment';
	$attachment_id = isset( $item['id'] ) ? absint( $item['id'] ) : 0;

	if ( 'video' !== $media_type || 'attachment' !== $source_type || ! $attachment_id ) {
		return array();
	}

	$mime_type = get_post_mime_type( $attachment_id );

	if ( ! is_string( $mime_type ) || 0 !== strpos( $mime_type, 'video/' ) ) {
		return array();
	}

	$video_item = array();
	$poster_id  = isset( $item['poster_id'] ) ? absint( $item['poster_id'] ) : 0;

	$video_item['source_type'] = 'attachment';
	$video_item['id']          = $attachment_id;
	$video_item['position']    = isset( $item['position'] ) ? absint( $item['position'] ) : $fallback_position;

	if (
		$poster_id &&
		(
			wp_attachment_is_image( $poster_id ) ||
			0 === strpos( (string) get_post_mime_type( $poster_id ), 'image/' )
		)
	) {
		$video_item['poster_id'] = $poster_id;
	}

	return $video_item;
}