WP YouTube Lyte - Version 1.7.5

Version Description

  • improvement: also act on YouTube iframe code if "also act on YouTube links" is on.
  • improvement: if extracted from Gutenburg YouTube embed blocks keep the figure-tag with all relevant CSS classes and keep the caption (if set).
Download this release

Release Info

Developer futtta
Plugin Icon 128x128 WP YouTube Lyte
Version 1.7.5
Comparing to
See all releases

Code changes from version 1.7.4 to 1.7.5

Files changed (3) hide show
  1. options.php +2 -2
  2. readme.txt +8 -5
  3. wp-youtube-lyte.php +16 -6
options.php CHANGED
@@ -253,7 +253,7 @@ function lyte_settings_page() {
253
  </td>
254
  </tr>
255
  <tr valign="top">
256
- <th scope="row"><?php _e("Also act on normal YouTube links?","wp-youtube-lyte") ?></th>
257
  <td>
258
  <fieldset>
259
  <legend class="screen-reader-text"><span><?php _e("Also act on normal YouTube links?","wp-youtube-lyte") ?></span></legend>
@@ -263,7 +263,7 @@ function lyte_settings_page() {
263
  </td>
264
  </tr>
265
  <tr valign="top">
266
- <th scope="row"><?php _e("Cache thumbnails locally?","wp-youtube-lyte"); ?> (beta)</th>
267
  <td>
268
  <fieldset>
269
  <legend class="screen-reader-text"><span><?php _e("Cache thumbnails locally?","wp-youtube-lyte") ?></span></legend>
253
  </td>
254
  </tr>
255
  <tr valign="top">
256
+ <th scope="row"><?php _e("Also act on normal YouTube links and iframes?","wp-youtube-lyte") ?></th>
257
  <td>
258
  <fieldset>
259
  <legend class="screen-reader-text"><span><?php _e("Also act on normal YouTube links?","wp-youtube-lyte") ?></span></legend>
263
  </td>
264
  </tr>
265
  <tr valign="top">
266
+ <th scope="row"><?php _e("Cache thumbnails locally?","wp-youtube-lyte"); ?></th>
267
  <td>
268
  <fieldset>
269
  <legend class="screen-reader-text"><span><?php _e("Cache thumbnails locally?","wp-youtube-lyte") ?></span></legend>
readme.txt CHANGED
@@ -4,7 +4,7 @@ Tags: youtube, video, performance, gdpr, lazy load
4
  Donate link: http://blog.futtta.be/2013/10/21/do-not-donate-to-me/
5
  Requires at least: 4.0
6
  Tested up to: 4.9
7
- Stable tag: 1.7.4
8
 
9
  High performance YouTube video, playlist and audio-only embeds which don't slow down your blog and offer optimal accessibility.
10
 
@@ -77,7 +77,7 @@ Just enter "none" (without the quotes) in the API key field and Lyte will stop n
77
  As opposed to some of the [most important](http://blog.futtta.be/2010/12/15/wordpress-com-stats-trojan-horse-for-quantcast-tracking/) [plugins](http://blog.futtta.be/2010/01/22/add-to-any-removed-from-here/) there is no 3rd party tracking code in WP YouTube Lyte, but YouTube off course does see visitor requests coming in for the thumbnails unless the option to cache thumbnails locally is enabled. If thumbnails are cached locally, no request will be sent to YouTube by your visitor's browser until/ unless the video is played.
78
 
79
  = I use a page builder and LYTE does not seem active on the YouTube video's I add there? =
80
- LYTE by default uses WordPress' "the_content"-filter. Page builders don't apply that filter to their content and thus LYTE does not get triggered on those. As a workaround you can either add the LYTE video using the shortcode in your page-builder Text-block or use the LYTE widget (selecting one of the bigger widget sizes), this works in most page-builders.
81
 
82
  = Can I use WP YouTube Lyte for a custom field? =
83
  Just pass the httpv url of such a field to lyte_preparse like this:
@@ -101,8 +101,8 @@ In January 2014 [Benetech](http://benetech.org/), a U.S. nonprofit that develops
101
  * Widgets are not responsive.
102
  * if the content div width gets to around 200 pixels, the LYTE UI will become garbled (YouTube requires the minimum embed width to be 200px as well).
103
 
104
- = Can I use WP YouTube Lyte on normal YouTube links? =
105
- Yes, starting with version 1.5.0 normal YouTube links are automatically transferred in Lyte embeds as well. You will automagically also get a (non-Lyte) preview of the video in your visual post edit screen.
106
 
107
  = What can I do with the API? =
108
  A whole lot; there are filters to pre-parse the_content, to change settings, to change the CSS, to change the HTML of the LYTE-div, ... There are examples for all filters (and one action) in lyte_helper.php_example
@@ -124,7 +124,6 @@ function lyte_on_mobile(){
124
  `
125
 
126
  = Any other issues should I know about? =
127
- * Although the widget is available in (very) small sizes, these do not display that great and might, in the near future, be disabled by YouTube as their Terms of Service state that the smallest available embedded player is 200X200 pixels. Use the deprecated smaller sizes at your own risk.
128
  * Having the same YouTube-video on one page can cause WP YouTube Lyte to malfunction (as the YouTube id is used as the div's id in the DOM, and DOM id's are supposed to be unique)
129
 
130
  = I found a bug/ I would like a feature to be added! =
@@ -137,6 +136,10 @@ Just tell me, I like the feedback! Use the [Contact-page on my blog](http://blog
137
 
138
  == Changelog ==
139
 
 
 
 
 
140
  = 1.7.4 =
141
  * improvement: make sure locally cached thumbnails are served with good HTTP response headers (allowing HTTP 304 responses and allowing images to be cached in browser).
142
  * improvemnet: bigger widget sizes for use in pagebuilders.
4
  Donate link: http://blog.futtta.be/2013/10/21/do-not-donate-to-me/
5
  Requires at least: 4.0
6
  Tested up to: 4.9
7
+ Stable tag: 1.7.5
8
 
9
  High performance YouTube video, playlist and audio-only embeds which don't slow down your blog and offer optimal accessibility.
10
 
77
  As opposed to some of the [most important](http://blog.futtta.be/2010/12/15/wordpress-com-stats-trojan-horse-for-quantcast-tracking/) [plugins](http://blog.futtta.be/2010/01/22/add-to-any-removed-from-here/) there is no 3rd party tracking code in WP YouTube Lyte, but YouTube off course does see visitor requests coming in for the thumbnails unless the option to cache thumbnails locally is enabled. If thumbnails are cached locally, no request will be sent to YouTube by your visitor's browser until/ unless the video is played.
78
 
79
  = I use a page builder and LYTE does not seem active on the YouTube video's I add there? =
80
+ LYTE by default uses WordPress' "the_content"-filter. Page builders don't apply that filter to their content and thus LYTE does not get triggered on those. As a workaround you can either add the LYTE widget or add the LYTE video using the shortcode in your page-builder Text-block, this works in most page-builders.
81
 
82
  = Can I use WP YouTube Lyte for a custom field? =
83
  Just pass the httpv url of such a field to lyte_preparse like this:
101
  * Widgets are not responsive.
102
  * if the content div width gets to around 200 pixels, the LYTE UI will become garbled (YouTube requires the minimum embed width to be 200px as well).
103
 
104
+ = Can I use WP YouTube Lyte on normal YouTube links or iframes? =
105
+ Yes, starting with version 1.5.0 normal YouTube links are automatically transferred in Lyte embeds as well. You will automagically also get a (non-Lyte) preview of the video in your visual post edit screen. Starting from LYTE 1.7.5 YouTube iframes can be automatically converted as well.
106
 
107
  = What can I do with the API? =
108
  A whole lot; there are filters to pre-parse the_content, to change settings, to change the CSS, to change the HTML of the LYTE-div, ... There are examples for all filters (and one action) in lyte_helper.php_example
124
  `
125
 
126
  = Any other issues should I know about? =
 
127
  * Having the same YouTube-video on one page can cause WP YouTube Lyte to malfunction (as the YouTube id is used as the div's id in the DOM, and DOM id's are supposed to be unique)
128
 
129
  = I found a bug/ I would like a feature to be added! =
136
 
137
  == Changelog ==
138
 
139
+ = 1.7.5 =
140
+ * improvement: also act on YouTube iframe code if "also act on YouTube links" is on.
141
+ * improvement: if extracted from Gutenburg YouTube embed blocks keep the figure-tag with all relevant CSS classes and keep the caption (if set).
142
+
143
  = 1.7.4 =
144
  * improvement: make sure locally cached thumbnails are served with good HTTP response headers (allowing HTTP 304 responses and allowing images to be cached in browser).
145
  * improvemnet: bigger widget sizes for use in pagebuilders.
wp-youtube-lyte.php CHANGED
@@ -4,7 +4,7 @@ Plugin Name: WP YouTube Lyte
4
  Plugin URI: http://blog.futtta.be/wp-youtube-lyte/
5
  Description: Lite and accessible YouTube audio and video embedding.
6
  Author: Frank Goossens (futtta)
7
- Version: 1.7.4
8
  Author URI: http://blog.futtta.be/
9
  Text Domain: wp-youtube-lyte
10
  Domain Path: /languages
@@ -100,6 +100,13 @@ function lyte_parse($the_content,$doExcerpt=false) {
100
  $the_content=preg_replace('/^https?:\/\/(www.)?youtu(be.com|.be)\/playlist\?list=/m','httpv://www.youtube.com/playlist?list=',$the_content);
101
  }
102
  $the_content=preg_replace('/^https?:\/\/(www.)?youtu(be.com|.be)\/(watch\?v=)?/m','httpv://www.youtube.com/watch?v=',$the_content);
 
 
 
 
 
 
 
103
  }
104
 
105
  if ( strpos($the_content,"<!-- wp:") !== false && strpos($the_content,"youtu") !== false ) {
@@ -113,11 +120,11 @@ function lyte_parse($the_content,$doExcerpt=false) {
113
  * https://media1.giphy.com/media/l2QZTNMFTQ2Z00zHG/giphy.gif
114
  */
115
  if (strpos($the_content,'/playlist?list=') !== false ) {
116
- $gutenbeard_playlist_regex = '%<\!--\s?wp:(?:core[-|/])?embed(?:/youtube)?\s?{"url":"https://www.youtube.com/playlist\?list=(.*)"}\s?-->.*<\!--\s?/wp:(?:core[-|/])?embed(?:/youtube)?\s?-->%Us';
117
- $the_content = preg_replace($gutenbeard_playlist_regex, 'httpv://www.youtube.com/playlist?list=\1',$the_content);
118
  }
119
- $gutenbeard_single_regex = '%<\!--\s?wp:(?:core[-|/])?embed(?:/youtube)?\s?{"url":"https?://(?:www\.)?youtu(?:be\.com|.be)/(?:watch\?v=)?(.*)"}\s?-->.*<\!--\s?/wp:(?:core[-|/])?embed(?:/youtube)?\s?-->%Us';
120
- $the_content = preg_replace($gutenbeard_single_regex, 'httpv://www.youtube.com/watch?v=\1',$the_content);
121
  }
122
 
123
  if((strpos($the_content, "httpv")!==FALSE)||(strpos($the_content, "httpa")!==FALSE)) {
@@ -239,7 +246,10 @@ function lyte_parse($the_content,$doExcerpt=false) {
239
  }
240
 
241
  // add disclaimer to lytelinks
242
- $disclaimer = '<span class="lyte_disclaimer">' . wp_kses_data( get_option( 'lyte_disclaimer', '') ) . '</span>';
 
 
 
243
 
244
  if ( $disclaimer && empty( $lytelinks_txt ) ) {
245
  $lytelinks_txt = "<div class=\"lL\" style=\"max-width:100%;width:".$lyteSettings[2]."px;".$lyteSettings['pos']."\">".$diclaimer."</div>";
4
  Plugin URI: http://blog.futtta.be/wp-youtube-lyte/
5
  Description: Lite and accessible YouTube audio and video embedding.
6
  Author: Frank Goossens (futtta)
7
+ Version: 1.7.5
8
  Author URI: http://blog.futtta.be/
9
  Text Domain: wp-youtube-lyte
10
  Domain Path: /languages
100
  $the_content=preg_replace('/^https?:\/\/(www.)?youtu(be.com|.be)\/playlist\?list=/m','httpv://www.youtube.com/playlist?list=',$the_content);
101
  }
102
  $the_content=preg_replace('/^https?:\/\/(www.)?youtu(be.com|.be)\/(watch\?v=)?/m','httpv://www.youtube.com/watch?v=',$the_content);
103
+
104
+ // new: also replace original YT embed code (iframes)
105
+ if ( apply_filters( 'lyte_eats_yframes', true ) && preg_match_all('#<iframe(?:.*)?\ssrc=["|\']https:\/\/www\.youtube\.com\/embed\/(.*)["|\']\s(?:.*)><\/iframe>#Usm', $the_content, $matches, PREG_SET_ORDER)) {
106
+ foreach ($matches as $match) {
107
+ $the_content = str_replace($match[0], 'httpv://youtu.be/'.$match[1], $the_content);
108
+ }
109
+ }
110
  }
111
 
112
  if ( strpos($the_content,"<!-- wp:") !== false && strpos($the_content,"youtu") !== false ) {
120
  * https://media1.giphy.com/media/l2QZTNMFTQ2Z00zHG/giphy.gif
121
  */
122
  if (strpos($the_content,'/playlist?list=') !== false ) {
123
+ $gutenbeard_playlist_regex = '%<\!--\s?wp:(?:core[-|/])?embed(?:/youtube)?\s?{"url":"https://www.youtube.com/playlist\?list=(.*)"}\s?-->.*<figcaption>(.*)</figcaption><\!--\s?/wp:(?:core[-|/])?embed(?:/youtube)?\s?-->%Us';
124
+ $the_content = preg_replace($gutenbeard_playlist_regex, '<figure class="wp-block-embed-youtube wp-block-embed is-type-video is-provider-youtube">httpv://www.youtube.com/playlist?list=\1<figcaption>\2</figcaption></figure>',$the_content);
125
  }
126
+ $gutenbeard_single_regex = '%<\!--\s?wp:(?:core[-|/])?embed(?:/youtube)?\s?{"url":"https?://(?:www\.)?youtu(?:be\.com|.be)/(?:watch\?v=)?(.*)"}\s?-->.*<figcaption>(.*)</figcaption><\!--\s?/wp:(?:core[-|/])?embed(?:/youtube)?\s?-->%Us';
127
+ $the_content = preg_replace($gutenbeard_single_regex, '<figure class="wp-block-embed-youtube wp-block-embed is-type-video is-provider-youtube">httpv://www.youtube.com/watch?v=\1<figcaption>\2</figcaption></figure>',$the_content);
128
  }
129
 
130
  if((strpos($the_content, "httpv")!==FALSE)||(strpos($the_content, "httpa")!==FALSE)) {
246
  }
247
 
248
  // add disclaimer to lytelinks
249
+ $disclaimer = wp_kses_data( get_option( 'lyte_disclaimer', '') );
250
+ if ( !empty( $disclaimer ) ) {
251
+ $disclaimer = '<span class="lyte_disclaimer">' . $disclaimer . '</span>';
252
+ }
253
 
254
  if ( $disclaimer && empty( $lytelinks_txt ) ) {
255
  $lytelinks_txt = "<div class=\"lL\" style=\"max-width:100%;width:".$lyteSettings[2]."px;".$lyteSettings['pos']."\">".$diclaimer."</div>";