Skip to content

Commit 3163d47

Browse files
Support background keys without leading underscore
1 parent 959f7a4 commit 3163d47

1 file changed

Lines changed: 20 additions & 10 deletions

File tree

php/integrations/class-elementor.php

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,27 +22,27 @@ class Elementor extends Integrations {
2222
* @var array
2323
*/
2424
const ELEMENTOR_BACKGROUND_IMAGES = array(
25-
'_background_image' => array(
25+
'background_image' => array(
2626
'device' => 'desktop',
2727
'suffix' => '',
2828
),
29-
'_background_hover_image' => array(
29+
'background_hover_image' => array(
3030
'device' => 'desktop',
3131
'suffix' => ':hover',
3232
),
33-
'_background_image_tablet' => array(
33+
'background_image_tablet' => array(
3434
'device' => 'tablet',
3535
'suffix' => '',
3636
),
37-
'_background_hover_image_tablet' => array(
37+
'background_hover_image_tablet' => array(
3838
'device' => 'tablet',
3939
'suffix' => ':hover',
4040
),
41-
'_background_image_mobile' => array(
41+
'background_image_mobile' => array(
4242
'device' => 'mobile',
4343
'suffix' => '',
4444
),
45-
'_background_hover_image_mobile' => array(
45+
'background_hover_image_mobile' => array(
4646
'device' => 'mobile',
4747
'suffix' => ':hover',
4848
),
@@ -84,13 +84,23 @@ public function replace_background_images_in_css( $post_css, $element ) {
8484
}
8585

8686
foreach ( self::ELEMENTOR_BACKGROUND_IMAGES as $background_key => $background_data ) {
87-
// We need to have the ID from the image to proceed.
88-
if ( ! isset( $settings[ $background_key ]['id'] ) ) {
87+
$background = null;
88+
89+
if ( isset( $settings[ $background_key ] ) ) {
90+
// Elementor section/column elements store background settings without a leading underscore.
91+
$background = $settings[ $background_key ];
92+
} elseif ( isset( $settings[ '_' . $background_key ] ) ) {
93+
// Elementor basic elements (e.g. heading) store background settings with a leading underscore.
94+
$background = $settings[ '_' . $background_key ];
95+
}
96+
97+
// If this specific background setting is not set, we can skip it and check for the next setting.
98+
if ( empty( $background ) || ! isset( $background['id'] ) ) {
8999
continue;
90100
}
91101

92-
$media_id = $settings[ $background_key ]['id'];
93-
$media_size = isset( $settings[ $background_key ]['size'] ) ? $settings[ $background_key ]['size'] : array();
102+
$media_id = $background['id'];
103+
$media_size = isset( $background['size'] ) ? $background['size'] : array();
94104

95105
// Skip if the media is not deliverable via Cloudinary.
96106
if ( ! $delivery->is_deliverable( $media_id ) ) {

0 commit comments

Comments
 (0)