When upgrading my website to PHP 8.0, then the following message will appear on the page:
Warning: Trying to access array offset on value of type bool in......../vc_row.php on line 155
and in
............/vc_row.php on line 159
This relates to the following line of code (line 155):
$style .= 'background-image: url('. $bg_image_src\[0\]. '); ';
and line 159:
$fixed_bg = '\<div class="ios-fixed-bg"\>\<div style="background-image: url('. $bg_image_src\[0\]. '); background-position: '. $background_position .'; background-repeat: '. $background_repeat .'; "\>\</div\>\</div\>';
The code for the function is:
if ( $background_type == 'image_bg' && $background_image != '' && $background_effect != 'crossfade' ) {
if ( $background_effect == 'animation' ) {
if( !preg_match('/^\d+$/',$background_image) ) {
$animate_style .= 'background-image: url('. $background_image . '); ';
$animate_style .= 'background-position: '. $background_position .'; ';
$animate_style .= 'background-repeat: '. $background_repeat .'; ';
} else {
$bg_image_src = wp_get_attachment_image_src($background_image, 'full');
$animate_style .= 'background-image: url('. $bg_image_src[0]. '); ';
$animate_style .= 'background-position: '. $background_position .'; ';
$animate_style .= 'background-repeat: '. $background_repeat .'; ';
}
} else {
if( !preg_match('/^\d+$/',$background_image) ) {
$style .= 'background-image: url('. $background_image . '); ';
$style .= 'background-position: '. $background_position .'; ';
$style .= 'background-repeat: '. $background_repeat .'; ';
if ( $background_attachment != '' ) {
$fixed_bg = '<div class="ios-fixed-bg"><div style="background-image: url('. $background_image . '); background-position: '. $background_position .'; background-repeat: '. $background_repeat .'; "></div></div>';
}
} else {
$bg_image_src = wp_get_attachment_image_src($background_image, 'full');
$style .= 'background-image: url('. $bg_image_src[0]. '); ';
$style .= 'background-position: '. $background_position .'; ';
$style .= 'background-repeat: '. $background_repeat .'; ';
if ( $background_attachment != '' ) {
$fixed_bg = '<div class="ios-fixed-bg"><div style="background-image: url('. $bg_image_src[0]. '); background-position: '. $background_position .'; background-repeat: '. $background_repeat .'; "></div></div>';
}
}
}
}
Can someone please help me with the code so I can use PHP 8.0?
When I go back to PHP 7.4 the warning disappears.
Thanks for helping!
So far I haven't dared to change the code myself.