| Conditions | 7 |
| Paths | 17 |
| Total Lines | 41 |
| Code Lines | 24 |
| Lines | 6 |
| Ratio | 14.63 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 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 | if ( is_numeric( $atts['width'] ) ) { |
||
| 23 | $output .= ' data-width="' . esc_attr( $atts['width'] ) . '"'; |
||
| 24 | } |
||
| 25 | View Code Duplication | if ( is_numeric( $atts['height'] ) ) { |
|
| 26 | $output .= ' data-height="' . esc_attr( $atts['height'] ) . '"'; |
||
| 27 | } |
||
| 28 | View Code Duplication | if ( is_numeric( $atts['id'] ) ) { |
|
| 29 | $output .= ' data-widget-id="' . esc_attr( $atts['id'] ) . '"'; |
||
| 30 | } |
||
| 31 | if ( ! empty( $atts['username'] ) ) { |
||
| 32 | $output .= ' href="' . esc_url( 'https://twitter.com/' . $atts['username'] ) . '"'; |
||
| 33 | } |
||
| 34 | |||
| 35 | $output .= '>'; |
||
| 36 | |||
| 37 | $output .= sprintf( __( 'Tweets by @%s', 'jetpack' ), $atts['username'] ); |
||
| 38 | |||
| 39 | $output .= '</a>'; |
||
| 40 | |||
| 41 | wp_enqueue_script( 'jetpack-twitter-timeline' ); |
||
| 42 | |||
| 43 | return $output; |
||
| 44 | } |
||
| 45 | |||
| 52 |