Changeset 3090452
- Timestamp:
- 05/22/2024 12:01:44 AM (20 months ago)
- Location:
- lazy-embed/trunk
- Files:
-
- 2 edited
-
lazy-embed.php (modified) (3 diffs)
-
readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
lazy-embed/trunk/lazy-embed.php
r3089815 r3090452 7 7 * Plugin URI: https://bitbucket.org/beleaf-au/lazy-embed/ 8 8 * Description: Improves the performance and reduces the emissions of your website by only loading embeds (youtube, vimeo, etc) when they are clicked. 9 * Version: 1.6. 29 * Version: 1.6.3 10 10 * Requires PHP: 7.1 11 11 * Requires at least: 6.2.0 … … 254 254 $id = self::extractID($url); 255 255 256 // We can request the youtube thumbnail using the image url. 257 // https://ourcodeworld.com/articles/read/1364/how-to-obtain-the-thumbnails-of-any-youtube-video 258 return !empty($id) 259 ? "https://img.youtube.com/vi/$id/maxresdefault.jpg" 260 : ''; 261 } 262 263 private static function dailymotionThumbnail(string $url): string 264 { 265 $id = self::extractID($url); 266 267 return !empty($id) 268 ? "https://www.dailymotion.com/thumbnail/video/$id" 269 : ''; 256 if(empty($id)) { 257 return ''; 258 } 259 260 // Sometimes the maxresdefault thumbnail at youtube does not get 261 // generated. Can be because the video is of low quality to begin 262 // with. To ensure we load the highest quality thumbnail, without 263 // occuring a performance overhead on each page load, on the first 264 // load, we make a query to youtube to find the largest available 265 // thumbnail, and then store that response in a transient 266 $transientName = 'lazy_embed_youtube_' . $id; 267 268 if ($url = get_transient($transientName)) { 269 return $url; 270 } 271 272 $maxresdefault = "https://img.youtube.com/vi/$id/maxresdefault.jpg"; 273 $hqdefault = "https://img.youtube.com/vi/$id/hqdefault.jpg"; 274 275 $response = wp_remote_get($maxresdefault); 276 277 if(wp_remote_retrieve_response_code($response) === 200) { 278 set_transient($transientName, $maxresdefault); 279 return $maxresdefault; 280 } 281 282 set_transient($transientName, $hqdefault); 283 return $hqdefault; 270 284 } 271 285 … … 296 310 } 297 311 312 private static function dailymotionThumbnail(string $url): string 313 { 314 $id = self::extractID($url); 315 316 return !empty($id) 317 ? "https://www.dailymotion.com/thumbnail/video/$id" 318 : ''; 319 } 320 298 321 private static function thumbnailSize(): int 299 322 { -
lazy-embed/trunk/readme.txt
r3089815 r3090452 4 4 Requires at least: 6.2.0 5 5 Tested up to: 6.4 6 Stable tag: 1.6. 26 Stable tag: 1.6.3 7 7 Requires PHP: 5.6 8 8 License: GPLv2 or later … … 27 27 == Changelog == 28 28 29 = 1.6.3 - 22/05/2024 = 30 Fix: Sometimes the maxresdefault thumbnail from youtube doesnt exist. If this is the case, use a smaller image as a fallback 31 29 32 = 1.6.2 - 21/05/2024 = 30 Fix iframe lazy loading implementation33 Fix: iframe lazy loading implementation 31 34 32 35 = 1.6.1 - 21/05/2024 =
Note: See TracChangeset
for help on using the changeset viewer.