'method_name', /** * This run on [embed] shortcode */ 'embed_oembed_html' => array( 'function_to_add' => 'get_embed', 'accepted_args' => 4, ), 'oembed_result' => array( 'function_to_add' => 'get_embed', 'accepted_args' => 3, ), 'wp_video_shortcode' => array( 'function_to_add' => 'get_video_shortcode', 'accepted_args' => 5, ), /** * @todo Future improvements */ // 'embed_defaults' => array( // 'function_to_add' => 'embed_defaults', // 'accepted_args' => 2, // ), ); } /** * A regex to search for youtube video * * @see WP_oEmbed::$providers in wp-includes/class-oembed.php for more regex * @see wp_video_shortcode() in wp-includes/media.php L#2428 * * @regex null */ // private $regex = '#https?://(www.)?youtube\.com/(?:v|embed)/([^/]+)#i'; private $regex = '#(?:v=|\/v\/|\.be\/)([a-zA-Z0-9_-]+)#i'; /** * Constructor */ function __construct() { Inline_Style::set( $this->get_asset( 'style' ) ); Inline_Script::set( $this->get_asset( 'script' ) ); } /** * Filters the default array of embed dimensions. * * @since 2.8.0 * * @see wp-includes/embed.php * * @param array $size An array of embed width and height values * in pixels (in that order). * @param string $url The URL that should be embedded. */ public function embed_defaults( $size, $url ) { return $size; } /** * Get embed * * @todo Problema con gli embed da link di siti WordPress, controllare $matches[1] * Provare con questa url nell'editor https://css-tricks.com/moving-to-https-on-wordpress/ * * @param string $value [description] * * @return string [description] */ public function get_embed( $cache, $url, $attr, $post_ID = null ) { return $this->get_video_html( $url, $cache ); } /** * Get embed * * @todo Problema con gli embed da link di siti WordPress, controllare $matches[1] * Provare con questa url nell'editor https://css-tricks.com/moving-to-https-on-wordpress/ * * @param string $output Video shortcode HTML output. * @param array $atts Array of video shortcode attributes. * @param string $video Video file. * @param int $post_id Post ID. * @param string $library Media library used for the video shortcode. * * @return string The video HTML output */ public function get_video_shortcode( $html, $atts, $video, $post_id, $library ) { if ( ! isset( $atts['src'] ) ) { return $html; } return $this->get_video_html( $atts['src'], $html ); } /** * Get the video HTML * * @param string $url The url of the video. * * @return string Return the video HTML for lazy load */ public function get_video_html( $url, $html ) { preg_match( $this->regex, $url, $matches ); if ( ! isset( $matches[1] ) ) { return $html; } $html = sprintf( '