PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 8.9.4
Jetpack – WP Security, Backup, Speed, & Growth v8.9.4
12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 13.7.2 13.8.3 13.9.2 14.0.1 14.1.1 14.2.2 14.3.1 14.4.2 All 500 releases
jetpack / modules / shortcodes / twitter-timeline.php
twitter-timeline.php
77 lines 1.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Twitter Timeline Shortcode.
4 *
5 * Examples:
6 * [twitter-timeline username=jetpack]
7 *
8 * @package Jetpack
9 */
10
11 /**
12 * Render the Twitter shortcode.
13 *
14 * @param array $atts Shortcode attributes.
15 */
16 function twitter_timeline_shortcode( $atts ) {
17 $default_atts = array(
18 'username' => '',
19 'id' => '',
20 'width' => '450',
21 'height' => '282',
22 );
23
24 $atts = shortcode_atts( $default_atts, $atts, 'twitter-timeline' );
25
26 $atts['username'] = preg_replace( '/[^A-Za-z0-9_]+/', '', $atts['username'] );
27
28 if ( empty( $atts['username'] ) && ! is_numeric( $atts['id'] ) ) {
29 return '<!-- ' . __( 'Must specify Twitter Timeline id or username.', 'jetpack' ) . ' -->';
30 }
31
32 $output = '<a class="twitter-timeline"';
33
34 /** This filter is documented in modules/shortcodes/tweet.php */
35 $partner = apply_filters( 'jetpack_twitter_partner_id', 'jetpack' );
36 if ( ! empty( $partner ) ) {
37 $output .= ' data-partner="' . esc_attr( $partner ) . '"';
38 }
39 if ( is_numeric( $atts['width'] ) ) {
40 $output .= ' data-width="' . esc_attr( $atts['width'] ) . '"';
41 }
42 if ( is_numeric( $atts['height'] ) ) {
43 $output .= ' data-height="' . esc_attr( $atts['height'] ) . '"';
44 }
45 if ( is_numeric( $atts['id'] ) ) {
46 $output .= ' data-widget-id="' . esc_attr( $atts['id'] ) . '"';
47 }
48 if ( ! empty( $atts['username'] ) ) {
49 $output .= ' href="' . esc_url( 'https://twitter.com/' . $atts['username'] ) . '"';
50 }
51
52 $output .= '>';
53
54 $output .= sprintf(
55 /* Translators: placeholder is a Twitter username. */
56 __( 'Tweets by @%s', 'jetpack' ),
57 $atts['username']
58 );
59
60 $output .= '</a>';
61
62 wp_enqueue_script( 'jetpack-twitter-timeline' );
63
64 return $output;
65 }
66 add_shortcode( 'twitter-timeline', 'twitter_timeline_shortcode' );
67
68 /**
69 * Enqueue the js used by the Twitter shortcode.
70 */
71 function twitter_timeline_js() {
72 if ( is_customize_preview() ) {
73 wp_enqueue_script( 'jetpack-twitter-timeline' );
74 }
75 }
76 add_action( 'wp_enqueue_scripts', 'twitter_timeline_js' );
77