PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 6.9
Jetpack – WP Security, Backup, Speed, & Growth v6.9
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.9, at modules/shortcodes/vine.php

69 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 * 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
31 $vine_size = Jetpack::get_content_width();
32
33 // If the user enters a value for width or height, we ignore the Jetpack::get_content_width()
34 if ( isset( $rawattr['width'] ) || isset( $rawattr['height'] ) ) {
35 // 300 is the minimum size that Vine provides for embeds. Lower than that, the postcard embeds looks weird.
36 $vine_size = max( $max_height, min( $attr['width'], $attr['height'] ) );
37 }
38
39 if ( empty( $vine_size ) ) {
40 $vine_size = $max_height;
41 }
42
43 $url = 'https://vine.co/v/' . $matches[1] . '/embed/' . $type;
44 $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 );
45
46 if ( $vine_flag_embedded_script !== true ) {
47 $vine_html .= '<script async src="//platform.vine.co/static/scripts/embed.js" charset="utf-8"></script>';
48 $vine_flag_embedded_script = true;
49 }
50
51 return $vine_html;
52 }
53 wp_embed_register_handler( 'jetpack_vine', '#https?://vine.co/v/([a-z0-9]+).*#i', 'vine_embed_video' );
54
55 function vine_shortcode( $atts ) {
56 global $wp_embed;
57
58 if ( empty( $atts['url'] ) ) {
59 return '';
60 }
61
62 if ( ! preg_match( '#https?://vine.co/v/([a-z0-9]+).*#i', $atts['url'] ) ) {
63 return '';
64 }
65
66 return $wp_embed->shortcode( $atts, $atts['url'] );
67 }
68 add_shortcode( 'vine', 'vine_shortcode' );
69