Skip to content

Commit

Permalink
Reuse get_valid_src to obtain valid srcset
Browse files Browse the repository at this point in the history
  • Loading branch information
westonruter committed Dec 4, 2024
1 parent 8f6550a commit ece0618
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down

0 comments on commit ece0618

Please sign in to comment.