Skip to content

Commit e1c1780

Browse files
committed
reuse attachment id logic
1 parent 8ef0eca commit e1c1780

File tree

1 file changed

+4
-11
lines changed

1 file changed

+4
-11
lines changed

inc/media_offload.php

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -540,20 +540,13 @@ public function get_local_attachement_id_from_url( $url ) {
540540

541541
$size = 'full';
542542
$found_size = $this->parse_dimensions_from_filename( $url );
543-
$strip_url = $url;
544-
$scaled_url = $url;
543+
$url = $this->add_schema( $url );
545544
if ( $found_size[0] !== false && $found_size[1] !== false ) {
546-
$size = $found_size;
547-
$strip_url = str_replace( '-' . $found_size[0] . 'x' . $found_size[1], '', $url );
548-
$scaled_url = str_replace( '-' . $found_size[0] . 'x' . $found_size[1], '-scaled', $url );
549-
}
550-
$strip_url = $this->add_schema( $strip_url );
545+
$size = $found_size;
551546

552-
$attachment_id = attachment_url_to_postid( $strip_url );
553-
if ( $attachment_id === 0 ) {
554-
$scaled_url = $this->add_schema( $scaled_url );
555-
$attachment_id = attachment_url_to_postid( $scaled_url );
556547
}
548+
$url = $this->add_schema( $url );
549+
$attachment_id = $this->attachment_url_to_post_id( $url );
557550

558551
return [ 'attachment_id' => $attachment_id, 'size' => $size ];
559552
}

0 commit comments

Comments
 (0)