Skip to content

$lazy_sources triggers a undefined variable PHP notice #123

Open
@DahmaniAdame

Description

@DahmaniAdame

Undefined variable: lazy_sources in Image.php on line 273

We need to either move $lazy_sources = 0; outside of if ( preg_match_all()){} or move if ( 0 === $lazy_sources ){} inside of if ( preg_match_all()){} (like we do on WP Rocket).

if ( preg_match_all( '#<source(?<atts>\s.+)>#iUs', $picture['sources'], $sources, PREG_SET_ORDER ) ) {
$sources = array_unique( $sources, SORT_REGULAR );
$lazy_sources = 0;
foreach ( $sources as $source ) {
$lazyload_srcset = preg_replace( '/([\s"\'])srcset/i', '\1data-lazy-srcset', $source[0] );
$html = str_replace( $source[0], $lazyload_srcset, $html );
unset( $lazyload_srcset );
$lazy_sources++;
}
}
if ( 0 === $lazy_sources ) {
continue;
}

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions