Skip to content

Commit

Permalink
Merge pull request #51 from josephdsouza86/master
Browse files Browse the repository at this point in the history
Update class-spectra.php
  • Loading branch information
av3nger authored Oct 7, 2024
2 parents 2de8e60 + 27e9816 commit 25d2de3
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions app/integrations/class-spectra.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class Spectra {
*/
public function __construct() {
add_filter( 'cf_images_content_attachment_id', array( $this, 'detect_image_id' ), 10, 2 );
add_filter( 'uagb_block_attributes_for_css_and_js', array( $this, 'replace_background_images' ) );
}

/**
Expand Down Expand Up @@ -58,4 +59,30 @@ public function detect_image_id( int $attachment_id, string $filtered_image ): i

return $attachment_id;
}

/**
* Replace background images in Spectra blocks.
*
* @param array $attributes Block attributes.
*
* @return array
*/
public function replace_background_images( array $attributes ): array {
$device_aliases = array( 'Desktop', 'Tablet', 'Mobile' );

// Check background images for all devices.
foreach ( $device_aliases as $device ) {
$key = 'backgroundImage' . $device;
if ( ! isset( $attributes[ $key ] ) ) {
continue;
}

$image = apply_filters( 'wp_get_attachment_image_src', array( $attributes[ $key ]['url'] ), $attributes[ $key ]['id'], '', false );

// Replace the background image URL.
$attributes[ $key ]['url'] = $image[0];
}

return $attributes;
}
}

0 comments on commit 25d2de3

Please sign in to comment.