Skip to content

Commit 8657a3d

Browse files
committed
simplify logic
1 parent b328f6b commit 8657a3d

File tree

1 file changed

+7
-47
lines changed

1 file changed

+7
-47
lines changed

inc/media_offload.php

Lines changed: 7 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -2221,7 +2221,6 @@ public function alter_attachment_image_src( $image, $attachment_id, $size, $icon
22212221

22222222
$url = get_post( $attachment_id );
22232223
$url = $url->guid;
2224-
$image_url = $this->get_new_offloaded_attachment_url( $url, $attachment_id );
22252224
$metadata = wp_get_attachment_metadata( $attachment_id );
22262225

22272226
// 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
22442243
];
22452244
}
22462245

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-
22732246
if ( wp_attachment_is( 'video', $attachment_id ) && doing_action( 'wp_insert_post_data' ) ) {
22742247
return $image;
22752248
}
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 );
22902250
$image_url = $this->get_new_offloaded_attachment_url(
22912251
$url,
22922252
$attachment_id,
22932253
[
2294-
'width' => $width,
2295-
'height' => $height,
2296-
'resize' => $resize,
2254+
'width' => $sizes['width'],
2255+
'height' => $sizes['height'],
2256+
'resize' => $sizes['resize'],
22972257
'attachment_id' => $attachment_id,
22982258
]
22992259
);
23002260

23012261
return [
23022262
$image_url,
2303-
$width,
2304-
$height,
2305-
$crop,
2263+
$sizes['width'],
2264+
$sizes['height'],
2265+
$size === 'full',
23062266
];
23072267
}
23082268

0 commit comments

Comments
 (0)