@@ -615,14 +615,41 @@ function pmh_add_external_media_without_import( $url, $attributes = array(), $op
615
615
if (
616
616
$ image_sizes
617
617
&&
618
- isset ( $ image_sizes ['width ' ] )
618
+ ( isset ( $ image_sizes [ ' width ' ] ) && $ image_sizes ['width ' ] )
619
619
&&
620
- isset ( $ image_sizes ['height ' ] )
620
+ ( isset ( $ image_sizes [ ' height ' ] ) && $ image_sizes ['height ' ] )
621
621
) {
622
622
623
623
// Set width and height.
624
624
$ attachment_metadata ['width ' ] = $ image_sizes ['width ' ];
625
625
$ attachment_metadata ['height ' ] = $ image_sizes ['height ' ];
626
+ } else {
627
+ // Get the attachment URL.
628
+ $ s_attachment_url = wp_get_attachment_url ( $ attachment_id );
629
+ // Initialize media fix cli object.
630
+ $ media_fix_cli = new PMH_Worker ();
631
+
632
+ // Get the image dimensions.
633
+ $ a_image_sizes = $ media_fix_cli ->clean_url_get_imagesize ( $ s_attachment_url );
634
+ update_post_meta ( $ attachment_id , '_temp_import_image_size_from_download ' , $ a_image_sizes );
635
+
636
+ // If the image dimensions are found.
637
+ if ( $ a_image_sizes ) {
638
+
639
+ list ( $ i_width , $ i_height ) = $ a_image_sizes ;
640
+
641
+ // Update the attachment metadata.
642
+ $ attachment_metadata ['width ' ] = $ i_width ;
643
+ $ attachment_metadata ['height ' ] = $ i_height ;
644
+ } else {
645
+ // If width and height are still missing after a dowload set them with max wp size as default value.
646
+ if ( ! $ attachment_metadata ['width ' ] ) {
647
+ $ attachment_metadata ['width ' ] = 2560 ;
648
+ }
649
+ if ( ! $ attachment_metadata ['height ' ] ) {
650
+ $ attachment_metadata ['height ' ] = 2560 ;
651
+ }
652
+ }
626
653
}
627
654
}
628
655
0 commit comments