Automattic\WooCommerce\Internal\ProductGallery
ProductMediaGallery::get_image_ids
Get image IDs from media gallery items.
Method of the class: ProductMediaGallery{}
No Hooks.
Returns
array.
Usage
$result = ProductMediaGallery::get_image_ids( $media_gallery ): array;
- $media_gallery(array) (required)
- Media gallery items.
ProductMediaGallery::get_image_ids() ProductMediaGallery::get image ids code WC 11.1.2
public static function get_image_ids( array $media_gallery ): array {
$image_ids = array();
foreach ( $media_gallery as $item ) {
if (
is_array( $item ) &&
'image' === ( $item['media_type'] ?? '' ) &&
'attachment' === ( $item['source_type'] ?? 'attachment' ) &&
! empty( $item['id'] )
) {
$image_ids[] = absint( $item['id'] );
}
}
return array_values( array_filter( $image_ids ) );
}