From 0794d4bde321a3e2717df282d2c22aba28181c28 Mon Sep 17 00:00:00 2001 From: Raul Miller Date: Wed, 13 Feb 2019 11:11:27 -0500 Subject: [PATCH] Remove "dangerous" optimization: The removed code would prevent the player definition from being delivered to the page. The intent was to prevent redundant player definitions, but: 1) wordpress shortcode expansion does not mean that that expansion becomes a part of the currently constructed page. 2) inspecting a sample player definition suggests that if we put player definition a on the page, then player definition b on the page, then an further attempt to use player definition a would instead use definition b 3) but it's actually quite rare to have multiple video players on a page (so why are we optimizing for that case?), and 4) browsers heavily cache javascript (so this optimization should be of little benefit) Basically, if there's a real issue here, it should be addressed in the player definition itself. We're already over-optimized on the browser side. Removing this mechanism prevents the video player from failing (with an undefined error) in a [relatively] common case. --- jw-player/include/shortcode.php | 40 ++++----------------------------- 1 file changed, 4 insertions(+), 36 deletions(-) diff --git a/jw-player/include/shortcode.php b/jw-player/include/shortcode.php index 4dcfbf6..d0e12aa 100644 --- a/jw-player/include/shortcode.php +++ b/jw-player/include/shortcode.php @@ -3,7 +3,6 @@ // We use a global variable to keep track of all the players that are embedded // on a page. If multiple videos with the same player are embedded on the // same page the library only needs to be injected once. -$jwplayer_shortcode_embedded_players = array(); // Regular shortcode function. function jwplayer_shortcode_handle( $atts ) { @@ -185,19 +184,12 @@ function jwplayer_shortcode_filter_player_params( $atts ) { // Create the JS embed code for the jwplayer player function jwplayer_shortcode_create_js_embed( $media_hash, $player_hash = null, $params = array() ) { - global $jwplayer_shortcode_embedded_players; $player_hash = ( null === $player_hash ) ? get_option( 'jwplayer_player' ) : $player_hash; $content_mask = jwplayer_get_content_mask(); $protocol = ( is_ssl() && JWPLAYER_CONTENT_MASK === $content_mask ) ? 'https' : 'http'; - if ( in_array( $player_hash, $jwplayer_shortcode_embedded_players, true ) ) { - $player_script = ''; - } else { - // Injecting script tag because there's no way to properly enqueue a javascript - // at this point in the process :'-( - $player_script = true; - $jwplayer_shortcode_embedded_players[] = $player_hash; - } + // Injecting script tag because there's no way to properly enqueue a javascript + // at this point in the process :'-( if ( 'local' == $media_hash ) { $element_id = "jwplayer_" . wp_generate_password( 12, false ) . "_div"; @@ -243,8 +235,7 @@ function jwplayer_shortcode_create_js_embed( $media_hash, $player_hash = null, $ // Redeclare fitVids to stop it from breaking the JW Player embedding. if ( JWPLAYER_DISABLE_FITVIDS ) { - if ( $player_script ) { - return " + return "
"; - } else { // no player script - return " -
- - "; - } } else { - // no fitvids script here. - if ( $player_script ) { - return " + return "
"; - } else { // no player script - return " -
- - "; - } } }