Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closes #6312: Exclude youtube thumbnail from lazyload #6391

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion inc/Dependencies/RocketLazyload/Iframe.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function lazyloadIframes( $html, $buffer, $args = [] ) {
continue;
}

if ( $args['youtube'] ) {
if ( $args['youtube'] && ! $this->is_youtube_excluded( $iframe ) ) {
$iframe_lazyload = $this->replaceYoutubeThumbnail( $iframe );
}

Expand Down Expand Up @@ -234,4 +234,27 @@ public function cleanYoutubeUrl( $url ) {

return $scheme . $host . $path;
}

/**
* Checks if a youtube thumbnail is excluded from lazyload.
*
* @param array $iframe Array of matched patterns.
* @return boolean
*/
private function is_youtube_excluded( array $iframe ): bool {
/**
* Filters the patterns excluded from lazyload for youtube thumbnails.
*
* @param array $excluded_patterns Array of excluded patterns.
*/
$excluded_patterns = apply_filters( 'rocket_lazyload_exclude_youtube_thumbnail', [] );

foreach ( $excluded_patterns as $excluded_pattern ) {
if ( strpos( $iframe[0], $excluded_pattern ) !== false ) {
return true;
}
}

return false;
}
}
Loading