Plugin Directory

Changeset 3090452


Ignore:
Timestamp:
05/22/2024 12:01:44 AM (20 months ago)
Author:
beleaf
Message:

Release 1.6.3

Location:
lazy-embed/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • lazy-embed/trunk/lazy-embed.php

    r3089815 r3090452  
    77 * Plugin URI: https://bitbucket.org/beleaf-au/lazy-embed/
    88 * 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.2
     9 * Version: 1.6.3
    1010 * Requires PHP: 7.1
    1111 * Requires at least: 6.2.0
     
    254254            $id = self::extractID($url);
    255255
    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;
    270284        }
    271285
     
    296310        }
    297311
     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
    298321        private static function thumbnailSize(): int
    299322        {
  • lazy-embed/trunk/readme.txt

    r3089815 r3090452  
    44Requires at least: 6.2.0
    55Tested up to: 6.4
    6 Stable tag: 1.6.2
     6Stable tag: 1.6.3
    77Requires PHP: 5.6
    88License: GPLv2 or later
     
    2727== Changelog ==
    2828
     29= 1.6.3 - 22/05/2024 =
     30Fix: Sometimes the maxresdefault thumbnail from youtube doesnt exist. If this is the case, use a smaller image as a fallback
     31
    2932= 1.6.2 - 21/05/2024 =
    30 Fix iframe lazy loading implementation
     33Fix: iframe lazy loading implementation
    3134
    3235= 1.6.1 - 21/05/2024 =
Note: See TracChangeset for help on using the changeset viewer.