Edit File by line
/home/zeestwma/richards.../wp-conte.../plugins/jetpack/modules/shortcod...
File: twitter.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* Twitter/X oEmbed proxy functionality.
[2] Fix | Delete
*
[3] Fix | Delete
* This file handles proxying Twitter/X oEmbed requests through Automattic's infrastructure
[4] Fix | Delete
* to minimize issues with rate limiting with 404 responses from Twitter/X.
[5] Fix | Delete
*
[6] Fix | Delete
* Unlike tweet.php which handles the [tweet] shortcode, this file provides core oEmbed support
[7] Fix | Delete
* and is force-loaded via module-extras.php regardless of module status.
[8] Fix | Delete
*
[9] Fix | Delete
* @package automattic/jetpack
[10] Fix | Delete
* @since 14.5
[11] Fix | Delete
*/
[12] Fix | Delete
[13] Fix | Delete
use Automattic\Jetpack\Connection\Client;
[14] Fix | Delete
use Automattic\Jetpack\Constants;
[15] Fix | Delete
use Automattic\Jetpack\Status;
[16] Fix | Delete
[17] Fix | Delete
if ( ! defined( 'ABSPATH' ) ) {
[18] Fix | Delete
exit( 0 );
[19] Fix | Delete
}
[20] Fix | Delete
[21] Fix | Delete
/**
[22] Fix | Delete
* Update Twitter providers to use Automattic's Twitter/X oEmbed proxy.
[23] Fix | Delete
*
[24] Fix | Delete
* See paFLeq-3QD-p2.
[25] Fix | Delete
*
[26] Fix | Delete
* @param string $provider The URL of the oEmbed provider.
[27] Fix | Delete
*
[28] Fix | Delete
* @return string The modified URL of the oEmbed provider.
[29] Fix | Delete
*/
[30] Fix | Delete
function jetpack_proxy_twitter_oembed_provider( $provider ) {
[31] Fix | Delete
if ( ! wp_startswith( $provider, 'https://publish.twitter.com/oembed' ) ) {
[32] Fix | Delete
return $provider;
[33] Fix | Delete
}
[34] Fix | Delete
[35] Fix | Delete
// Allow other plugins to override the proxy URL. This constant should be set on the WordPress.com side
[36] Fix | Delete
// to handle proxying after we're authenticated the request with the Jetpack token.
[37] Fix | Delete
$oembed_proxy_url = Constants::is_defined( 'JETPACK__TWITTER_OEMBED_PROXY_URL' )
[38] Fix | Delete
? Constants::get_constant( 'JETPACK__TWITTER_OEMBED_PROXY_URL' )
[39] Fix | Delete
: '';
[40] Fix | Delete
[41] Fix | Delete
// If we don't have a proxy URL, then we'll try to proxy through the WordPress.com.
[42] Fix | Delete
// To that end, we need to make sure that we're connected to WP.com and that we're not in offline mode.
[43] Fix | Delete
if ( empty( $oembed_proxy_url ) ) {
[44] Fix | Delete
if ( ! Jetpack::is_connection_ready() || ( new Status() )->is_offline_mode() ) {
[45] Fix | Delete
return $provider;
[46] Fix | Delete
}
[47] Fix | Delete
[48] Fix | Delete
$oembed_proxy_url = esc_url_raw(
[49] Fix | Delete
sprintf(
[50] Fix | Delete
'%s/wpcom/v2/oembed-proxy',
[51] Fix | Delete
JETPACK__WPCOM_JSON_API_BASE,
[52] Fix | Delete
Jetpack_Options::get_option( 'id' )
[53] Fix | Delete
)
[54] Fix | Delete
);
[55] Fix | Delete
[56] Fix | Delete
add_filter( 'oembed_remote_get_args', 'jetpack_twitter_oembed_remote_get_args', 10, 2 );
[57] Fix | Delete
}
[58] Fix | Delete
[59] Fix | Delete
return str_replace( 'https://publish.twitter.com/oembed', $oembed_proxy_url, $provider );
[60] Fix | Delete
}
[61] Fix | Delete
add_filter( 'oembed_fetch_url', 'jetpack_proxy_twitter_oembed_provider', 10 );
[62] Fix | Delete
[63] Fix | Delete
/**
[64] Fix | Delete
* Add JP auth headers if we're proxying through WP.com.
[65] Fix | Delete
*
[66] Fix | Delete
* @param array $args oEmbed remote get arguments.
[67] Fix | Delete
* @param string $url URL to be inspected.
[68] Fix | Delete
*/
[69] Fix | Delete
function jetpack_twitter_oembed_remote_get_args( $args, $url ) {
[70] Fix | Delete
if ( ! wp_startswith( $url, Constants::get_constant( 'JETPACK__WPCOM_JSON_API_BASE' ) ) ) {
[71] Fix | Delete
return $args;
[72] Fix | Delete
}
[73] Fix | Delete
[74] Fix | Delete
$method = 'GET';
[75] Fix | Delete
$signed_request = Client::build_signed_request(
[76] Fix | Delete
compact( 'url', 'method' )
[77] Fix | Delete
);
[78] Fix | Delete
[79] Fix | Delete
if ( is_wp_error( $signed_request ) ) {
[80] Fix | Delete
return $args;
[81] Fix | Delete
}
[82] Fix | Delete
[83] Fix | Delete
return $signed_request['request'];
[84] Fix | Delete
}
[85] Fix | Delete
[86] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function