PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 7.1
Jetpack – WP Security, Backup, Speed, & Growth v7.1
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 / twitchtv.php

twitchtv.php in Jetpack – WP Security, Backup, Speed, & Growth 7.1, at modules/shortcodes/twitchtv.php

75 lines 2.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * twitch.tv shortcode
4 * [twitchtv url='http://www.twitch.tv/paperbat' height='378' width='620' autoplay='false']
5 * [twitchtv url='http://www.twitch.tv/paperbat/b/323486192' height='378' width='620' autoplay='false']
6 **/
7
8 /**
9 * (Live URL) http://www.twitch.tv/paperbat
10 *
11 * <iframe src="https://player.twitch.tv/?autoplay=false&#038;muted=false&#038;channel=paperbat" width="620" height="378" frameborder="0" scrolling="no" allowfullscreen></iframe>
12 *
13 * (Archive URL) http://www.twitch.tv/paperbat/v/323486192
14 *
15 * <iframe src="https://player.twitch.tv/?autoplay=false&#038;muted=false&#038;video=v323486192" width="620" height="378" frameborder="0" scrolling="no" allowfullscreen></iframe>
16 *
17 * @param $atts array User supplied shortcode arguments.
18 *
19 * @return string HTML output of the shortcode.
20 */
21 function wpcom_twitchtv_shortcode( $atts ) {
22 $attr = shortcode_atts(
23 array(
24 'height' => 378,
25 'width' => 620,
26 'url' => '',
27 'autoplay' => 'false',
28 'muted' => 'false',
29 'time' => null,
30 ),
31 $atts
32 );
33
34 if ( empty( $attr['url'] ) ) {
35 return '<!-- Invalid twitchtv URL -->';
36 }
37
38 preg_match( '|^http://www.twitch.tv/([^/?]+)(/v/(\d+))?|i', $attr['url'], $match );
39
40 $url_args = array(
41 'autoplay' => ( false !== $attr['autoplay'] && 'false' !== $attr['autoplay'] ) ? 'true' : 'false',
42 'muted' => ( false !== $attr['muted'] && 'false' !== $attr['muted'] ) ? 'true' : 'false',
43 'time' => $attr['time'],
44 );
45
46 $width = intval( $attr['width'] );
47 $height = intval( $attr['height'] );
48
49 $user_id = $match[1];
50 $video_id = 0;
51 if ( ! empty( $match[3] ) ) {
52 $video_id = (int) $match[3];
53 }
54
55 do_action( 'jetpack_bump_stats_extras', 'twitchtv', 'shortcode' );
56
57 if ( $video_id > 0 ) {
58 $url_args['video'] = 'v' . $video_id;
59 } else {
60 $url_args['channel'] = $user_id;
61 }
62
63 $url = add_query_arg( $url_args, 'https://player.twitch.tv/' );
64
65 return sprintf(
66 '<iframe src="%s" width="%d" height="%d" frameborder="0" scrolling="no" allowfullscreen></iframe>',
67 esc_url( $url ),
68 esc_attr( $width ),
69 esc_attr( $height )
70 );
71 }
72
73 add_shortcode( 'twitch', 'wpcom_twitchtv_shortcode' );
74 add_shortcode( 'twitchtv', 'wpcom_twitchtv_shortcode' );
75