NO BUG: filter with bricks/element/settings

Hi, I used a function with filter ‘bricks/element/settings’

Before v.1.9.3 (1.9.2) this working:

add_filter( ‘bricks/element/settings’, ‘bricks_product_gallery_in_carousel’, 10, 2 );
function bricks_product_gallery_in_carousel( $settings, $element ) {
// if this is not the correct element or if WooCommerce is not active or if this is not a singular product page, return the default settings array
if ( $element->id !== ‘qczeyr’ || ! class_exists( ‘woocommerce’ ) || ! is_singular( ‘product’ ) ) {
return $settings;
}

// ensure the global $product variable is in scope
global $product;

// if $product is not an object, return the default settings array
if ( $product === false ) {
return $settings;
}

// get the product gallery attachment IDs
$product_gallery_images_ids = $product->get_gallery_image_ids();

// declare an empty array to store the new images settings
$id_product = (int) $product->get_image_id();
$new_images_settings = [
[
‘id’ => $id_product,
‘url’ => wp_get_attachment_image_url( $id_product, ‘thumbnail’ ),
‘full’ => wp_get_attachment_image_src( $id_product, ‘full’ )[0],
]
];

// loop through the product gallery image IDs and construct the new image settings array
foreach( $product_gallery_images_ids as $id ) {
$new_images_settings = array(
‘id’ => $id,
‘url’ => wp_get_attachment_image_url( $id, ‘thumbnail’ ),
‘full’ => wp_get_attachment_image_src( $id, ‘full’ )[0],
);
}

// replace the element’s images settings array with the above array
if ( ! empty( $new_images_settings ) ) {
$settings[‘items’][‘images’] = $new_images_settings;
$settings[‘items’][‘size’] = ‘full’;
}

return $settings;
}

With last version is always empty. It’s a bug?

With version 1.9.2 work perfect.

Hi @soodesign,

If I understand your use case correctly, I think you might have a bug in your code. It seems like you intend to gather all the images from a WooCommerce product gallery and update the settings of an “Image gallery” element.

However, there’s an issue in the way the gallery images are being handled in your loop:

Here’s the corrected version of your code:

Let me know if that wasn’t the intended use case.

My code is like yours, but for some reason the square brackets were omitted here.

As I was saying, it works in Bricks version 1.9.2. When I update it stops working

I couldn’t replicate this locally, it’s working for me on 1.9.2 & 1.9.3. Could you maybe share temporary admin access to a staging environment where we could investigate this? if so please share the credentials to help@bricksbuilder.io with a link to this forum thread.