From ece0618a1bcb4b7331f1144cddca05e18f6de1c7 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Wed, 4 Dec 2024 15:52:34 -0800 Subject: [PATCH] Reuse get_valid_src to obtain valid srcset --- .../class-image-prioritizer-img-tag-visitor.php | 15 ++++++--------- .../class-od-html-tag-processor.php | 1 + 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/plugins/image-prioritizer/class-image-prioritizer-img-tag-visitor.php b/plugins/image-prioritizer/class-image-prioritizer-img-tag-visitor.php index ded4d6ae2..ba14edf57 100644 --- a/plugins/image-prioritizer/class-image-prioritizer-img-tag-visitor.php +++ b/plugins/image-prioritizer/class-image-prioritizer-img-tag-visitor.php @@ -218,12 +218,8 @@ private function process_picture( OD_HTML_Tag_Processor $processor, OD_Tag_Visit } // Abort processing if a SOURCE lacks the required srcset attribute. - $srcset = $processor->get_attribute( 'srcset' ); - if ( ! is_string( $srcset ) ) { - return false; - } - $srcset = trim( $srcset ); - if ( '' === $srcset ) { + $srcset = $this->get_valid_src( $processor, 'srcset' ); + if ( null === $srcset ) { return false; } @@ -289,11 +285,12 @@ private function process_picture( OD_HTML_Tag_Processor $processor, OD_Tag_Visit * * @since n.e.x.t * - * @param OD_HTML_Tag_Processor $processor Processor. + * @param OD_HTML_Tag_Processor $processor Processor. + * @param 'src'|'srcset' $attribute_name Attribute name. * @return non-empty-string|null URL which is not a data: URL. */ - private function get_valid_src( OD_HTML_Tag_Processor $processor ): ?string { - $src = $processor->get_attribute( 'src' ); + private function get_valid_src( OD_HTML_Tag_Processor $processor, string $attribute_name = 'src' ): ?string { + $src = $processor->get_attribute( $attribute_name ); if ( ! is_string( $src ) ) { return null; } diff --git a/plugins/optimization-detective/class-od-html-tag-processor.php b/plugins/optimization-detective/class-od-html-tag-processor.php index 30bfc5eb5..7fc896711 100644 --- a/plugins/optimization-detective/class-od-html-tag-processor.php +++ b/plugins/optimization-detective/class-od-html-tag-processor.php @@ -514,6 +514,7 @@ private function get_indexed_breadcrumbs(): Generator { * They always include the entire path from the root HTML node to the matched element. * * @since n.e.x.t + * @see WP_HTML_Processor::get_breadcrumbs() * * @return string[] Array of tag names representing path to matched node. */