Support » Plugin: Featured Video Plus » Fix for WordPress 4.4.2 for YouTube Video Error

  • Resolved tannem9

    (@tannem9)


    Hello, My name is Marc Tanne. My co-developer and I have used this plugin and developed a fix for the YouTube error. In essence, WP 4.4 changed the way the src was structured. Please replace the code specified below in your class-oembed.php file located under:

    SiteName/wp-content/plugins/featured-video-plus/php/class-oembed.php

    where it says public function get_html{} delete this entire function and place the code below in it’s place:

    public function get_html( $url, $args = array(), $provider = null ) {
    		if ( $provider ) {
    			$args = $this->filter_legal_args( $provider, $args );
    		}
    
    		$html = $this->oembed->get_html( $url, $args );
    
    		if ( empty( $provider ) ) {
    			return $html;
    		}
    
    		// Some providers do not provide it's player API to oEmbed requests,
    		// therefore the plugin needs to manually interfere with their iframe's
    		// source URL..
    		switch ( $provider ) {
    
    			// YouTube.com
    			case 'youtube':
    				// Add <code>origin</code> paramter.
    				$args['origin'] = urlencode( get_bloginfo( 'url' ) );
    
    				// The loop parameter does not work with single videos if there is no
    				// playlist defined. Workaround: Set playlist to video itself.
    				// @see https://developers.google.com/youtube/player_parameters#loop-supported-players
    				if ( ! empty( $args['loop'] ) && $args['loop'] ) {
    					$args['playlist'] = $this->get_youtube_video_id( $url );
    				}
    
    				// Remove fullscreen button manually because the YouTube API
    				//  does not care about <code>&fs=0</code>.
    				if ( array_key_exists( 'fs', $args ) && $args['fs'] == 0 ) {
    					$html = str_replace( 'allowfullscreen', '', $html );
    				}
    
    				// We strip the 'feature=oembed' from the parameters because it breaks
    				// some parameters.
    				$hook = '?feature=oembed';
    				$html = str_replace( $hook, '', $html );
    				break;
    
    			// DailyMotion.com
    			case 'dailymotion':
    				$args = $this->translate_time_arg( $args );
    				break;
    		}
    
    		if ( ! empty( $args ) ) {
    			$pattern = "/src=([\"'])([^\"']*)[\"']/";
    			preg_match( $pattern, $html, $match );
    			if ( ! empty( $match[1] ) && ! empty( $match[2] ) ) {
    				$code = $this->clean_wp_embed($match[2]);
    				$replace = sprintf('src=$1%s$1', add_query_arg( $args, $code ) );
    				$html = preg_replace( $pattern, $replace, $html );
    			}
    		}
    
    		return $html;
    	}
    
    	public function clean_wp_embed($url)
    	{
    		$out = $url;
    
    		$out = preg_replace("/\?/","&",$out,1);
    		$out = preg_replace("/&/","?",$out,1);
    
    		return $out;
    	}

    https://wordpress.org/plugins/featured-video-plus/

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Fix for WordPress 4.4.2 for YouTube Video Error’ is closed to new replies.