Edit File by line
/home/zeestwma/richards.../wp-conte.../plugins/jetpack/modules/theme-to...
File: responsive-videos.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* Theme Tools: Responsive videos enhancements.
[2] Fix | Delete
*
[3] Fix | Delete
* @package automattic/jetpack
[4] Fix | Delete
*/
[5] Fix | Delete
[6] Fix | Delete
use Automattic\Jetpack\Assets;
[7] Fix | Delete
[8] Fix | Delete
if ( ! defined( 'ABSPATH' ) ) {
[9] Fix | Delete
exit( 0 );
[10] Fix | Delete
}
[11] Fix | Delete
[12] Fix | Delete
if ( ! class_exists( '\Automattic\Jetpack\Classic_Theme_Helper\Main' ) ) {
[13] Fix | Delete
/**
[14] Fix | Delete
* Load the Responsive videos plugin
[15] Fix | Delete
*
[16] Fix | Delete
* @deprecated 13.7 Moved to Classic Theme Helper package.
[17] Fix | Delete
*/
[18] Fix | Delete
function jetpack_responsive_videos_init() {
[19] Fix | Delete
_deprecated_function( __FUNCTION__, 'jetpack-13.7' );
[20] Fix | Delete
[21] Fix | Delete
/* If the doesn't theme support 'jetpack-responsive-videos', don't continue */
[22] Fix | Delete
if ( ! current_theme_supports( 'jetpack-responsive-videos' ) ) {
[23] Fix | Delete
return;
[24] Fix | Delete
}
[25] Fix | Delete
[26] Fix | Delete
/* If the theme does support 'jetpack-responsive-videos', wrap the videos */
[27] Fix | Delete
add_filter( 'wp_video_shortcode', 'jetpack_responsive_videos_embed_html' );
[28] Fix | Delete
add_filter( 'video_embed_html', 'jetpack_responsive_videos_embed_html' );
[29] Fix | Delete
[30] Fix | Delete
/* Only wrap oEmbeds if video */
[31] Fix | Delete
add_filter( 'embed_oembed_html', 'jetpack_responsive_videos_maybe_wrap_oembed', 10, 2 );
[32] Fix | Delete
add_filter( 'embed_handler_html', 'jetpack_responsive_videos_maybe_wrap_oembed', 10, 2 );
[33] Fix | Delete
[34] Fix | Delete
/* Wrap videos in Buddypress */
[35] Fix | Delete
add_filter( 'bp_embed_oembed_html', 'jetpack_responsive_videos_embed_html' );
[36] Fix | Delete
[37] Fix | Delete
/* Wrap Slideshare shortcodes */
[38] Fix | Delete
add_filter( 'jetpack_slideshare_shortcode', 'jetpack_responsive_videos_embed_html' );
[39] Fix | Delete
[40] Fix | Delete
// Remove the Jetpack Responsive video wrapper in embed blocks on sites that support core Responsive embeds.
[41] Fix | Delete
if ( current_theme_supports( 'responsive-embeds' ) ) {
[42] Fix | Delete
add_filter( 'render_block', 'jetpack_responsive_videos_remove_wrap_oembed', 10, 2 );
[43] Fix | Delete
}
[44] Fix | Delete
}
[45] Fix | Delete
add_action( 'after_setup_theme', 'jetpack_responsive_videos_init', 99 );
[46] Fix | Delete
[47] Fix | Delete
/**
[48] Fix | Delete
* Adds a wrapper to videos and enqueue script
[49] Fix | Delete
*
[50] Fix | Delete
* @deprecated 13.7 Moved to Classic Theme Helper package.
[51] Fix | Delete
*
[52] Fix | Delete
* @param string $html The video embed HTML.
[53] Fix | Delete
* @return string
[54] Fix | Delete
*/
[55] Fix | Delete
function jetpack_responsive_videos_embed_html( $html ) {
[56] Fix | Delete
_deprecated_function( __FUNCTION__, 'jetpack-13.7' );
[57] Fix | Delete
[58] Fix | Delete
if ( empty( $html ) || ! is_string( $html ) ) {
[59] Fix | Delete
return $html;
[60] Fix | Delete
}
[61] Fix | Delete
[62] Fix | Delete
// Short-circuit for AMP responses, since custom scripts are not allowed in AMP and videos are naturally responsive.
[63] Fix | Delete
if ( class_exists( 'Jetpack_AMP_Support' ) && Jetpack_AMP_Support::is_amp_request() ) {
[64] Fix | Delete
return $html;
[65] Fix | Delete
}
[66] Fix | Delete
[67] Fix | Delete
// The customizer video widget wraps videos with a class of wp-video
[68] Fix | Delete
// mejs as of 4.9 apparently resizes videos too which causes issues
[69] Fix | Delete
// skip the video if it is wrapped in wp-video.
[70] Fix | Delete
$video_widget_wrapper = 'class="wp-video"';
[71] Fix | Delete
[72] Fix | Delete
$mejs_wrapped = strpos( $html, $video_widget_wrapper );
[73] Fix | Delete
[74] Fix | Delete
// If this is a video widget wrapped by mejs, return the html.
[75] Fix | Delete
if ( false !== $mejs_wrapped ) {
[76] Fix | Delete
return $html;
[77] Fix | Delete
}
[78] Fix | Delete
[79] Fix | Delete
Assets::register_script(
[80] Fix | Delete
'jetpack-responsive-videos',
[81] Fix | Delete
'_inc/build/theme-tools/responsive-videos/responsive-videos.min.js',
[82] Fix | Delete
JETPACK__PLUGIN_FILE,
[83] Fix | Delete
array(
[84] Fix | Delete
'in_footer' => true,
[85] Fix | Delete
'enqueue' => true,
[86] Fix | Delete
'textdomain' => 'jetpack',
[87] Fix | Delete
'css_path' => '_inc/build/theme-tools/responsive-videos/responsive-videos.css',
[88] Fix | Delete
)
[89] Fix | Delete
);
[90] Fix | Delete
[91] Fix | Delete
return '<div class="jetpack-video-wrapper">' . $html . '</div>';
[92] Fix | Delete
}
[93] Fix | Delete
[94] Fix | Delete
/**
[95] Fix | Delete
* Check if oEmbed is a `$video_patterns` provider video before wrapping.
[96] Fix | Delete
*
[97] Fix | Delete
* @deprecated 13.7 Moved to Classic Theme Helper package.
[98] Fix | Delete
*
[99] Fix | Delete
* @param mixed $html The cached HTML result, stored in post meta.
[100] Fix | Delete
* @param string $url he attempted embed URL.
[101] Fix | Delete
*
[102] Fix | Delete
* @return string
[103] Fix | Delete
*/
[104] Fix | Delete
function jetpack_responsive_videos_maybe_wrap_oembed( $html, $url = null ) {
[105] Fix | Delete
_deprecated_function( __FUNCTION__, 'jetpack-13.7' );
[106] Fix | Delete
[107] Fix | Delete
if ( empty( $html ) || ! is_string( $html ) || ! $url ) {
[108] Fix | Delete
return $html;
[109] Fix | Delete
}
[110] Fix | Delete
[111] Fix | Delete
// Short-circuit for AMP responses, since custom scripts are not allowed in AMP and videos are naturally responsive.
[112] Fix | Delete
if ( class_exists( 'Jetpack_AMP_Support' ) && Jetpack_AMP_Support::is_amp_request() ) {
[113] Fix | Delete
return $html;
[114] Fix | Delete
}
[115] Fix | Delete
[116] Fix | Delete
$jetpack_video_wrapper = '<div class="jetpack-video-wrapper">';
[117] Fix | Delete
[118] Fix | Delete
$already_wrapped = strpos( $html, $jetpack_video_wrapper );
[119] Fix | Delete
[120] Fix | Delete
// If the oEmbed has already been wrapped, return the html.
[121] Fix | Delete
if ( false !== $already_wrapped ) {
[122] Fix | Delete
return $html;
[123] Fix | Delete
}
[124] Fix | Delete
[125] Fix | Delete
/**
[126] Fix | Delete
* The oEmbed video providers.
[127] Fix | Delete
*
[128] Fix | Delete
* An allowed list of oEmbed video provider Regex patterns to check against before wrapping the output.
[129] Fix | Delete
*
[130] Fix | Delete
* @module theme-tools
[131] Fix | Delete
*
[132] Fix | Delete
* @since 3.8.0
[133] Fix | Delete
*
[134] Fix | Delete
* @param array $video_patterns oEmbed video provider Regex patterns.
[135] Fix | Delete
*/
[136] Fix | Delete
$video_patterns = apply_filters(
[137] Fix | Delete
'jetpack_responsive_videos_oembed_videos',
[138] Fix | Delete
array(
[139] Fix | Delete
'https?://((m|www)\.)?youtube\.com/watch',
[140] Fix | Delete
'https?://((m|www)\.)?youtube\.com/playlist',
[141] Fix | Delete
'https?://youtu\.be/',
[142] Fix | Delete
'https?://(.+\.)?vimeo\.com/',
[143] Fix | Delete
'https?://(www\.)?dailymotion\.com/',
[144] Fix | Delete
'https?://dai.ly/',
[145] Fix | Delete
'https?://(www\.)?hulu\.com/watch/',
[146] Fix | Delete
'https?://wordpress.tv/',
[147] Fix | Delete
'https?://(www\.)?funnyordie\.com/videos/',
[148] Fix | Delete
'https?://vine.co/v/',
[149] Fix | Delete
'https?://(www\.)?collegehumor\.com/video/',
[150] Fix | Delete
'https?://(www\.|embed\.)?ted\.com/talks/',
[151] Fix | Delete
)
[152] Fix | Delete
);
[153] Fix | Delete
[154] Fix | Delete
// Merge patterns to run in a single preg_match call.
[155] Fix | Delete
$video_patterns = '(' . implode( '|', $video_patterns ) . ')';
[156] Fix | Delete
[157] Fix | Delete
$is_video = preg_match( $video_patterns, $url );
[158] Fix | Delete
[159] Fix | Delete
// If the oEmbed is a video, wrap it in the responsive wrapper.
[160] Fix | Delete
if ( false === $already_wrapped && 1 === $is_video ) {
[161] Fix | Delete
return jetpack_responsive_videos_embed_html( $html );
[162] Fix | Delete
}
[163] Fix | Delete
[164] Fix | Delete
return $html;
[165] Fix | Delete
}
[166] Fix | Delete
[167] Fix | Delete
/**
[168] Fix | Delete
* Remove the Jetpack Responsive video wrapper in embed blocks.
[169] Fix | Delete
*
[170] Fix | Delete
* @since 7.0.0
[171] Fix | Delete
*
[172] Fix | Delete
* @deprecated 13.7 Moved to Classic Theme Helper package.
[173] Fix | Delete
*
[174] Fix | Delete
* @param string $block_content The block content about to be appended.
[175] Fix | Delete
* @param array $block The full block, including name and attributes.
[176] Fix | Delete
*
[177] Fix | Delete
* @return string $block_content String of rendered HTML.
[178] Fix | Delete
*/
[179] Fix | Delete
function jetpack_responsive_videos_remove_wrap_oembed( $block_content, $block ) {
[180] Fix | Delete
_deprecated_function( __FUNCTION__, 'jetpack-13.7' );
[181] Fix | Delete
[182] Fix | Delete
if (
[183] Fix | Delete
isset( $block['blockName'] )
[184] Fix | Delete
&& (
[185] Fix | Delete
str_contains( $block['blockName'], 'core-embed' ) // pre-WP 5.6 embeds (multiple embed blocks starting with 'core-embed').
[186] Fix | Delete
|| 'core/embed' === $block['blockName'] // WP 5.6 embed block format (single embed block w/ block variations).
[187] Fix | Delete
)
[188] Fix | Delete
) {
[189] Fix | Delete
$block_content = preg_replace( '#<div class="jetpack-video-wrapper">(.*?)</div>#', '${1}', $block_content );
[190] Fix | Delete
}
[191] Fix | Delete
[192] Fix | Delete
return $block_content;
[193] Fix | Delete
}
[194] Fix | Delete
}
[195] Fix | Delete
[196] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function