Edit File by line
/home/zeestwma/richards.../wp-conte.../plugins/jetpack/modules/shortcod...
File: ted.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* TED Player embed code
[2] Fix | Delete
* http://www.ted.com
[3] Fix | Delete
*
[4] Fix | Delete
* Examples:
[5] Fix | Delete
* http://www.ted.com/talks/view/id/210
[6] Fix | Delete
* http://www.ted.com/talks/marc_goodman_a_vision_of_crimes_in_the_future.html
[7] Fix | Delete
* [ted id="210" lang="en"]
[8] Fix | Delete
* [ted id="http://www.ted.com/talks/view/id/210" lang="en"]
[9] Fix | Delete
* [ted id=1539 lang=fr width=560 height=315]
[10] Fix | Delete
*
[11] Fix | Delete
* @package automattic/jetpack
[12] Fix | Delete
*/
[13] Fix | Delete
[14] Fix | Delete
if ( ! defined( 'ABSPATH' ) ) {
[15] Fix | Delete
exit( 0 );
[16] Fix | Delete
}
[17] Fix | Delete
[18] Fix | Delete
wp_oembed_add_provider( '!https?://(www\.)?ted.com/talks/view/id/.+!i', 'https://www.ted.com/talks/oembed.json', true );
[19] Fix | Delete
wp_oembed_add_provider( '!https?://(www\.)?ted.com/talks/[a-zA-Z\-\_]+\.html!i', 'https://www.ted.com/talks/oembed.json', true );
[20] Fix | Delete
[21] Fix | Delete
/**
[22] Fix | Delete
* Get the unique ID of a TED video.
[23] Fix | Delete
* Used in Jetpack_Media_Meta_Extractor.
[24] Fix | Delete
*
[25] Fix | Delete
* @param array $atts Shortcode attributes.
[26] Fix | Delete
*/
[27] Fix | Delete
function jetpack_shortcode_get_ted_id( $atts ) {
[28] Fix | Delete
return ( ! empty( $atts['id'] ) ? $atts['id'] : 0 );
[29] Fix | Delete
}
[30] Fix | Delete
[31] Fix | Delete
/**
[32] Fix | Delete
* Handle Ted Shortcode.
[33] Fix | Delete
*
[34] Fix | Delete
* @param array $atts Shortcode attributes.
[35] Fix | Delete
*/
[36] Fix | Delete
function shortcode_ted( $atts ) {
[37] Fix | Delete
global $wp_embed;
[38] Fix | Delete
[39] Fix | Delete
$defaults = array(
[40] Fix | Delete
'id' => '',
[41] Fix | Delete
'width' => '',
[42] Fix | Delete
'height' => '',
[43] Fix | Delete
'lang' => 'en',
[44] Fix | Delete
);
[45] Fix | Delete
$atts = shortcode_atts( $defaults, $atts, 'ted' );
[46] Fix | Delete
[47] Fix | Delete
if ( empty( $atts['id'] ) ) {
[48] Fix | Delete
return '<!-- Missing TED ID -->';
[49] Fix | Delete
}
[50] Fix | Delete
[51] Fix | Delete
$url = '';
[52] Fix | Delete
if ( preg_match( '#^[\d]+$#', $atts['id'], $matches ) ) {
[53] Fix | Delete
$url = 'https://ted.com/talks/view/id/' . $matches[0];
[54] Fix | Delete
} elseif ( preg_match( '#^https?://(www\.)?ted\.com/talks/view/id/[0-9]+$#', $atts['id'], $matches ) ) {
[55] Fix | Delete
$url = set_url_scheme( $matches[0], 'https' );
[56] Fix | Delete
}
[57] Fix | Delete
[58] Fix | Delete
unset( $atts['id'] );
[59] Fix | Delete
[60] Fix | Delete
$args = array();
[61] Fix | Delete
$embed_size_w = get_option( 'embed_size_w' );
[62] Fix | Delete
[63] Fix | Delete
if ( is_numeric( $atts['width'] ) ) {
[64] Fix | Delete
$args['width'] = $atts['width'];
[65] Fix | Delete
} elseif ( $embed_size_w ) {
[66] Fix | Delete
$args['width'] = $embed_size_w;
[67] Fix | Delete
} elseif ( ! empty( $GLOBALS['content_width'] ) ) {
[68] Fix | Delete
$args['width'] = (int) $GLOBALS['content_width'];
[69] Fix | Delete
} else {
[70] Fix | Delete
$args['width'] = 500;
[71] Fix | Delete
}
[72] Fix | Delete
[73] Fix | Delete
// Default to a 16x9 aspect ratio if there's no height set.
[74] Fix | Delete
if ( is_numeric( $atts['height'] ) ) {
[75] Fix | Delete
$args['height'] = $atts['height'];
[76] Fix | Delete
} else {
[77] Fix | Delete
$args['height'] = $args['width'] * 0.5625;
[78] Fix | Delete
}
[79] Fix | Delete
[80] Fix | Delete
if ( ! empty( $atts['lang'] ) ) {
[81] Fix | Delete
$args['lang'] = sanitize_key( $atts['lang'] );
[82] Fix | Delete
add_filter( 'oembed_fetch_url', 'ted_filter_oembed_fetch_url', 10, 3 );
[83] Fix | Delete
}
[84] Fix | Delete
$retval = $wp_embed->shortcode( $args, $url );
[85] Fix | Delete
remove_filter( 'oembed_fetch_url', 'ted_filter_oembed_fetch_url', 10 );
[86] Fix | Delete
[87] Fix | Delete
return $retval;
[88] Fix | Delete
}
[89] Fix | Delete
add_shortcode( 'ted', 'shortcode_ted' );
[90] Fix | Delete
[91] Fix | Delete
/**
[92] Fix | Delete
* Filter the request URL to also include the $lang parameter
[93] Fix | Delete
*
[94] Fix | Delete
* @param string $provider URL of provider that supplies the tweet we're requesting.
[95] Fix | Delete
* @param string $url URL of tweet to embed.
[96] Fix | Delete
* @param array $args Parameters supplied to shortcode and passed to wp_oembed_get.
[97] Fix | Delete
*/
[98] Fix | Delete
function ted_filter_oembed_fetch_url( $provider, $url, $args ) {
[99] Fix | Delete
return add_query_arg( 'lang', $args['lang'], $provider );
[100] Fix | Delete
}
[101] Fix | Delete
[102] Fix | Delete
/**
[103] Fix | Delete
* Filter the oembed html to set the sandbox attribute in the iframe
[104] Fix | Delete
*
[105] Fix | Delete
* @param string|false $cache The cached HTML result, stored in post meta.
[106] Fix | Delete
* @param string $url The attempted embed URL.
[107] Fix | Delete
*
[108] Fix | Delete
* @return string|false
[109] Fix | Delete
*/
[110] Fix | Delete
function ted_filter_oembed_amp_iframe( $cache, $url ) {
[111] Fix | Delete
if ( ! is_string( $cache ) ) {
[112] Fix | Delete
return $cache;
[113] Fix | Delete
}
[114] Fix | Delete
[115] Fix | Delete
$host = wp_parse_url( $url, PHP_URL_HOST );
[116] Fix | Delete
if ( ! $host ) {
[117] Fix | Delete
return $cache;
[118] Fix | Delete
}
[119] Fix | Delete
[120] Fix | Delete
$allowed_hosts = array(
[121] Fix | Delete
'ted.com',
[122] Fix | Delete
'www.ted.com',
[123] Fix | Delete
'embed.ted.com',
[124] Fix | Delete
);
[125] Fix | Delete
[126] Fix | Delete
$host = strtolower( $host );
[127] Fix | Delete
if ( in_array( $host, $allowed_hosts, true ) ) {
[128] Fix | Delete
$cache = preg_replace(
[129] Fix | Delete
'/src=[\'"].*?[\'"]/',
[130] Fix | Delete
'$0 sandbox="allow-popups allow-scripts allow-same-origin"',
[131] Fix | Delete
$cache
[132] Fix | Delete
);
[133] Fix | Delete
}
[134] Fix | Delete
[135] Fix | Delete
return $cache;
[136] Fix | Delete
}
[137] Fix | Delete
add_filter( 'embed_oembed_html', 'ted_filter_oembed_amp_iframe', 10, 2 );
[138] Fix | Delete
[139] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function