PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 6.7
Jetpack – WP Security, Backup, Speed, & Growth v6.7
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 / untappd-menu.php

untappd-menu.php in Jetpack – WP Security, Backup, Speed, & Growth 6.7, at modules/shortcodes/untappd-menu.php

70 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Untappd Shortcodes
4 *
5 * @author kraftbj
6 *
7 * [untappd-menu location="123" theme="123"]
8 * @since 4.1.0
9 * @param location int Location ID for the Untappd venue. Required.
10 * @param theme int Theme ID for the Untappd menu. Required.
11 */
12
13 class Jetpack_Untappd {
14
15 function __construct() {
16 add_action( 'init', array( $this, 'action_init' ) );
17 }
18
19 function action_init() {
20 add_shortcode( 'untappd-menu', array( $this, 'menu_shortcode' ) );
21 }
22
23 /**
24 * [untappd-menu] shortcode.
25 */
26 static function menu_shortcode( $atts, $content = '' ) {
27 // Let's bail if we don't have location or theme.
28 if ( ! isset( $atts['location'] ) || ! isset( $atts['theme'] ) ) {
29 if ( current_user_can( 'edit_posts' ) ) {
30 return __( 'No location or theme ID provided in the untappd-menu shortcode.', 'jetpack' );
31 }
32 return;
33 }
34
35 // Let's apply some defaults.
36 $atts = shortcode_atts(
37 array(
38 'location' => '',
39 'theme' => '',
40 ),
41 $atts,
42 'untappd-menu'
43 );
44
45 // We're going to clean the user input.
46 $atts = array_map( 'absint', $atts );
47
48 if ( $atts['location'] < 1 || $atts['theme'] < 1 ) {
49 return;
50 }
51
52 static $untappd_menu = 1;
53
54 $html = '<div id="menu-container-untappd-' . $untappd_menu . '" class="untappd-menu"></div>';
55 $html .= '<script type="text/javascript">' . PHP_EOL;
56 $html .= '!function(e,n){var t=document.createElement("script"),a=document.getElementsByTagName("script")[0];' . PHP_EOL;
57 $html .= 't.async=1,a.parentNode.insertBefore(t,a),t.onload=t.onreadystatechange=function(e,a){' . PHP_EOL;
58 $html .= '(a||!t.readyState||/loaded|complete/.test(t.readyState))&&(t.onload=t.onreadystatechange=null,t=void 0,a||n&&n())},' . PHP_EOL;
59 $html .= 't.src=e}("https://embed-menu-preloader.untappdapi.com/embed-menu-preloader.min.js",function(){' . PHP_EOL;
60 $html .= 'PreloadEmbedMenu( "menu-container-untappd-' . $untappd_menu . '",' . $atts['location'] . ',' . $atts['theme'] . ' )});' . PHP_EOL;
61 $html .= '</script>';
62
63 $untappd_menu++;
64
65 return $html;
66 }
67 }
68
69 new Jetpack_Untappd();
70