PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 6.2
Jetpack – WP Security, Backup, Speed, & Growth v6.2
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 / vine.php

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

66 lines 2.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Vine shortcode
4 */
5
6 /**
7 * Vine embed code:
8 * <iframe class="vine-embed" src="https://vine.co/v/bjHh0zHdgZT" width="600" height="600" frameborder="0"></iframe>
9 * <script async src="//platform.vine.co/static/scripts/embed.js" charset="utf-8"></script>
10 *
11 * URL example:
12 * https://vine.co/v/bjHh0zHdgZT/
13 *
14 * Embed shortcode examples:
15 * [embed]https://vine.co/v/bjHh0zHdgZT[/embed]
16 * [embed width="300"]https://vine.co/v/bjHh0zHdgZT[/embed]
17 * [embed type="postcard" width="300"]https://vine.co/v/bjHh0zHdgZT[/embed]
18 **/
19
20 function vine_embed_video( $matches, $attr, $url, $rawattr ) {
21 static $vine_flag_embedded_script;
22
23 $max_height = 300;
24 $type = 'simple';
25
26 // Only allow 'postcard' or 'simple' types
27 if ( isset( $rawattr['type'] ) && $rawattr['type'] === 'postcard' )
28 $type = 'postcard';
29
30 $vine_size = Jetpack::get_content_width();
31
32 // If the user enters a value for width or height, we ignore the Jetpack::get_content_width()
33 if ( isset( $rawattr['width'] ) || isset( $rawattr['height'] ) ) {
34 // 300 is the minimum size that Vine provides for embeds. Lower than that, the postcard embeds looks weird.
35 $vine_size = max( $max_height, min( $attr['width'], $attr['height'] ) );
36 }
37
38 if ( empty( $vine_size ) ) {
39 $vine_size = $max_height;
40 }
41
42 $url = 'https://vine.co/v/' . $matches[1] . '/embed/' . $type;
43 $vine_html = sprintf( '<span class="embed-vine" style="display: block;"><iframe class="vine-embed" src="%s" width="%s" height="%s" frameborder="0"></iframe></span>', esc_url( $url ), (int) $vine_size, (int) $vine_size );
44
45 if ( $vine_flag_embedded_script !== true ) {
46 $vine_html .= '<script async src="//platform.vine.co/static/scripts/embed.js" charset="utf-8"></script>';
47 $vine_flag_embedded_script = true;
48 }
49
50 return $vine_html;
51 }
52 wp_embed_register_handler( 'jetpack_vine', '#https?://vine.co/v/([a-z0-9]+).*#i', 'vine_embed_video' );
53
54 function vine_shortcode( $atts ) {
55 global $wp_embed;
56
57 if ( empty( $atts['url'] ) )
58 return '';
59
60 if ( ! preg_match( '#https?://vine.co/v/([a-z0-9]+).*#i', $atts['url'] ) )
61 return '';
62
63 return $wp_embed->shortcode( $atts, $atts['url'] );
64 }
65 add_shortcode( 'vine', 'vine_shortcode' );
66