Automattic\WooCommerce\Internal\ProductGallery
ProductMediaGallery::get_attachment_ids
Get attachment IDs represented by media gallery items.
Метод класса: ProductMediaGallery{}
Хуков нет.
Возвращает
array.
Использование
$result = ProductMediaGallery::get_attachment_ids( $media_gallery, $include_posters ): array;
- $media_gallery(массив) (обязательный)
- Media gallery items.
- $include_posters(true|false)
- Whether to include resolved video poster IDs.
По умолчанию:false
Код ProductMediaGallery::get_attachment_ids() ProductMediaGallery::get attachment ids WC 11.3.0
private static function get_attachment_ids( array $media_gallery, bool $include_posters = false ): array {
$attachment_ids = array();
foreach ( $media_gallery as $item ) {
if ( ! is_array( $item ) ) {
continue;
}
if ( 'attachment' === ( $item['source_type'] ?? 'attachment' ) && ! empty( $item['id'] ) ) {
$attachment_ids[] = absint( $item['id'] );
}
if (
$include_posters &&
(
! isset( $item['media_type'] ) ||
'video' === $item['media_type']
)
) {
$attachment_ids[] = self::get_video_poster_id( $item );
}
}
return array_values( array_unique( array_filter( $attachment_ids ) ) );
}