• Jon

    (@freshyjon)


    I don’t exactly know when this started occuring, since I didn’t cross-check the version with a particular date, but it seems that Vimeo oEmbed players are now being given a dnt=1 parameter on the Vimeo player’s iframe source URL. This is causing an issue that may have been overlooked.

    If there are numerious Vimeo videos embedded on the page, previously (by default), Vimeo would only allow one of those video to play at a time. If a user played one video — then started playing another video — it would then pause the previous video that as playing. Again, this is default Vimeo behavior. However, when the Vimeo URL has the parameter of dnt=1 on the URL, it causes that default behavior to be overridden. Therefore, it allows the user to play multiple videos at once (which is NOT default behavior, and is arguably not very “Accessible friendly”.

    Digging into the code, I see that it’s likely this following function from class-wp-oembed.php that’s the culprit. Is there a way to override this function, with something in the child theme? If not, it seems I’d be forced to either:

    1. replace URLs with jQuery
    2. embed the Vimeo videos with an iframe code, instead of the oEmbed feature

    Ideally, this would be looked in to further, since it nows overrides default/expected Vimeo behavior.

    	/**
    	 * Connects to a oEmbed provider and returns the result.
    	 *
    	 * @since 2.9.0
    	 *
    	 * @param string       $provider The URL to the oEmbed provider.
    	 * @param string       $url      The URL to the content that is desired to be embedded.
    	 * @param array|string $args     Optional. Arguments, usually passed from a shortcode. Default empty.
    	 * @return object|false The result in the form of an object on success, false on failure.
    	 */
    	public function fetch( $provider, $url, $args = '' ) {
    		$args = wp_parse_args( $args, wp_embed_defaults( $url ) );
    
    		$provider = add_query_arg( 'maxwidth', (int) $args['width'], $provider );
    		$provider = add_query_arg( 'maxheight', (int) $args['height'], $provider );
    		$provider = add_query_arg( 'url', urlencode( $url ), $provider );
    		$provider = add_query_arg( 'dnt', 1, $provider );
    
    		/**
    		 * Filters the oEmbed URL to be fetched.
    		 *
    		 * @since 2.9.0
    		 * @since 4.9.0 The <code>dnt</code> (Do Not Track) query parameter was added to all oEmbed provider URLs.
    		 *
    		 * @param string $provider URL of the oEmbed provider.
    		 * @param string $url      URL of the content to be embedded.
    		 * @param array  $args     Optional arguments, usually passed from a shortcode.
    		 */
    		$provider = apply_filters( 'oembed_fetch_url', $provider, $url, $args );
    
    		foreach ( array( 'json', 'xml' ) as $format ) {
    			$result = $this->_fetch_with_format( $provider, $format );
    			if ( is_wp_error( $result ) && 'not-implemented' == $result->get_error_code() ) {
    				continue;
    			}
    			return ( $result && ! is_wp_error( $result ) ) ? $result : false;
    		}
    		return false;
    	}
    • This topic was modified 4 years ago by Jan Dembowski. Reason: Moved to Fixing WordPress, this is not a Requests and Feedback topic
Viewing 9 replies - 1 through 9 (of 9 total)
  • Thread Starter Jon

    (@freshyjon)

    For now, I’m using jQuery to remove that parameter from the src. I’m sure there’s a better way though…

    <script>
    	// replace the dnt=1 parameter that WordPress adds to the Vimeo player when using oEmbed
    	jQuery(document).ready(function($){
    		// find any Vimeo iframe
    		$('iframe[src*="player.vimeo.com"]').each(function(){
    			// get the src
    			var src = $(this).attr('src');
    			// replace parameters with nothing
    			$(this).attr('src',src.replace('dnt=1&', ''));
    		});
    	});
    </script>

    dnt = “do not track”

    How did you determine that parameter has something to do with simultaneously playing videos embedded on the same page?

    Fwiw, this may be a lead on a better solution …

    https://core.trac.wordpress.org/changeset/41345

    … to make a change in your site’s WP core

    Thread Starter Jon

    (@freshyjon)

    I determined the parameter was responsible for the issue, by banging my head a few times, and removing various parameters from the URL to test. I happened to narrow it down to the dnt=1 parameter. As mentioned, when removing it, the videos are handled as expected. I think it should be removed from core, with some sort of filter to add if desired.

    Interesting that a parameter designed to tell vimeo to not track plays impacted simultaneous playing. Anyway, I agree. Would be best to remove dnt=1 from the core and add an option in settings to add it and set the value.

    Thread Starter Jon

    (@freshyjon)

    My guess is that, by adding dnt=1, that Vimeo is no longer able to tell if you are already playing a Vimeo video in the same browser/tab/session… so it isn’t able to pause the other one before playing the new one.

    I had this issue a while ago. The fix was adding this to the child theme’s functions.php:

    function custom_remove_embed_url_dnt($provider, $url, $args){
    return add_query_arg( array(‘dnt’ => false), $provider );
    }
    add_filter(‘oembed_fetch_url’, ‘custom_remove_embed_url_dnt’, 10, 3);`

    I think that’s cleaner than jQuery or anything else I could think of.

    Here is the copyable code per Joao’s recommendation but I added a filter to only do this to Vimeo Videos.

    function dl_oembed ( $provider, $url, $args ) {
      if ( strpos( $provider, 'vimeo.com' ) !== false)
        return add_query_arg( array(‘dnt’ => false), $provider );
    }
    add_filter( 'oembed_fetch_url', 'dl_oembed', 10, 3 );
    Freshy

    (@freshysites)

    @jonroc804 I think you need to fix the single quotes around the dnt

    Even with this code and dnt is removed, Vimeo does not save the video progress. Is this normal? Does somebody know if I need to add anything else to achieve that?

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Vimeo oEmbed now has dnt=1 parameter’ is closed to new replies.