Edit File by line
/home/zeestwma/richards.../wp-conte.../plugins/jetpack/modules/shortcod...
File: tweet.php
<?php //phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
[0] Fix | Delete
/**
[1] Fix | Delete
* Tweet shortcode.
[2] Fix | Delete
* Params map to key value pairs, and all but tweet are optional:
[3] Fix | Delete
* tweet = id or permalink url* (Required)
[4] Fix | Delete
* align = none|left|right|center
[5] Fix | Delete
* width = number in pixels example: width="300"
[6] Fix | Delete
* lang = en|fr|de|ko|etc... language country code.
[7] Fix | Delete
* hide_thread = true | false **
[8] Fix | Delete
* hide_media = true | false **
[9] Fix | Delete
*
[10] Fix | Delete
* Basic:
[11] Fix | Delete
* [tweet https://twitter.com/jack/statuses/20 width="350"]
[12] Fix | Delete
*
[13] Fix | Delete
* More parameters and another tweet syntax admitted:
[14] Fix | Delete
* [tweet tweet="https://twitter.com/jack/statuses/20" align="left" width="350" align="center" lang="es"]
[15] Fix | Delete
*
[16] Fix | Delete
* @package automattic/jetpack
[17] Fix | Delete
*/
[18] Fix | Delete
[19] Fix | Delete
if ( ! defined( 'ABSPATH' ) ) {
[20] Fix | Delete
exit( 0 );
[21] Fix | Delete
}
[22] Fix | Delete
[23] Fix | Delete
add_shortcode( 'tweet', array( 'Jetpack_Tweet', 'jetpack_tweet_shortcode' ) );
[24] Fix | Delete
[25] Fix | Delete
/**
[26] Fix | Delete
* Tweet Shortcode class.
[27] Fix | Delete
*/
[28] Fix | Delete
class Jetpack_Tweet {
[29] Fix | Delete
[30] Fix | Delete
/**
[31] Fix | Delete
* Array of arguments about a tweet.
[32] Fix | Delete
*
[33] Fix | Delete
* @var array
[34] Fix | Delete
*/
[35] Fix | Delete
public static $provider_args;
[36] Fix | Delete
[37] Fix | Delete
/**
[38] Fix | Delete
* Parse shortcode arguments and render its output.
[39] Fix | Delete
*
[40] Fix | Delete
* @since 4.5.0
[41] Fix | Delete
*
[42] Fix | Delete
* @param array $atts Shortcode parameters.
[43] Fix | Delete
*
[44] Fix | Delete
* @return string
[45] Fix | Delete
*/
[46] Fix | Delete
public static function jetpack_tweet_shortcode( $atts ) {
[47] Fix | Delete
global $wp_embed;
[48] Fix | Delete
[49] Fix | Delete
$default_atts = array(
[50] Fix | Delete
'tweet' => '',
[51] Fix | Delete
'align' => 'none',
[52] Fix | Delete
'width' => '',
[53] Fix | Delete
'lang' => 'en',
[54] Fix | Delete
'hide_thread' => 'false',
[55] Fix | Delete
'hide_media' => 'false',
[56] Fix | Delete
);
[57] Fix | Delete
[58] Fix | Delete
$attr = shortcode_atts( $default_atts, $atts );
[59] Fix | Delete
[60] Fix | Delete
self::$provider_args = $attr;
[61] Fix | Delete
[62] Fix | Delete
/*
[63] Fix | Delete
* figure out the tweet id for the requested tweet
[64] Fix | Delete
* supporting both omitted attributes and tweet="tweet_id"
[65] Fix | Delete
* and supporting both an id and a URL
[66] Fix | Delete
*/
[67] Fix | Delete
if ( empty( $attr['tweet'] ) && ! empty( $atts[0] ) ) {
[68] Fix | Delete
$attr['tweet'] = $atts[0];
[69] Fix | Delete
}
[70] Fix | Delete
[71] Fix | Delete
if ( ctype_digit( $attr['tweet'] ) ) {
[72] Fix | Delete
$id = 'https://twitter.com/jetpack/status/' . $attr['tweet'];
[73] Fix | Delete
$tweet_id = (int) $attr['tweet'];
[74] Fix | Delete
} else {
[75] Fix | Delete
preg_match( '/^http(s|):\/\/twitter\.com(\/\#\!\/|\/)([a-zA-Z0-9_]{1,20})\/status(es)*\/(\d+)$/', $attr['tweet'], $urlbits );
[76] Fix | Delete
[77] Fix | Delete
if ( isset( $urlbits[5] ) && (int) $urlbits[5] ) {
[78] Fix | Delete
$id = 'https://twitter.com/' . $urlbits[3] . '/status/' . (int) $urlbits[5];
[79] Fix | Delete
$tweet_id = (int) $urlbits[5];
[80] Fix | Delete
} else {
[81] Fix | Delete
return '<!-- Invalid tweet id -->';
[82] Fix | Delete
}
[83] Fix | Delete
}
[84] Fix | Delete
[85] Fix | Delete
// Add shortcode arguments to provider URL.
[86] Fix | Delete
add_filter( 'oembed_fetch_url', array( 'Jetpack_Tweet', 'jetpack_tweet_url_extra_args' ), 10, 3 );
[87] Fix | Delete
[88] Fix | Delete
/*
[89] Fix | Delete
* In Jetpack, we use $wp_embed->shortcode() to return the tweet output.
[90] Fix | Delete
* @see https://github.com/Automattic/jetpack/pull/11173
[91] Fix | Delete
*/
[92] Fix | Delete
$output = $wp_embed->shortcode( $atts, $id );
[93] Fix | Delete
[94] Fix | Delete
// Clean up filter.
[95] Fix | Delete
remove_filter( 'oembed_fetch_url', array( 'Jetpack_Tweet', 'jetpack_tweet_url_extra_args' ), 10 );
[96] Fix | Delete
[97] Fix | Delete
/** This action is documented in modules/widgets/social-media-icons.php */
[98] Fix | Delete
do_action( 'jetpack_bump_stats_extras', 'embeds', 'tweet' );
[99] Fix | Delete
[100] Fix | Delete
if ( class_exists( 'Jetpack_AMP_Support' ) && Jetpack_AMP_Support::is_amp_request() ) {
[101] Fix | Delete
$width = ! empty( $attr['width'] ) ? $attr['width'] : 600;
[102] Fix | Delete
$height = 480;
[103] Fix | Delete
$output = sprintf(
[104] Fix | Delete
'<amp-twitter data-tweetid="%1$s" layout="responsive" width="%2$d" height="%3$d"></amp-twitter>',
[105] Fix | Delete
esc_attr( $tweet_id ),
[106] Fix | Delete
absint( $width ),
[107] Fix | Delete
absint( $height )
[108] Fix | Delete
);
[109] Fix | Delete
} else {
[110] Fix | Delete
// Add Twitter widgets.js script to the footer.
[111] Fix | Delete
add_action( 'wp_footer', array( 'Jetpack_Tweet', 'jetpack_tweet_shortcode_script' ) );
[112] Fix | Delete
}
[113] Fix | Delete
[114] Fix | Delete
return $output;
[115] Fix | Delete
}
[116] Fix | Delete
[117] Fix | Delete
/**
[118] Fix | Delete
* Adds parameters to URL used to fetch the tweet.
[119] Fix | Delete
*
[120] Fix | Delete
* @since 4.5.0
[121] Fix | Delete
*
[122] Fix | Delete
* @param string $provider URL of provider that supplies the tweet we're requesting.
[123] Fix | Delete
* @param string $url URL of tweet to embed.
[124] Fix | Delete
* @param array $args Parameters supplied to shortcode and passed to wp_oembed_get.
[125] Fix | Delete
*
[126] Fix | Delete
* @return string
[127] Fix | Delete
*/
[128] Fix | Delete
public static function jetpack_tweet_url_extra_args( $provider, $url, $args = array() ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
[129] Fix | Delete
foreach ( self::$provider_args as $key => $value ) {
[130] Fix | Delete
switch ( $key ) {
[131] Fix | Delete
case 'align':
[132] Fix | Delete
case 'lang':
[133] Fix | Delete
case 'hide_thread':
[134] Fix | Delete
case 'hide_media':
[135] Fix | Delete
$provider = add_query_arg( $key, $value, $provider );
[136] Fix | Delete
break;
[137] Fix | Delete
}
[138] Fix | Delete
}
[139] Fix | Delete
[140] Fix | Delete
// Disable script since we're enqueing it in our own way in the footer.
[141] Fix | Delete
$provider = add_query_arg( 'omit_script', 'true', $provider );
[142] Fix | Delete
[143] Fix | Delete
// Twitter doesn't support maxheight so don't send it.
[144] Fix | Delete
$provider = remove_query_arg( 'maxheight', $provider );
[145] Fix | Delete
[146] Fix | Delete
/**
[147] Fix | Delete
* Filter the Twitter Partner ID.
[148] Fix | Delete
*
[149] Fix | Delete
* @module shortcodes
[150] Fix | Delete
*
[151] Fix | Delete
* @since 4.6.0
[152] Fix | Delete
*
[153] Fix | Delete
* @param string $partner_id Twitter partner ID.
[154] Fix | Delete
*/
[155] Fix | Delete
$partner = apply_filters( 'jetpack_twitter_partner_id', 'jetpack' );
[156] Fix | Delete
[157] Fix | Delete
// Add Twitter partner ID to track embeds from Jetpack.
[158] Fix | Delete
if ( ! empty( $partner ) ) {
[159] Fix | Delete
$provider = add_query_arg( 'partner', $partner, $provider );
[160] Fix | Delete
}
[161] Fix | Delete
[162] Fix | Delete
return $provider;
[163] Fix | Delete
}
[164] Fix | Delete
[165] Fix | Delete
/**
[166] Fix | Delete
* Enqueue front end assets.
[167] Fix | Delete
*
[168] Fix | Delete
* @since 4.5.0
[169] Fix | Delete
*/
[170] Fix | Delete
public static function jetpack_tweet_shortcode_script() {
[171] Fix | Delete
if ( ! wp_script_is( 'twitter-widgets', 'registered' ) ) {
[172] Fix | Delete
wp_register_script( 'twitter-widgets', 'https://platform.twitter.com/widgets.js', array(), JETPACK__VERSION, true );
[173] Fix | Delete
wp_print_scripts( 'twitter-widgets' );
[174] Fix | Delete
}
[175] Fix | Delete
}
[176] Fix | Delete
} // class end
[177] Fix | Delete
[178] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function