@@ -2221,7 +2221,6 @@ public function alter_attachment_image_src( $image, $attachment_id, $size, $icon
2221
2221
2222
2222
$ url = get_post ( $ attachment_id );
2223
2223
$ url = $ url ->guid ;
2224
- $ image_url = $ this ->get_new_offloaded_attachment_url ( $ url , $ attachment_id );
2225
2224
$ metadata = wp_get_attachment_metadata ( $ attachment_id );
2226
2225
2227
2226
// Use the original size if the requested size is full.
@@ -2244,65 +2243,26 @@ public function alter_attachment_image_src( $image, $attachment_id, $size, $icon
2244
2243
];
2245
2244
}
2246
2245
2247
- $ crop = false ;
2248
-
2249
- // Size can be int [] containing width and height.
2250
- if ( is_array ( $ size ) ) {
2251
- $ width = $ size [0 ];
2252
- $ height = $ size [1 ];
2253
- $ crop = true ;
2254
- } else {
2255
- $ sizes = $ this ->get_all_image_sizes ();
2256
-
2257
- if ( ! isset ( $ sizes [ $ size ] ) ) {
2258
- return [
2259
- $ image_url ,
2260
- $ metadata ['width ' ],
2261
- $ metadata ['height ' ],
2262
- false ,
2263
- ];
2264
- }
2265
-
2266
- $ width = $ sizes [ $ size ]['width ' ];
2267
- $ height = $ sizes [ $ size ]['height ' ];
2268
- $ crop = is_array ( $ sizes [ $ size ]['crop ' ] ) ? $ sizes [ $ size ]['crop ' ] : (bool ) $ sizes [ $ size ]['crop ' ];
2269
- }
2270
-
2271
- $ sizes2crop = self ::size_to_crop ();
2272
-
2273
2246
if ( wp_attachment_is ( 'video ' , $ attachment_id ) && doing_action ( 'wp_insert_post_data ' ) ) {
2274
2247
return $ image ;
2275
2248
}
2276
-
2277
- $ resize = apply_filters ( 'optml_default_crop ' , [] );
2278
- $ data = image_get_intermediate_size ( $ attachment_id , $ size );
2279
-
2280
- if ( is_array ( $ data ) && isset ( $ data ['width ' ] ) && isset ( $ data ['height ' ] ) ) { // @phpstan-ignore-line - these both exist.
2281
- if ( isset ( $ sizes2crop [ $ data ['width ' ] . $ data ['height ' ] ] ) ) {
2282
- $ resize = $ this ->to_optml_crop ( $ sizes2crop [ $ data ['width ' ] . $ data ['height ' ] ] );
2283
- }
2284
- }
2285
-
2286
- if ( $ crop !== false ) {
2287
- $ resize = $ this ->to_optml_crop ( $ crop );
2288
- }
2289
-
2249
+ $ sizes = $ this ->size_to_dimension ( $ size , $ metadata );
2290
2250
$ image_url = $ this ->get_new_offloaded_attachment_url (
2291
2251
$ url ,
2292
2252
$ attachment_id ,
2293
2253
[
2294
- 'width ' => $ width ,
2295
- 'height ' => $ height ,
2296
- 'resize ' => $ resize ,
2254
+ 'width ' => $ sizes [ ' width ' ] ,
2255
+ 'height ' => $ sizes [ ' height ' ] ,
2256
+ 'resize ' => $ sizes [ ' resize ' ] ,
2297
2257
'attachment_id ' => $ attachment_id ,
2298
2258
]
2299
2259
);
2300
2260
2301
2261
return [
2302
2262
$ image_url ,
2303
- $ width ,
2304
- $ height ,
2305
- $ crop ,
2263
+ $ sizes [ ' width ' ] ,
2264
+ $ sizes [ ' height ' ] ,
2265
+ $ size === ' full ' ,
2306
2266
];
2307
2267
}
2308
2268
0 commit comments