Edit File by line
/home/zeestwma/richards.../wp-conte.../plugins/jetpack
File: functions.compat.php
<?php // phpcs:ignore WordPress.Files.FileName.NotHyphenatedLowercase
[0] Fix | Delete
/**
[1] Fix | Delete
* Compatibility functions for YouTube URLs and WP.com helper functions.
[2] Fix | Delete
*
[3] Fix | Delete
* @package automattic/jetpack
[4] Fix | Delete
*/
[5] Fix | Delete
[6] Fix | Delete
use Automattic\Jetpack\Connection\Manager as Connection_Manager;
[7] Fix | Delete
[8] Fix | Delete
/**
[9] Fix | Delete
* Required for class.media-extractor.php to match expected function naming convention.
[10] Fix | Delete
*
[11] Fix | Delete
* @param string|array $url Can be just the $url or the whole $atts array.
[12] Fix | Delete
* @return bool|mixed The Youtube video ID via jetpack_get_youtube_id
[13] Fix | Delete
*/
[14] Fix | Delete
function jetpack_shortcode_get_youtube_id( $url ) {
[15] Fix | Delete
return jetpack_get_youtube_id( $url );
[16] Fix | Delete
}
[17] Fix | Delete
[18] Fix | Delete
/**
[19] Fix | Delete
* Extract video ID from a YouTube url.
[20] Fix | Delete
*
[21] Fix | Delete
* @param string|array $url YouTube URL.
[22] Fix | Delete
* @return bool|mixed The Youtube video ID
[23] Fix | Delete
*/
[24] Fix | Delete
function jetpack_get_youtube_id( $url ) {
[25] Fix | Delete
// Do we have an $atts array? Get first att
[26] Fix | Delete
if ( is_array( $url ) ) {
[27] Fix | Delete
$url = reset( $url );
[28] Fix | Delete
}
[29] Fix | Delete
[30] Fix | Delete
$url = jetpack_youtube_sanitize_url( $url );
[31] Fix | Delete
$url = wp_parse_url( $url );
[32] Fix | Delete
$id = false;
[33] Fix | Delete
[34] Fix | Delete
if ( ! isset( $url['query'] ) ) {
[35] Fix | Delete
return false;
[36] Fix | Delete
}
[37] Fix | Delete
[38] Fix | Delete
parse_str( $url['query'], $qargs );
[39] Fix | Delete
[40] Fix | Delete
if ( ! isset( $qargs['v'] ) && ! isset( $qargs['list'] ) ) {
[41] Fix | Delete
return false;
[42] Fix | Delete
}
[43] Fix | Delete
[44] Fix | Delete
if ( isset( $qargs['list'] ) ) {
[45] Fix | Delete
$id = preg_replace( '|[^_a-z0-9-]|i', '', $qargs['list'] );
[46] Fix | Delete
}
[47] Fix | Delete
[48] Fix | Delete
if ( empty( $id ) ) {
[49] Fix | Delete
$id = preg_replace( '|[^_a-z0-9-]|i', '', $qargs['v'] );
[50] Fix | Delete
}
[51] Fix | Delete
[52] Fix | Delete
return $id;
[53] Fix | Delete
}
[54] Fix | Delete
[55] Fix | Delete
if ( ! function_exists( 'jetpack_youtube_sanitize_url' ) ) :
[56] Fix | Delete
/**
[57] Fix | Delete
* Normalizes a YouTube URL to include a v= parameter and a query string free of encoded ampersands.
[58] Fix | Delete
*
[59] Fix | Delete
* @param string|array $url YouTube URL.
[60] Fix | Delete
* @return string|false The normalized URL or false if input is invalid.
[61] Fix | Delete
*/
[62] Fix | Delete
function jetpack_youtube_sanitize_url( $url ) {
[63] Fix | Delete
if ( is_array( $url ) && isset( $url['url'] ) ) {
[64] Fix | Delete
$url = $url['url'];
[65] Fix | Delete
}
[66] Fix | Delete
if ( ! is_string( $url ) ) {
[67] Fix | Delete
return false;
[68] Fix | Delete
}
[69] Fix | Delete
[70] Fix | Delete
$url = trim( $url, ' "' );
[71] Fix | Delete
$url = trim( $url );
[72] Fix | Delete
$url = str_replace( array( 'youtu.be/', '/v/', '#!v=', '&amp;', '&#038;', 'playlist' ), array( 'youtu.be/?v=', '/?v=', '?v=', '&', '&', 'videoseries' ), $url );
[73] Fix | Delete
[74] 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.
[75] Fix | Delete
$query_string_start = strpos( $url, '?' );
[76] Fix | Delete
[77] Fix | Delete
if ( false !== $query_string_start ) {
[78] Fix | Delete
$url = substr( $url, 0, $query_string_start + 1 ) . str_replace( '?', '&', substr( $url, $query_string_start + 1 ) );
[79] Fix | Delete
}
[80] Fix | Delete
[81] Fix | Delete
return $url;
[82] Fix | Delete
}
[83] Fix | Delete
endif;
[84] Fix | Delete
[85] Fix | Delete
/**
[86] Fix | Delete
* Merge in three string helper functions from WPCOM to make working with strings easier.
[87] Fix | Delete
*
[88] Fix | Delete
* @see WPCOM/wp-content/mu-plugins/string-helpers.php
[89] Fix | Delete
*/
[90] Fix | Delete
if ( ! function_exists( 'wp_startswith' ) ) :
[91] Fix | Delete
/**
[92] Fix | Delete
* Check whether a string starts with a specific substring.
[93] Fix | Delete
*
[94] Fix | Delete
* @param string $haystack String we are filtering.
[95] Fix | Delete
* @param string $needle The substring we are looking for.
[96] Fix | Delete
* @return bool
[97] Fix | Delete
*/
[98] Fix | Delete
function wp_startswith( $haystack, $needle ) {
[99] Fix | Delete
if ( ! $haystack || ! $needle || ! is_scalar( $haystack ) || ! is_scalar( $needle ) ) {
[100] Fix | Delete
return false;
[101] Fix | Delete
}
[102] Fix | Delete
[103] Fix | Delete
$haystack = (string) $haystack;
[104] Fix | Delete
$needle = (string) $needle;
[105] Fix | Delete
[106] Fix | Delete
return str_starts_with( $haystack, $needle );
[107] Fix | Delete
}
[108] Fix | Delete
endif;
[109] Fix | Delete
[110] Fix | Delete
if ( ! function_exists( 'wp_endswith' ) ) :
[111] Fix | Delete
/**
[112] Fix | Delete
* Check whether a string ends with a specific substring.
[113] Fix | Delete
*
[114] Fix | Delete
* @param string $haystack String we are filtering.
[115] Fix | Delete
* @param string $needle The substring we are looking for.
[116] Fix | Delete
* @return bool
[117] Fix | Delete
*/
[118] Fix | Delete
function wp_endswith( $haystack, $needle ) {
[119] Fix | Delete
if ( ! $haystack || ! $needle || ! is_scalar( $haystack ) || ! is_scalar( $needle ) ) {
[120] Fix | Delete
return false;
[121] Fix | Delete
}
[122] Fix | Delete
[123] Fix | Delete
$haystack = (string) $haystack;
[124] Fix | Delete
$needle = (string) $needle;
[125] Fix | Delete
[126] Fix | Delete
return str_ends_with( $haystack, $needle );
[127] Fix | Delete
}
[128] Fix | Delete
endif;
[129] Fix | Delete
[130] Fix | Delete
if ( ! function_exists( 'wp_in' ) ) :
[131] Fix | Delete
/**
[132] Fix | Delete
* Checks whether a string contains a specific substring.
[133] Fix | Delete
*
[134] Fix | Delete
* @param string $needle The substring we are looking for.
[135] Fix | Delete
* @param string $haystack String we are filtering.
[136] Fix | Delete
* @return bool
[137] Fix | Delete
*/
[138] Fix | Delete
function wp_in( $needle, $haystack ) {
[139] Fix | Delete
if ( ! $haystack || ! $needle || ! is_scalar( $haystack ) || ! is_scalar( $needle ) ) {
[140] Fix | Delete
return false;
[141] Fix | Delete
}
[142] Fix | Delete
[143] Fix | Delete
$haystack = (string) $haystack;
[144] Fix | Delete
$needle = (string) $needle;
[145] Fix | Delete
[146] Fix | Delete
return str_contains( $haystack, $needle );
[147] Fix | Delete
}
[148] Fix | Delete
endif;
[149] Fix | Delete
[150] Fix | Delete
/**
[151] Fix | Delete
* Deprecated connection function.
[152] Fix | Delete
*
[153] Fix | Delete
* @param string $text Deprecated.
[154] Fix | Delete
* @deprecated 7.5 Use Connection_Manager instead.
[155] Fix | Delete
*/
[156] Fix | Delete
function jetpack_sha1_base64( $text ) {
[157] Fix | Delete
$connection = new Connection_Manager();
[158] Fix | Delete
return $connection->sha1_base64( $text );
[159] Fix | Delete
}
[160] Fix | Delete
[161] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function