Edit File by line
/home/zeestwma/richards.../wp-conte.../plugins/jetpack/modules/shortcod...
File: youtube.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* Youtube shortcode
[2] Fix | Delete
*
[3] Fix | Delete
* Contains shortcode + some improvements over the Core Embeds syntax (see http://codex.wordpress.org/Embeds )
[4] Fix | Delete
*
[5] Fix | Delete
* Examples:
[6] Fix | Delete
* [youtube https://www.youtube.com/watch?v=WVbQ-oro7FQ]
[7] Fix | Delete
* [youtube=http://www.youtube.com/watch?v=wq0rXGLs0YM&fs=1&hl=bg_BG&autohide=1&rel=0]
[8] Fix | Delete
* http://www.youtube.com/watch?v=H2Ncxw1xfck&w=320&h=240&fmt=1&rel=0&showsearch=1&hd=0
[9] Fix | Delete
* http://www.youtube.com/v/9FhMMmqzbD8?fs=1&hl=en_US
[10] Fix | Delete
* https://www.youtube.com/playlist?list=PLP7HaNDU4Cifov7C2fQM8Ij6Ew_uPHEXW
[11] Fix | Delete
*
[12] Fix | Delete
* @package automattic/jetpack
[13] Fix | Delete
*/
[14] Fix | Delete
[15] Fix | Delete
if ( ! defined( 'ABSPATH' ) ) {
[16] Fix | Delete
exit( 0 );
[17] Fix | Delete
}
[18] Fix | Delete
[19] Fix | Delete
/**
[20] Fix | Delete
* Replaces YouTube embeds with YouTube shortcodes.
[21] Fix | Delete
*
[22] Fix | Delete
* Covers the following formats:
[23] Fix | Delete
* 2008-07-15:
[24] Fix | Delete
* <object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/bZBHZT3a-FA&hl=en&fs=1"></param><param name="allowFullScreen" value="true"></param><embed src="http://www.youtube.com/v/bZBHZT3a-FA&hl=en&fs=1" type="application/x-shockwave-flash" allowfullscreen="true" width="425" height="344"></embed></object>
[25] Fix | Delete
* around 2008-06-06 youtube changed their old embed code to this:
[26] Fix | Delete
* <object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/M1D30gS7Z8U&hl=en"></param><embed src="http://www.youtube.com/v/M1D30gS7Z8U&hl=en" type="application/x-shockwave-flash" width="425" height="344"></embed></object>
[27] Fix | Delete
* old style was:
[28] Fix | Delete
* <object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/dGY28Qbj76A&rel=0"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/dGY28Qbj76A&rel=0" type="application/x-shockwave-flash" wmode="transparent" width="425" height="344"></embed></object>
[29] Fix | Delete
* 12-2010:
[30] Fix | Delete
* <object width="640" height="385"><param name="movie" value="http://www.youtube.com/v/3H8bnKdf654?fs=1&amp;hl=en_GB"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/3H8bnKdf654?fs=1&amp;hl=en_GB" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="640" height="385"></embed></object>
[31] Fix | Delete
* 01-2011:
[32] Fix | Delete
* <iframe title="YouTube video player" class="youtube-player" width="640" height="390" src="http://www.youtube.com/embed/Qq9El3ki0_g" frameborder="0" allowFullScreen></iframe>
[33] Fix | Delete
* <iframe class="youtube-player" width="640" height="385" src="http://www.youtube.com/embed/VIDEO_ID" frameborder="0"></iframe>
[34] Fix | Delete
*
[35] Fix | Delete
* @param string $content HTML content.
[36] Fix | Delete
* @return string The content with YouTube embeds replaced with YouTube shortcodes.
[37] Fix | Delete
*/
[38] Fix | Delete
function jetpack_youtube_embed_to_short_code( $content ) {
[39] Fix | Delete
if ( ! is_string( $content ) || ! str_contains( $content, 'youtube.com' ) ) {
[40] Fix | Delete
return $content;
[41] Fix | Delete
}
[42] Fix | Delete
[43] Fix | Delete
// older codes.
[44] Fix | Delete
$regexp = '!<object(.*?)>.*?<param\s+name=[\'"]movie[\'"]\s+value=[\'"](https?:)?//www\.youtube\.com/v/([^\'"]+)[\'"].*?>.*?</object>!i';
[45] Fix | Delete
$regexp_ent = htmlspecialchars( $regexp, ENT_NOQUOTES );
[46] Fix | Delete
$old_regexp = '!<embed(?:\s+\w+="[^"]*")*\s+src="https?(?:\:|&#0*58;)//www\.youtube\.com/v/([^"]+)"(?:\s+\w+="[^"]*")*\s*(?:/>|>\s*</embed>)!';
[47] Fix | Delete
$old_regexp_ent = str_replace( '&amp;#0*58;', '&amp;#0*58;|&#0*58;', htmlspecialchars( $old_regexp, ENT_NOQUOTES ) );
[48] Fix | Delete
[49] Fix | Delete
// new code.
[50] Fix | Delete
$ifr_regexp = '!<iframe((?:\s+\w+="[^"]*")*?)\s+src="(https?:)?//(?:www\.)*youtube.com/embed/([^"]+)".*?</iframe>!i';
[51] Fix | Delete
$ifr_regexp_ent = str_replace( '&amp;#0*58;', '&amp;#0*58;|&#0*58;', htmlspecialchars( $ifr_regexp, ENT_NOQUOTES ) );
[52] Fix | Delete
[53] Fix | Delete
foreach ( compact( 'regexp', 'regexp_ent', 'old_regexp', 'old_regexp_ent', 'ifr_regexp', 'ifr_regexp_ent' ) as $reg => $regexp ) {
[54] Fix | Delete
if ( ! preg_match_all( $regexp, $content, $matches, PREG_SET_ORDER ) ) {
[55] Fix | Delete
continue;
[56] Fix | Delete
}
[57] Fix | Delete
[58] Fix | Delete
foreach ( $matches as $match ) {
[59] Fix | Delete
/*
[60] Fix | Delete
* Hack, but '?' should only ever appear once, and
[61] Fix | Delete
* it should be for the 1st field-value pair in query string,
[62] Fix | Delete
* if it is present
[63] Fix | Delete
* YouTube changed their embed code.
[64] Fix | Delete
* Example of how it is now:
[65] Fix | Delete
* <object width="640" height="385"><param name="movie" value="http://www.youtube.com/v/aP9AaD4tgBY?fs=1&amp;hl=en_US"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/aP9AaD4tgBY?fs=1&amp;hl=en_US" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="640" height="385"></embed></object>
[66] Fix | Delete
* As shown at the start of function, previous YouTube didn't '?'
[67] Fix | Delete
* the 1st field-value pair.
[68] Fix | Delete
*/
[69] Fix | Delete
if ( in_array( $reg, array( 'ifr_regexp', 'ifr_regexp_ent', 'regexp', 'regexp_ent' ), true ) ) {
[70] Fix | Delete
$params = $match[1];
[71] Fix | Delete
[72] Fix | Delete
if ( in_array( $reg, array( 'ifr_regexp_ent', 'regexp_ent' ), true ) ) {
[73] Fix | Delete
$params = html_entity_decode( $params, ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401 );
[74] Fix | Delete
}
[75] Fix | Delete
[76] Fix | Delete
$params = wp_kses_hair( $params, array( 'http' ) );
[77] Fix | Delete
[78] Fix | Delete
$width = isset( $params['width'] ) ? (int) $params['width']['value'] : 0;
[79] Fix | Delete
$height = isset( $params['height'] ) ? (int) $params['height']['value'] : 0;
[80] Fix | Delete
$wh = '';
[81] Fix | Delete
[82] Fix | Delete
if ( $width && $height ) {
[83] Fix | Delete
$wh = "&w=$width&h=$height";
[84] Fix | Delete
}
[85] Fix | Delete
[86] Fix | Delete
$url = esc_url_raw( "https://www.youtube.com/watch?v={$match[3]}{$wh}" );
[87] Fix | Delete
} else {
[88] Fix | Delete
$match[1] = str_replace( '?', '&', $match[1] );
[89] Fix | Delete
[90] Fix | Delete
$url = esc_url_raw( 'https://www.youtube.com/watch?v=' . html_entity_decode( $match[1], ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401 ) );
[91] Fix | Delete
}
[92] Fix | Delete
[93] Fix | Delete
$content = str_replace( $match[0], "[youtube $url]", $content );
[94] Fix | Delete
[95] Fix | Delete
/**
[96] Fix | Delete
* Fires before the YouTube embed is transformed into a shortcode.
[97] Fix | Delete
*
[98] Fix | Delete
* @module shortcodes
[99] Fix | Delete
*
[100] Fix | Delete
* @since 1.2.0
[101] Fix | Delete
*
[102] Fix | Delete
* @param string youtube Shortcode name.
[103] Fix | Delete
* @param string $url YouTube video URL.
[104] Fix | Delete
*/
[105] Fix | Delete
do_action( 'jetpack_embed_to_shortcode', 'youtube', $url );
[106] Fix | Delete
}
[107] Fix | Delete
}
[108] Fix | Delete
[109] Fix | Delete
return $content;
[110] Fix | Delete
}
[111] Fix | Delete
[112] Fix | Delete
if ( jetpack_shortcodes_should_hook_pre_kses() ) {
[113] Fix | Delete
add_filter( 'pre_kses', 'jetpack_youtube_embed_to_short_code' );
[114] Fix | Delete
}
[115] Fix | Delete
[116] Fix | Delete
/**
[117] Fix | Delete
* Replaces plain-text links to YouTube videos with YouTube embeds.
[118] Fix | Delete
*
[119] Fix | Delete
* @param string $content HTML content.
[120] Fix | Delete
*
[121] Fix | Delete
* @return string The content with embeds instead of URLs
[122] Fix | Delete
*/
[123] Fix | Delete
function jetpack_youtube_link( $content ) {
[124] Fix | Delete
return jetpack_preg_replace_callback_outside_tags( '!(?:\n|\A)https?://(?:www\.)?(?:youtube.com/(?:v/|playlist|watch[/\#?])|youtu\.be/)[^\s]+?(?:\n|\Z)!i', 'jetpack_youtube_link_callback', $content, 'youtube.com/' );
[125] Fix | Delete
}
[126] Fix | Delete
[127] Fix | Delete
/**
[128] Fix | Delete
* Callback function for the regex that replaces YouTube URLs with
[129] Fix | Delete
* YouTube embeds.
[130] Fix | Delete
*
[131] Fix | Delete
* @param array $matches An array containing a YouTube URL.
[132] Fix | Delete
*/
[133] Fix | Delete
function jetpack_youtube_link_callback( $matches ) {
[134] Fix | Delete
return "\n" . jetpack_youtube_id( $matches[0] ) . "\n";
[135] Fix | Delete
}
[136] Fix | Delete
[137] Fix | Delete
/**
[138] Fix | Delete
* Normalizes a YouTube URL to include a v= parameter and a query string free of encoded ampersands.
[139] Fix | Delete
*
[140] Fix | Delete
* @param string|array $url Youtube URL.
[141] Fix | Delete
* @return string|false The normalized URL or false if input is invalid.
[142] Fix | Delete
*/
[143] Fix | Delete
if ( ! function_exists( 'jetpack_youtube_sanitize_url' ) ) :
[144] Fix | Delete
/**
[145] Fix | Delete
* Clean up Youtube URL to match a single format.
[146] Fix | Delete
*
[147] Fix | Delete
* @param string|array $url Youtube URL.
[148] Fix | Delete
*/
[149] Fix | Delete
function jetpack_youtube_sanitize_url( $url ) {
[150] Fix | Delete
if ( is_array( $url ) && isset( $url['url'] ) ) {
[151] Fix | Delete
$url = $url['url'];
[152] Fix | Delete
}
[153] Fix | Delete
if ( ! is_string( $url ) ) {
[154] Fix | Delete
return false;
[155] Fix | Delete
}
[156] Fix | Delete
[157] Fix | Delete
$url = trim( $url, ' "' );
[158] Fix | Delete
$url = trim( $url );
[159] Fix | Delete
$url = str_replace( array( 'youtu.be/', '/v/', '#!v=', '&amp;', '&#038;', 'playlist' ), array( 'youtu.be/?v=', '/?v=', '?v=', '&', '&', 'videoseries' ), $url );
[160] Fix | Delete
[161] Fix | Delete
// Replace any extra question marks with ampersands - the result of a URL like "https://www.youtube.com/v/dQw4w9WgXcQ?fs=1&hl=en_US" being passed in.
[162] Fix | Delete
$query_string_start = strpos( $url, '?' );
[163] Fix | Delete
[164] Fix | Delete
if ( false !== $query_string_start ) {
[165] Fix | Delete
$url = substr( $url, 0, $query_string_start + 1 ) . str_replace( '?', '&', substr( $url, $query_string_start + 1 ) );
[166] Fix | Delete
}
[167] Fix | Delete
[168] Fix | Delete
return $url;
[169] Fix | Delete
}
[170] Fix | Delete
endif;
[171] Fix | Delete
[172] Fix | Delete
/**
[173] Fix | Delete
* Converts a YouTube URL into an embedded YouTube video.
[174] Fix | Delete
*
[175] Fix | Delete
* URL can be:
[176] Fix | Delete
* http://www.youtube.com/embed/videoseries?list=PL94269DA08231042B&amp;hl=en_US
[177] Fix | Delete
* http://www.youtube.com/watch#!v=H2Ncxw1xfck
[178] Fix | Delete
* http://www.youtube.com/watch?v=H2Ncxw1xfck
[179] Fix | Delete
* http://www.youtube.com/watch?v=H2Ncxw1xfck&w=320&h=240&fmt=1&rel=0&showsearch=1&hd=0
[180] Fix | Delete
* http://www.youtube.com/v/jF-kELmmvgA
[181] Fix | Delete
* http://www.youtube.com/v/9FhMMmqzbD8?fs=1&hl=en_US
[182] Fix | Delete
* http://youtu.be/Rrohlqeir5E
[183] Fix | Delete
* https://www.youtube.com/watch?v=GJNxoe-iSb4&list=PLAVZ4NFtZX0fE54mDSqNKym-o_rz-8xmk
[184] Fix | Delete
*
[185] Fix | Delete
* @param string $url Youtube URL.
[186] Fix | Delete
*/
[187] Fix | Delete
function jetpack_youtube_id( $url ) {
[188] Fix | Delete
$id = jetpack_get_youtube_id( $url );
[189] Fix | Delete
[190] Fix | Delete
if ( ! $id ) {
[191] Fix | Delete
return sprintf( '<!--%s-->', esc_html__( 'YouTube Error: bad URL entered', 'jetpack' ) );
[192] Fix | Delete
}
[193] Fix | Delete
[194] Fix | Delete
$url = jetpack_youtube_sanitize_url( $url );
[195] Fix | Delete
$url = wp_parse_url( $url );
[196] Fix | Delete
[197] Fix | Delete
$thumbnail = "https://i.ytimg.com/vi/$id/hqdefault.jpg";
[198] Fix | Delete
$video_url = add_query_arg( 'v', $id, 'https://www.youtube.com/watch' );
[199] Fix | Delete
[200] Fix | Delete
$args = jetpack_shortcode_youtube_args( $url );
[201] Fix | Delete
if ( empty( $args ) ) {
[202] Fix | Delete
return sprintf( '<!--%s-->', esc_html__( 'YouTube Error: empty URL args', 'jetpack' ) );
[203] Fix | Delete
}
[204] Fix | Delete
[205] Fix | Delete
// Account for URL having both v and list, where jetpack_get_youtube_id() only accounts for one or the other.
[206] Fix | Delete
if ( isset( $args['list'] ) && $args['list'] === $id ) {
[207] Fix | Delete
$id = null;
[208] Fix | Delete
}
[209] Fix | Delete
if ( isset( $args['v'] ) ) {
[210] Fix | Delete
$id = $args['v'];
[211] Fix | Delete
}
[212] Fix | Delete
if ( ! $id && empty( $args['list'] ) ) {
[213] Fix | Delete
return sprintf( '<!--%s-->', esc_html__( 'YouTube Error: missing id and/or list', 'jetpack' ) );
[214] Fix | Delete
}
[215] Fix | Delete
[216] Fix | Delete
list( $w, $h ) = jetpack_shortcode_youtube_dimensions( $args );
[217] Fix | Delete
[218] Fix | Delete
$params = array(
[219] Fix | Delete
'rel' => ( isset( $args['rel'] ) && '0' === $args['rel'] ) ? 0 : 1,
[220] Fix | Delete
'showsearch' => ( isset( $args['showsearch'] ) && '1' === $args['showsearch'] ) ? 1 : 0, // Now deprecated. See https://developers.google.com/youtube/player_parameters#march-29,-2012.
[221] Fix | Delete
'showinfo' => ( isset( $args['showinfo'] ) && '0' === $args['showinfo'] ) ? 0 : 1, // Now obsolete. See https://developers.google.com/youtube/player_parameters#showinfo.
[222] Fix | Delete
'iv_load_policy' => ( isset( $args['iv_load_policy'] ) && '3' === $args['iv_load_policy'] ) ? 3 : 1,
[223] Fix | Delete
'fs' => 1,
[224] Fix | Delete
'hl' => str_replace( '_', '-', get_locale() ),
[225] Fix | Delete
);
[226] Fix | Delete
if ( isset( $args['fmt'] ) && (int) $args['fmt'] ) {
[227] Fix | Delete
$params['fmt'] = (int) $args['fmt']; // Apparently an obsolete parameter. Not referenced on https://developers.google.com/youtube/player_parameters.
[228] Fix | Delete
}
[229] Fix | Delete
[230] Fix | Delete
// The autohide parameter has been deprecated since 2015. See https://developers.google.com/youtube/player_parameters#august-19,-2015.
[231] Fix | Delete
if ( ! isset( $args['autohide'] ) || ( $args['autohide'] < 0 || 2 < $args['autohide'] ) ) {
[232] Fix | Delete
$params['autohide'] = 2;
[233] Fix | Delete
} else {
[234] Fix | Delete
$params['autohide'] = (int) $args['autohide'];
[235] Fix | Delete
}
[236] Fix | Delete
[237] Fix | Delete
$start = 0;
[238] Fix | Delete
if ( isset( $args['start'] ) ) {
[239] Fix | Delete
$start = (int) $args['start'];
[240] Fix | Delete
} elseif ( isset( $args['t'] ) ) {
[241] Fix | Delete
if ( is_numeric( $args['t'] ) ) {
[242] Fix | Delete
$start = (int) $args['t'];
[243] Fix | Delete
} elseif ( is_string( $args['t'] ) ) {
[244] Fix | Delete
$time_pieces = preg_split( '/(?<=\D)(?=\d+)/', $args['t'] );
[245] Fix | Delete
[246] Fix | Delete
foreach ( $time_pieces as $time_piece ) {
[247] Fix | Delete
$int = (int) $time_piece;
[248] Fix | Delete
switch ( substr( $time_piece, - 1 ) ) {
[249] Fix | Delete
case 'h':
[250] Fix | Delete
$start += $int * 3600;
[251] Fix | Delete
break;
[252] Fix | Delete
case 'm':
[253] Fix | Delete
$start += $int * 60;
[254] Fix | Delete
break;
[255] Fix | Delete
case 's':
[256] Fix | Delete
$start += $int;
[257] Fix | Delete
break;
[258] Fix | Delete
}
[259] Fix | Delete
}
[260] Fix | Delete
}
[261] Fix | Delete
}
[262] Fix | Delete
if ( $start ) {
[263] Fix | Delete
$params['start'] = (int) $start;
[264] Fix | Delete
}
[265] Fix | Delete
[266] Fix | Delete
if ( isset( $args['end'] ) && (int) $args['end'] ) {
[267] Fix | Delete
$params['end'] = (int) $args['end'];
[268] Fix | Delete
}
[269] Fix | Delete
if ( isset( $args['hd'] ) && (int) $args['hd'] ) {
[270] Fix | Delete
$params['hd'] = (int) $args['hd']; // Now obsolete per https://developers.google.com/youtube/player_parameters#march-29,-2012.
[271] Fix | Delete
}
[272] Fix | Delete
if ( isset( $args['vq'] ) && in_array( $args['vq'], array( 'hd720', 'hd1080' ), true ) ) {
[273] Fix | Delete
$params['vq'] = $args['vq']; // Note, this appears to be obsolete. Not referenced on https://developers.google.com/youtube/player_parameters.
[274] Fix | Delete
}
[275] Fix | Delete
if ( isset( $args['cc_load_policy'] ) ) {
[276] Fix | Delete
$params['cc_load_policy'] = 1;
[277] Fix | Delete
}
[278] Fix | Delete
if ( isset( $args['cc_lang_pref'] ) ) {
[279] Fix | Delete
$params['cc_lang_pref'] = preg_replace( '/[^_a-z0-9-]/i', '', $args['cc_lang_pref'] );
[280] Fix | Delete
}
[281] Fix | Delete
[282] Fix | Delete
// The wmode parameter appears to be obsolete. Not referenced on https://developers.google.com/youtube/player_parameters.
[283] Fix | Delete
if ( isset( $args['wmode'] ) && in_array( strtolower( $args['wmode'] ), array( 'opaque', 'window', 'transparent' ), true ) ) {
[284] Fix | Delete
$params['wmode'] = $args['wmode'];
[285] Fix | Delete
} else {
[286] Fix | Delete
$params['wmode'] = 'transparent';
[287] Fix | Delete
}
[288] Fix | Delete
[289] Fix | Delete
// The theme parameter is obsolete per https://developers.google.com/youtube/player_parameters#august-19,-2015.
[290] Fix | Delete
if ( isset( $args['theme'] ) && in_array( strtolower( $args['theme'] ), array( 'dark', 'light' ), true ) ) {
[291] Fix | Delete
$params['theme'] = $args['theme'];
[292] Fix | Delete
}
[293] Fix | Delete
[294] Fix | Delete
if ( isset( $args['list'] ) ) {
[295] Fix | Delete
$params['listType'] = 'playlist';
[296] Fix | Delete
$params['list'] = preg_replace( '|[^_a-z0-9-]|i', '', $args['list'] );
[297] Fix | Delete
}
[298] Fix | Delete
[299] Fix | Delete
/**
[300] Fix | Delete
* Allow YouTube videos to start playing automatically.
[301] Fix | Delete
*
[302] Fix | Delete
* @module shortcodes
[303] Fix | Delete
*
[304] Fix | Delete
* @since 2.2.2
[305] Fix | Delete
*
[306] Fix | Delete
* @param bool false Enable autoplay for YouTube videos.
[307] Fix | Delete
*/
[308] Fix | Delete
if ( apply_filters( 'jetpack_youtube_allow_autoplay', false ) && isset( $args['autoplay'] ) ) {
[309] Fix | Delete
$params['autoplay'] = (int) $args['autoplay'];
[310] Fix | Delete
}
[311] Fix | Delete
[312] Fix | Delete
$is_amp = class_exists( 'Jetpack_AMP_Support' ) && Jetpack_AMP_Support::is_amp_request();
[313] Fix | Delete
[314] Fix | Delete
if ( $is_amp && $id ) {
[315] Fix | Delete
// Note that <amp-youtube> currently is not well suited for playlists that don't have an individual video selected, hence the $id check above.
[316] Fix | Delete
$placeholder = sprintf(
[317] Fix | Delete
'<a href="%1$s" placeholder><amp-img src="%2$s" alt="%3$s" layout="fill" object-fit="cover"><noscript><img src="%2$s" loading="lazy" decoding="async" alt="%3$s"></noscript></amp-img></a>',
[318] Fix | Delete
esc_url( $video_url ),
[319] Fix | Delete
esc_url( $thumbnail ),
[320] Fix | Delete
esc_attr__( 'YouTube Poster', 'jetpack' ) // Would be preferable to provide YouTube video title, but not available in this non-oEmbed context.
[321] Fix | Delete
);
[322] Fix | Delete
[323] Fix | Delete
$html_attributes = array();
[324] Fix | Delete
foreach ( $params as $param_name => $param_value ) {
[325] Fix | Delete
$html_attributes[] = sprintf(
[326] Fix | Delete
'data-param-%s="%s"',
[327] Fix | Delete
sanitize_key( $param_name ),
[328] Fix | Delete
esc_attr( $param_value )
[329] Fix | Delete
);
[330] Fix | Delete
}
[331] Fix | Delete
[332] Fix | Delete
$html = sprintf(
[333] Fix | Delete
'<amp-youtube data-videoid="%s" %s width="%d" height="%d" layout="responsive">%s</amp-youtube>',
[334] Fix | Delete
esc_attr( $id ),
[335] Fix | Delete
implode( ' ', $html_attributes ), // Note: Escaping done above.
[336] Fix | Delete
esc_attr( $w ),
[337] Fix | Delete
esc_attr( $h ),
[338] Fix | Delete
$placeholder
[339] Fix | Delete
);
[340] Fix | Delete
} else {
[341] Fix | Delete
// In AMP, the AMP_Iframe_Sanitizer will convert into <amp-iframe> as required.
[342] Fix | Delete
$src = 'https://www.youtube.com/embed';
[343] Fix | Delete
if ( $id ) {
[344] Fix | Delete
$src .= "/$id";
[345] Fix | Delete
}
[346] Fix | Delete
$src = add_query_arg(
[347] Fix | Delete
array_merge(
[348] Fix | Delete
array( 'version' => 3 ),
[349] Fix | Delete
$params
[350] Fix | Delete
),
[351] Fix | Delete
$src
[352] Fix | Delete
);
[353] Fix | Delete
[354] Fix | Delete
$layout = $is_amp ? 'layout="responsive" ' : '';
[355] Fix | Delete
[356] Fix | Delete
$html = sprintf(
[357] Fix | Delete
'<iframe class="youtube-player" width="%s" height="%s" %ssrc="%s" allowfullscreen="true" style="border:0;" sandbox="allow-scripts allow-same-origin allow-popups allow-presentation allow-popups-to-escape-sandbox"></iframe>',
[358] Fix | Delete
esc_attr( $w ),
[359] Fix | Delete
esc_attr( $h ),
[360] Fix | Delete
$layout,
[361] Fix | Delete
esc_url( $src )
[362] Fix | Delete
);
[363] Fix | Delete
}
[364] Fix | Delete
[365] Fix | Delete
// Let's do some alignment wonder in a span, unless we're producing a feed.
[366] Fix | Delete
if ( ! is_feed() ) {
[367] Fix | Delete
$alignmentcss = 'text-align:center;';
[368] Fix | Delete
if ( isset( $args['align'] ) ) {
[369] Fix | Delete
switch ( $args['align'] ) {
[370] Fix | Delete
case 'left':
[371] Fix | Delete
$alignmentcss = "float:left; width:{$w}px; height:{$h}px; margin-right:10px; margin-bottom: 10px;";
[372] Fix | Delete
break;
[373] Fix | Delete
case 'right':
[374] Fix | Delete
$alignmentcss = "float:right; width:{$w}px; height:{$h}px; margin-left:10px; margin-bottom: 10px;";
[375] Fix | Delete
break;
[376] Fix | Delete
}
[377] Fix | Delete
}
[378] Fix | Delete
[379] Fix | Delete
$html = sprintf(
[380] Fix | Delete
'<span class="embed-youtube" style="%s display: block;">%s</span>',
[381] Fix | Delete
esc_attr( $alignmentcss ),
[382] Fix | Delete
$html
[383] Fix | Delete
);
[384] Fix | Delete
[385] Fix | Delete
}
[386] Fix | Delete
[387] Fix | Delete
/**
[388] Fix | Delete
* Format output for Calypso Reader/Notifications/Comments
[389] Fix | Delete
*/
[390] Fix | Delete
if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) {
[391] Fix | Delete
require_once WP_CONTENT_DIR . '/lib/display-context.php';
[392] Fix | Delete
$context = A8C\Display_Context\get_current_context();
[393] Fix | Delete
if ( A8C\Display_Context\NOTIFICATIONS === $context ) {
[394] Fix | Delete
return sprintf(
[395] Fix | Delete
'<a href="%1$s" target="_blank" rel="noopener noreferrer"><img src="%2$s" alt="%3$s" /></a>',
[396] Fix | Delete
esc_url( $video_url ),
[397] Fix | Delete
esc_url( $thumbnail ),
[398] Fix | Delete
esc_html__( 'YouTube video', 'jetpack' )
[399] Fix | Delete
);
[400] Fix | Delete
}
[401] Fix | Delete
}
[402] Fix | Delete
[403] Fix | Delete
/**
[404] Fix | Delete
* Filter the YouTube video HTML output.
[405] Fix | Delete
*
[406] Fix | Delete
* @module shortcodes
[407] Fix | Delete
*
[408] Fix | Delete
* @since 1.2.3
[409] Fix | Delete
*
[410] Fix | Delete
* @param string $html YouTube video HTML output.
[411] Fix | Delete
*/
[412] Fix | Delete
$html = apply_filters( 'video_embed_html', $html );
[413] Fix | Delete
[414] Fix | Delete
return $html;
[415] Fix | Delete
}
[416] Fix | Delete
[417] Fix | Delete
/**
[418] Fix | Delete
* Gets the args present in the YouTube shortcode URL.
[419] Fix | Delete
*
[420] Fix | Delete
* @since 8.0.0
[421] Fix | Delete
*
[422] Fix | Delete
* @param array $url The parsed URL of the shortcode.
[423] Fix | Delete
*
[424] Fix | Delete
* @return array|false The query args of the URL, or false.
[425] Fix | Delete
*/
[426] Fix | Delete
function jetpack_shortcode_youtube_args( $url ) {
[427] Fix | Delete
$qargs = array();
[428] Fix | Delete
if ( ! empty( $url['query'] ) ) {
[429] Fix | Delete
wp_parse_str( $url['query'], $qargs );
[430] Fix | Delete
} else {
[431] Fix | Delete
return false;
[432] Fix | Delete
}
[433] Fix | Delete
[434] Fix | Delete
$fargs = array();
[435] Fix | Delete
if ( ! empty( $url['fragment'] ) ) {
[436] Fix | Delete
wp_parse_str( $url['fragment'], $fargs );
[437] Fix | Delete
}
[438] Fix | Delete
[439] Fix | Delete
return array_merge( $fargs, $qargs );
[440] Fix | Delete
}
[441] Fix | Delete
[442] Fix | Delete
/**
[443] Fix | Delete
* Display the Youtube shortcode.
[444] Fix | Delete
*
[445] Fix | Delete
* @param array $atts Shortcode attributes.
[446] Fix | Delete
*
[447] Fix | Delete
* @return string The rendered shortcode.
[448] Fix | Delete
*/
[449] Fix | Delete
function jetpack_youtube_shortcode( $atts ) {
[450] Fix | Delete
$url = ( isset( $atts[0] ) ) ? ltrim( $atts[0], '=' ) : shortcode_new_to_old_params( $atts );
[451] Fix | Delete
return jetpack_youtube_id( $url );
[452] Fix | Delete
}
[453] Fix | Delete
add_shortcode( 'youtube', 'jetpack_youtube_shortcode' );
[454] Fix | Delete
[455] Fix | Delete
/**
[456] Fix | Delete
* Gets the dimensions of the [youtube] shortcode.
[457] Fix | Delete
*
[458] Fix | Delete
* Calculates the width and height, taking $content_width into consideration.
[459] Fix | Delete
*
[460] Fix | Delete
* @since 8.0.0
[461] Fix | Delete
*
[462] Fix | Delete
* @param array $query_args The query args of the URL.
[463] Fix | Delete
*
[464] Fix | Delete
* @return array The width and height of the shortcode.
[465] Fix | Delete
*/
[466] Fix | Delete
function jetpack_shortcode_youtube_dimensions( $query_args ) {
[467] Fix | Delete
$h = null;
[468] Fix | Delete
global $content_width;
[469] Fix | Delete
[470] Fix | Delete
$input_w = ( isset( $query_args['w'] ) && (int) $query_args['w'] ) ? (int) $query_args['w'] : 0;
[471] Fix | Delete
$input_h = ( isset( $query_args['h'] ) && (int) $query_args['h'] ) ? (int) $query_args['h'] : 0;
[472] Fix | Delete
[473] Fix | Delete
// If we have $content_width, use it.
[474] Fix | Delete
if ( ! empty( $content_width ) ) {
[475] Fix | Delete
$default_width = (int) $content_width;
[476] Fix | Delete
} else {
[477] Fix | Delete
// Otherwise get default width from the old, now deprecated embed_size_w option.
[478] Fix | Delete
$default_width = (int) get_option( 'embed_size_w' );
[479] Fix | Delete
}
[480] Fix | Delete
[481] Fix | Delete
// If we don't know those 2 values use a hardcoded width.
[482] Fix | Delete
if ( empty( $default_width ) ) {
[483] Fix | Delete
$default_width = 640;
[484] Fix | Delete
}
[485] Fix | Delete
[486] Fix | Delete
if ( $input_w > 0 && $input_h > 0 ) {
[487] Fix | Delete
$w = $input_w;
[488] Fix | Delete
$h = $input_h;
[489] Fix | Delete
} elseif ( 0 === $input_w && 0 === $input_h ) {
[490] Fix | Delete
if ( isset( $query_args['fmt'] ) && (int) $query_args['fmt'] ) {
[491] Fix | Delete
$w = ( ! empty( $content_width ) ? min( $content_width, 480 ) : 480 );
[492] Fix | Delete
} else {
[493] Fix | Delete
$w = ( ! empty( $content_width ) ? min( $content_width, $default_width ) : $default_width );
[494] Fix | Delete
$h = ceil( ( $w / 16 ) * 9 );
[495] Fix | Delete
}
[496] Fix | Delete
} elseif ( $input_w > 0 ) {
[497] Fix | Delete
$w = $input_w;
[498] Fix | Delete
$h = ceil( ( $w / 16 ) * 9 );
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function