@@ -662,7 +662,6 @@ protected function strip_image_size_maybe( $src ) {
662
662
$ stripped_src = str_replace ( $ src_parts [1 ], '' , $ src );
663
663
$ upload_dir = wp_get_upload_dir ();
664
664
// Extracts the file path to the image minus the base url
665
-
666
665
$ file_path = substr ( $ stripped_src , strlen ( $ upload_dir ['baseurl ' ] ) );
667
666
668
667
if ( file_exists ( $ upload_dir ['basedir ' ] . $ file_path ) ) {
@@ -874,7 +873,7 @@ public function filter_the_content( $content ) {
874
873
$ new_tag = str_replace ( 'width=" ' . $ width . '" ' , 'width=" ' . $ new_sizes ['width ' ] . '" ' , $ new_tag );
875
874
$ new_tag = str_replace ( 'height=" ' . $ height . '" ' , 'height=" ' . $ new_sizes ['height ' ] . '" ' , $ new_tag );
876
875
877
- if ( $ this ->lazyload ) {
876
+ if ( $ this ->lazyload && $ this -> can_lazyload ( $ tmp ) ) {
878
877
$ new_sizes ['quality ' ] = 'eco ' ;
879
878
$ low_url = $ this ->get_imgcdn_url ( $ tmp , $ new_sizes );
880
879
@@ -948,13 +947,40 @@ public static function parse_images_from_html( $content ) {
948
947
* @return string The HTML without the <header/> tag
949
948
*/
950
949
public static function strip_header_from_content ( $ content ) {
951
- if ( preg_match ('/<header.*<\/header>/ismU ' , $ content , $ matches ) !== 1 ) {
950
+ if ( preg_match ( '/<header.*<\/header>/ismU ' , $ content , $ matches ) !== 1 ) {
952
951
return $ content ;
953
952
}
954
-
953
+
955
954
return str_replace ( $ matches [0 ], '' , $ content );
956
955
}
957
956
957
+ /**
958
+ * Check if the lazyload is allowed for this url.
959
+ *
960
+ * @param string $url Url.
961
+ *
962
+ * @return bool We can lazyload?
963
+ */
964
+ public function can_lazyload ( $ url ) {
965
+ if ( ! defined ( 'OPTML_DISABLE_PNG_LAZYLOAD ' ) ) {
966
+ return true ;
967
+ }
968
+ if ( ! OPTML_DISABLE_PNG_LAZYLOAD ) {
969
+ return true ;
970
+ }
971
+ $ type = wp_check_filetype (
972
+ basename ( $ url ),
973
+ array (
974
+ 'png ' => 'image/png ' ,
975
+ )
976
+ );
977
+ if ( ! isset ( $ type ['ext ' ] ) || empty ( $ type ['ext ' ] ) ) {
978
+ return true ;
979
+ }
980
+
981
+ return false ;
982
+ }
983
+
958
984
/**
959
985
* Extract slashed urls from content.
960
986
*
0 commit comments