@@ -420,6 +420,9 @@ public function replace_content( $html, $partial = false ) {
420420 if ( defined ( 'REST_REQUEST ' ) && REST_REQUEST && is_user_logged_in () && ( apply_filters ( 'optml_force_replacement ' , false ) !== true ) ) {
421421 return $ html ;
422422 }
423+ if ( OPTML_DEBUG ) {
424+ do_action ( 'optml_log ' , 'in Viewport: ' . var_export ( $ partial , true ) . wp_debug_backtrace_summary () );
425+ }
423426 if ( $ this ->settings ->is_lazyload_type_viewport () && ! $ partial ) {
424427 $ profile_id = Profile::generate_id ( $ html );
425428 // We disable the optimizer for logged in users.
@@ -594,11 +597,14 @@ public static function should_ignore_image_tags() {
594597 public static function parse_images_from_html ( $ content ) {
595598 $ images = [];
596599
600+ if ( OPTML_DEBUG ) {
601+ do_action ( 'optml_log ' , 'Content to parse images from: ' . $ content );
602+ }
597603 $ regex = '/(?:<a[^>]+?href=["| \'](?P<link_url>[^\s]+?)["| \'][^>]*?>\s*)?(?P<img_tag>(?:<noscript\s*>\s*)?<img[^>]*?\s?(?: ' . implode ( '| ' , array_merge ( [ 'src ' ], Optml_Tag_Replacer::possible_src_attributes () ) ) . ')=[" \'\\\\]*?(?P<img_url>[ ' . Optml_Config::$ chars . ']{10,}).*?>(?:\s*<\/noscript\s*>)?){1}(?:\s*<\/a>)?/ismu ' ;
598604
599605 if ( preg_match_all ( $ regex , $ content , $ images , PREG_OFFSET_CAPTURE ) ) {
600606 if ( OPTML_DEBUG ) {
601- do_action ( 'optml_log ' , 'images parased : ' . print_r ( $ images , true ) );
607+ do_action ( 'optml_log ' , 'Image tags parsed : ' . print_r ( $ images , true ) );
602608 }
603609 foreach ( $ images as $ key => $ unused ) {
604610 // Simplify the output as much as possible, mostly for confirming test results.
@@ -646,8 +652,7 @@ public static function parse_images_from_html( $content ) {
646652 public function process_urls_from_content ( $ html ) {
647653 $ extracted_urls = $ this ->extract_urls_from_content ( $ html );
648654 if ( OPTML_DEBUG ) {
649- do_action ( 'optml_log ' , 'matched urls ' );
650- do_action ( 'optml_log ' , $ extracted_urls );
655+ do_action ( 'optml_log ' , 'Extracted image urls from content: ' . print_r ( $ extracted_urls , true ) );
651656 }
652657 return $ this ->do_url_replacement ( $ html , $ extracted_urls );
653658 }
@@ -759,7 +764,20 @@ public function process_template_redirect_content() {
759764 remove_filter ( 'the_content ' , [ $ this , 'process_images_from_content ' ], PHP_INT_MAX );
760765
761766 ob_start (
762- [ &$ this , 'replace_content ' ]
767+ function ( $ content ) {
768+ /*
769+ * Wrap the call to replace_content() so that PHP’s output-buffering system
770+ * does not pass its own second argument ($phase bitmask) to our method.
771+ *
772+ * replace_content() expects the second parameter to be a boolean $partial,
773+ * indicating whether the content is a partial replacement (e.g. for
774+ * viewport lazy-load) or a full page. If PHP’s $phase integer is passed
775+ * directly, it would be misinterpreted as $partial and break the logic.
776+ *
777+ * This closure filters the call, forwarding only the captured HTML buffer.
778+ */
779+ return $ this ->replace_content ( $ content );
780+ }
763781 );
764782 }
765783
0 commit comments