PHP 8 Exposes Warning in Image Field file info

Support General PHP 8 Exposes Warning in Image Field file info

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #38919
    Austin PassyAustin Passy
    Participant

    Error:

    `
    PHP-ERROR.WARNING: Trying to access array offset on value of type bool
    {"file":"/usr/local/wordpress/wp-content/plugins/meta-box/inc/fields/image.php","line":145}
    {"wp":{"doing_cron":false,"doing_ajax":false,"is_admin":false,"doing_rest":true,"user_id":XX}}
    `

    This is due to RWMB_Image_Field::file_info calling wp_get_attachment_image_src and assuming it's an array always. This function can return false, and is a silent error in PHP < 8.x.

    A simple addition like so should resolve the issue:

    `
    $image = wp_get_attachment_image_src( $file, $args['size'] );
    if ( ! $image ) {
    return false;
    }
    `

    #38924
    Anh TranAnh Tran
    Keymaster

    Thanks, Austin. It's fixed here.

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.