PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 6.2.3
Jetpack – WP Security, Backup, Speed, & Growth v6.2.3
16.2-beta 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 All 501 releases
jetpack / modules / shortcodes / twitter-timeline.php
twitter-timeline.php
57 lines 1.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 add_shortcode( 'twitter-timeline', 'twitter_timeline_shortcode' );
3
4 function twitter_timeline_shortcode( $atts ) {
5 $default_atts = array(
6 'username' => '',
7 'id' => '',
8 'width' => '450',
9 'height' => '282',
10 );
11
12 $atts = shortcode_atts( $default_atts, $atts, 'twitter-timeline' );
13
14 $atts['username'] = preg_replace( '/[^A-Za-z0-9_]+/', '', $atts['username'] );
15
16 if ( empty( $atts['username'] ) && ! is_numeric( $atts['id'] ) ) {
17 return '<!-- ' . __( 'Must specify Twitter Timeline id or username.', 'jetpack' ) . ' -->';
18 }
19
20 $output = '<a class="twitter-timeline"';
21
22 /** This filter is documented in modules/shortcodes/tweet.php */
23 $partner = apply_filters( 'jetpack_twitter_partner_id', 'jetpack' );
24 if ( ! empty( $partner ) ) {
25 $output .= ' data-partner="' . esc_attr( $partner ) . '"';
26 }
27 if ( is_numeric( $atts['width'] ) ) {
28 $output .= ' data-width="' . esc_attr( $atts['width'] ) . '"';
29 }
30 if ( is_numeric( $atts['height'] ) ) {
31 $output .= ' data-height="' . esc_attr( $atts['height'] ) . '"';
32 }
33 if ( is_numeric( $atts['id'] ) ) {
34 $output .= ' data-widget-id="' . esc_attr( $atts['id'] ) . '"';
35 }
36 if ( ! empty( $atts['username'] ) ) {
37 $output .= ' href="' . esc_url( 'https://twitter.com/' . $atts['username'] ) . '"';
38 }
39
40 $output .= '>';
41
42 $output .= sprintf( __( 'Tweets by @%s', 'jetpack' ), $atts['username'] );
43
44 $output .= '</a>';
45
46 wp_enqueue_script( 'jetpack-twitter-timeline' );
47
48 return $output;
49 }
50
51 function twitter_timeline_js() {
52 if ( is_customize_preview() ) {
53 wp_enqueue_script( 'jetpack-twitter-timeline' );
54 }
55 }
56 add_action( 'wp_enqueue_scripts', 'twitter_timeline_js' );
57