0

When I upgrade wordpress6.1.1, i have an errors:

1- Trying to access array offset on value of type bool: error for $dst_w = $dims[4]; and $dst_h = $dims[5]; I try to change theses two lines in the first else but the same error.

    // Get image size after cropping.
$dims = image_resize_dimensions( $orig_w, $orig_h, $width, $height, $crop );
$dst_w = $dims[4];
$dst_h = $dims[5];

// Return the original image only if it exactly fits the needed measures.
if ( ! $dims && ( ( ( null === $height && $orig_w == $width ) xor ( null === $width && $orig_h == $height )    
)  xor ( $height == $orig_h && $width == $orig_w ) ) ) {
    $img_url = $url;
    $dst_w = $orig_w;
    $dst_h = $orig_h;
} else {
    // Use this to check if cropped image already exists, so we can return that instead.
    $suffix = "{$dst_w}x{$dst_h}";
    $dst_rel_path = str_replace( '.' . $ext, '', $rel_path );
    $destfilename = "{$upload_dir}{$dst_rel_path}-{$suffix}.{$ext}";

    if ( ! $dims || ( true == $crop && false == $upscale && ( $dst_w < $width || $dst_h < $height ) ) ) {
        // Can't resize, so return origin image url.
        return $url;
    }
    // Else check if cache exists.
    elseif ( file_exists( $destfilename ) && getimagesize( $destfilename ) ) {
        $img_url = "{$upload_url}{$dst_rel_path}-{$suffix}.{$ext}";
    }
    // Else, we resize the image and return the new resized image url.
    else {

        // Note: This pre-3.5 fallback check will edited out in subsequent version.
        if ( function_exists( 'wp_get_image_editor' ) ) {

            $editor = wp_get_image_editor( $img_path );

            if ( is_wp_error( $editor ) || is_wp_error( $editor->resize( $width, $height, $crop ) ) )
                return false;

            $resized_file = $editor->save();

            if ( ! is_wp_error( $resized_file ) ) {
                $resized_rel_path = str_replace( $upload_dir, '', $resized_file['path'] );
                $img_url = $upload_url . $resized_rel_path;
            } else {
                return false;
            }

        } else {

            $resized_img_path = image_resize( $img_path, $width, $height, $crop ); // Fallback foo.
            if ( ! is_wp_error( $resized_img_path ) ) {
                $resized_rel_path = str_replace( $upload_dir, '', $resized_img_path );
                $img_url = $upload_url . $resized_rel_path;
            } else {
                return false;
            }

        }

    }
}

2-Only variables should be passed by reference

          $uploads_dir_name = end( ( explode( '/', $uploads['baseurl'] ) ) );

          $img_path = explode( 'uploads', $img );

Any help!!

Chaima
  • 15
  • 5
  • `$dim` is false, which [happens when image_resize_dimensions fails](https://developer.wordpress.org/reference/functions/image_resize_dimensions/). For the second part, [you'll need to separate out the `end` and `explode` calls](https://stackoverflow.com/questions/4636166/only-variables-should-be-passed-by-reference) – aynber Nov 16 '22 at 20:42

0 Answers0