Viper's Video Quicktags
Found a bug causing YouTube videos to not display (2 posts)

  1. Jon Jennings
    Posted 4 years ago #

    A client updated her site this weekend & emailed me to say that YouTube videos weren't displaying any more. She's seeing "[ERROR: Unable to parse URL, check for correct YouTube format]" messages where the video should be. Looks like a couple of other people might be having the same problem.

    I located the bug, but haven't fixed it. The faulty code is:

    // Short youtu.be URL
    			elseif ( FALSE !== stristr( $content, 'youtu.be' ) ) {
    				preg_match( '#https?://youtu\.be/([\w-]+)#i', $content, $matches );
    				if ( empty($matches) || empty($matches[1]) )
    					return $this->error( sprintf( __('Unable to parse URL, check for correct %s format', 'vipers-video-quicktags'), __('YouTube') ) );
    				$embedpath = 'v/' . $matches[1];
    				$fallbacklink = 'http://www.youtube.com/watch?v=' . $matches[1];
    				$fallbackcontent = '<img src="http://img.youtube.com/vi/' . $matches[1] . '/0.jpg" alt="' . __('YouTube Preview Image', 'vipers-video-quicktags') . '" />';

    This looks for any URL that includes the characters "youtu.be" and assumes that it's using the YouTube URL shortcode. It then parses the URL assuming that it begins "http://youtu.be...".

    But if you have an URL that ISN'T using the YouTube shortcode but DOES include the characters "youtu.be" somewhere else, it'll fail.

    My client had URLs like http://www.youtube.com/watch?v=HxKOfGpdFkM&feature=youtu.be

    For now, the easiest way to fix your sites is to strip off the attribute in the URL that uses youtu.be and resave the posts.


  2. Jon Jennings
    Posted 4 years ago #

    I think a quick & easy way to fix this is to change the elseif line to

    elseif ( FALSE !== stristr( $content, '//youtu.be' ) ) {

    This works because youtu.be shortcode URLs never have www on the front. So now we're only entering the conditional clause if the host portion of the URL starts with youtu.be - an instance of 'youtu.be' later on in the URL won't confuse us.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic