Skip to content

Commit ece0618

Browse files
committed
Reuse get_valid_src to obtain valid srcset
1 parent 8f6550a commit ece0618

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed

plugins/image-prioritizer/class-image-prioritizer-img-tag-visitor.php

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -218,12 +218,8 @@ private function process_picture( OD_HTML_Tag_Processor $processor, OD_Tag_Visit
218218
}
219219

220220
// Abort processing if a SOURCE lacks the required srcset attribute.
221-
$srcset = $processor->get_attribute( 'srcset' );
222-
if ( ! is_string( $srcset ) ) {
223-
return false;
224-
}
225-
$srcset = trim( $srcset );
226-
if ( '' === $srcset ) {
221+
$srcset = $this->get_valid_src( $processor, 'srcset' );
222+
if ( null === $srcset ) {
227223
return false;
228224
}
229225

@@ -289,11 +285,12 @@ private function process_picture( OD_HTML_Tag_Processor $processor, OD_Tag_Visit
289285
*
290286
* @since n.e.x.t
291287
*
292-
* @param OD_HTML_Tag_Processor $processor Processor.
288+
* @param OD_HTML_Tag_Processor $processor Processor.
289+
* @param 'src'|'srcset' $attribute_name Attribute name.
293290
* @return non-empty-string|null URL which is not a data: URL.
294291
*/
295-
private function get_valid_src( OD_HTML_Tag_Processor $processor ): ?string {
296-
$src = $processor->get_attribute( 'src' );
292+
private function get_valid_src( OD_HTML_Tag_Processor $processor, string $attribute_name = 'src' ): ?string {
293+
$src = $processor->get_attribute( $attribute_name );
297294
if ( ! is_string( $src ) ) {
298295
return null;
299296
}

plugins/optimization-detective/class-od-html-tag-processor.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,7 @@ private function get_indexed_breadcrumbs(): Generator {
514514
* They always include the entire path from the root HTML node to the matched element.
515515
*
516516
* @since n.e.x.t
517+
* @see WP_HTML_Processor::get_breadcrumbs()
517518
*
518519
* @return string[] Array of tag names representing path to matched node.
519520
*/

0 commit comments

Comments
 (0)