WP YouTube Lyte - Version 1.7.11

Version Description

  • fix playlist that got broken due to the priority change (from 4 to 10)
  • add is_amp (and is_feed) checks to the new lyte_prepare function (which runs at priority 4)
Download this release

Release Info

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

Code changes from version 1.7.10 to 1.7.11

Files changed (2) hide show
  1. readme.txt +5 -1
  2. wp-youtube-lyte.php +27 -24
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: 5.3
7
- Stable tag: 1.7.10
8
 
9
  High performance YouTube video, playlist and audio-only embeds which don't slow down your blog and offer optimal accessibility.
10
 
@@ -135,6 +135,10 @@ Just tell me, I like the feedback! Use the [Contact-page on my blog](http://blog
135
 
136
  == Changelog ==
137
 
 
 
 
 
138
  = 1.7.10 =
139
  * fix regression for YouTube embed WordPress block (https://wordpress.org/support/topic/errors-caused-by-upgrading-to-version-1-7-9/) due to changed priority in 1.7.9.
140
 
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: 5.3
7
+ Stable tag: 1.7.11
8
 
9
  High performance YouTube video, playlist and audio-only embeds which don't slow down your blog and offer optimal accessibility.
10
 
135
 
136
  == Changelog ==
137
 
138
+ = 1.7.11 =
139
+ * fix playlist that got broken due to the priority change (from 4 to 10)
140
+ * add is_amp (and is_feed) checks to the new lyte_prepare function (which runs at priority 4)
141
+
142
  = 1.7.10 =
143
  * fix regression for YouTube embed WordPress block (https://wordpress.org/support/topic/errors-caused-by-upgrading-to-version-1-7-9/) due to changed priority in 1.7.9.
144
 
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.10
8
  Author URI: http://blog.futtta.be/
9
  Text Domain: wp-youtube-lyte
10
  Domain Path: /languages
@@ -13,7 +13,7 @@ Domain Path: /languages
13
  if ( ! defined( 'ABSPATH' ) ) exit;
14
 
15
  $debug=false;
16
- $lyte_version="1.7.10";
17
  $lyte_db_version=get_option('lyte_version','none');
18
 
19
  /** have we updated? */
@@ -81,11 +81,8 @@ function lyte_settings_enforcer() {
81
  add_action('after_setup_theme','lyte_settings_enforcer');
82
 
83
  function lyte_parse($the_content,$doExcerpt=false) {
84
- /** bail if amp */
85
- if ( is_amp()) { return str_replace( 'httpv://', 'https://', $the_content ); }
86
-
87
- /** bail if LYTE feed disabled and is_feed */
88
- if ( apply_filters( 'lyte_filter_dofeed', true ) === false && is_feed() ) { return str_replace( 'httpv://', 'https://', $the_content ); }
89
 
90
  /** main function to parse the content, searching and replacing httpv-links */
91
  global $lyteSettings, $toCache_index, $postID, $cachekey;
@@ -94,20 +91,13 @@ function lyte_parse($the_content,$doExcerpt=false) {
94
  $origin=$urlArr['scheme']."://".$urlArr['host'];
95
 
96
  /** API: filter hook to preparse the_content, e.g. to force normal youtube links to be parsed */
97
- $the_content = apply_filters( 'lyte_content_preparse',$the_content );
98
-
99
- if ( get_option('lyte_greedy','1')==="1" && strpos($the_content,"youtu") !== false ){
100
- // only preg_replace if "youtu" (as part of youtube.com or youtu.be) is found
101
- if (strpos($the_content,'/playlist?list=') !== false ) {
102
- // only preg_replace for playlists if there are playlists to be parsed
103
- $the_content=preg_replace('/^(?:<p>)?https?:\/\/(www.)?youtu(be.com|.be)\/playlist\?list=/m','httpv://www.youtube.com/playlist?list=',$the_content);
104
- }
105
- $the_content=preg_replace('/^(?:<p>)?https?:\/\/(www.)?youtu(be.com|.be)\/(watch\?v=)?/m','httpv://www.youtube.com/watch?v=',$the_content);
106
 
 
107
  // new: also replace original YT embed code (iframes)
108
- if ( apply_filters( 'lyte_eats_yframes', true ) && preg_match_all('#<iframe(?:[^<]*)?\ssrc=["|\']https:\/\/www\.youtube(?:-nocookie)?\.com\/embed\/(.*)["|\'](?:.*)><\/iframe>#Usm', $the_content, $matches, PREG_SET_ORDER)) {
109
- foreach ($matches as $match) {
110
- $the_content = str_replace($match[0], 'httpv://youtu.be/'.$match[1], $the_content);
111
  }
112
  }
113
  }
@@ -730,8 +720,12 @@ if (!function_exists("is_amp")) {
730
  }
731
  }
732
 
733
- function lyte_do_gutenberg( $the_content ) {
734
- if ( strpos( $the_content, "<!-- wp:" ) !== false && strpos( $the_content, "youtu" ) !== false ) {
 
 
 
 
735
  /*
736
  * do Gutenberg stuff here, playlists if needed first and then single videos
737
  *
@@ -748,6 +742,17 @@ function lyte_do_gutenberg( $the_content ) {
748
  $gutenbeard_single_regex = '%<\!--\s?wp:(?:core[-|/])?embed(?:/youtube)?\s?{"url":"https?://(?:www\.)?youtu(?:be\.com/watch\?v=|.be/)(.*)"(?:.*)?}\s?-->.*(?:<figcaption>(.*)</figcaption>)?<\!--\s?/wp:(?:core[-|/])?embed(?:/youtube)?\s?-->%Us';
749
  $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);
750
  }
 
 
 
 
 
 
 
 
 
 
 
751
  return $the_content;
752
  }
753
 
@@ -756,9 +761,7 @@ if ( is_admin() ) {
756
  require_once(dirname(__FILE__).'/options.php');
757
  add_filter( 'plugin_action_links_' . plugin_basename(__FILE__), 'lyte_add_action_link' );
758
  } else {
759
- if ( apply_filters( 'lyte_filter_do_gutenberg', true ) ) {
760
- add_filter('the_content', 'lyte_do_gutenberg', 4);
761
- }
762
  add_filter('the_content', 'lyte_parse', 10);
763
  add_shortcode("lyte", "shortcode_lyte");
764
  remove_filter('get_the_excerpt', 'wp_trim_excerpt');
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.11
8
  Author URI: http://blog.futtta.be/
9
  Text Domain: wp-youtube-lyte
10
  Domain Path: /languages
13
  if ( ! defined( 'ABSPATH' ) ) exit;
14
 
15
  $debug=false;
16
+ $lyte_version="1.7.11";
17
  $lyte_db_version=get_option('lyte_version','none');
18
 
19
  /** have we updated? */
81
  add_action('after_setup_theme','lyte_settings_enforcer');
82
 
83
  function lyte_parse($the_content,$doExcerpt=false) {
84
+ /** bail if AMP or if LYTE feed disabled and is_feed */
85
+ if ( is_amp() || ( apply_filters( 'lyte_filter_dofeed', true ) === false && is_feed() ) ) { return str_replace( 'httpv://', 'https://', $the_content ); }
 
 
 
86
 
87
  /** main function to parse the content, searching and replacing httpv-links */
88
  global $lyteSettings, $toCache_index, $postID, $cachekey;
91
  $origin=$urlArr['scheme']."://".$urlArr['host'];
92
 
93
  /** API: filter hook to preparse the_content, e.g. to force normal youtube links to be parsed */
94
+ $the_content = apply_filters( 'lyte_content_preparse', $the_content );
 
 
 
 
 
 
 
 
95
 
96
+ if ( get_option( 'lyte_greedy', '1' ) === "1" && strpos( $the_content, "youtu" ) !== false ){
97
  // new: also replace original YT embed code (iframes)
98
+ if ( apply_filters( 'lyte_eats_yframes', true ) && preg_match_all( '#<iframe(?:[^<]*)?\ssrc=["|\']https:\/\/www\.youtube(?:-nocookie)?\.com\/embed\/(.*)["|\'](?:.*)><\/iframe>#Usm', $the_content, $matches, PREG_SET_ORDER ) ) {
99
+ foreach ( $matches as $match ) {
100
+ $the_content = str_replace( $match[0], 'httpv://youtu.be/'.$match[1], $the_content );
101
  }
102
  }
103
  }
720
  }
721
  }
722
 
723
+ function lyte_prepare( $the_content ) {
724
+ /** bail if AMP or if LYTE feed disabled and is_feed */
725
+ if ( is_amp() || ( apply_filters( 'lyte_filter_dofeed', true ) === false && is_feed() ) ) { return str_replace( 'httpv://', 'https://', $the_content ); }
726
+
727
+ // catch gutenberg blocks before being rendered.
728
+ if ( apply_filters( 'lyte_filter_do_gutenberg', true ) && strpos( $the_content, "<!-- wp:" ) !== false && strpos( $the_content, "youtu" ) !== false ) {
729
  /*
730
  * do Gutenberg stuff here, playlists if needed first and then single videos
731
  *
742
  $gutenbeard_single_regex = '%<\!--\s?wp:(?:core[-|/])?embed(?:/youtube)?\s?{"url":"https?://(?:www\.)?youtu(?:be\.com/watch\?v=|.be/)(.*)"(?:.*)?}\s?-->.*(?:<figcaption>(.*)</figcaption>)?<\!--\s?/wp:(?:core[-|/])?embed(?:/youtube)?\s?-->%Us';
743
  $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);
744
  }
745
+
746
+ // do the most of the greedy part early.
747
+ if ( get_option( 'lyte_greedy', '1' ) === "1" && strpos( $the_content, "youtu" ) !== false ){
748
+ // only preg_replace if "youtu" (as part of youtube.com or youtu.be) is found.
749
+ if ( strpos( $the_content, '/playlist?list=' ) !== false ) {
750
+ // only preg_replace for playlists if there are playlists to be parsed.
751
+ $the_content = preg_replace( '/^(?:<p>)?https?:\/\/(www.)?youtu(be.com|.be)\/playlist\?list=/m', 'httpv://www.youtube.com/playlist?list=', $the_content );
752
+ }
753
+ // and lastly normal single embeds.
754
+ $the_content = preg_replace( '/^(?:<p>)?https?:\/\/(www.)?youtu(be.com|.be)\/(watch\?v=)?/m', 'httpv://www.youtube.com/watch?v=', $the_content );
755
+ }
756
  return $the_content;
757
  }
758
 
761
  require_once(dirname(__FILE__).'/options.php');
762
  add_filter( 'plugin_action_links_' . plugin_basename(__FILE__), 'lyte_add_action_link' );
763
  } else {
764
+ add_filter('the_content', 'lyte_prepare', 4);
 
 
765
  add_filter('the_content', 'lyte_parse', 10);
766
  add_shortcode("lyte", "shortcode_lyte");
767
  remove_filter('get_the_excerpt', 'wp_trim_excerpt');