IF Error. PHP 8.1.26 Trying to access array offset on value of type bool in

87 Views Asked by At

I get the following errors in the theme functions file on a website with Wordpress installed. This error appeared when I upgraded to PHP 8.1.26.

2 Error Log:

[proxy_fcgi:error] AH01071: Got error 'PHP message: PHP Warning: Trying to access array offset on value of type bool in /home/mywebsite/public_html/wp-content/themes/mytheme/framework/functions/momizat_functions.php on line 104

PHP message: PHP Warning: Trying to access array offset on value of type bool in /home/mywebsite/public_html/wp-content/themes/mytheme/framework/functions/momizat_functions.php on line 170

Line 104 code is:

$image = $image[0]

Line 170code is:

if ($image) { return $image; }
function mom_post_image($size = 'thumbnail', $id = ''){
        global $post;
        if ($id == '') {
            $id = $post->ID;
        }
                $image = '';
        
        //get the post thumbnail
        $image_id = get_post_thumbnail_id($id);
        $image = wp_get_attachment_image_src($image_id,
        $size);
        $image = $image[0];

        if ($image) {
            return $image;
        }


//If there is still no image, get the first image from the post
        if (mom_option('post_first_image') == 1) {
                    if (mom_get_first_image($id)) {
                    return mom_get_first_image($id, $size);
                    }
            }

            if (mom_option('default_post_image') != '') {
                $image = wp_get_attachment_image_src(mom_option('default_post_image', 'id'), $size);
            $image = $image[0];
                if ($image) { return $image; }
            }
0

There are 0 best solutions below