1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Untappd Shortcodes |
4
|
|
|
* @author kraftbj |
5
|
|
|
* |
6
|
|
|
* [untappd-menu location="123" theme="123"] |
7
|
|
|
* @since 4.1.0 |
8
|
|
|
* @param location int Location ID for the Untappd venue. Required. |
9
|
|
|
* @param theme int Theme ID for the Untappd menu. Required. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
class Jetpack_Untappd { |
13
|
|
|
|
14
|
|
|
function __construct() { |
15
|
|
|
add_action( 'init', array( $this, 'action_init' ) ); |
16
|
|
|
} |
17
|
|
|
|
18
|
|
|
function action_init() { |
19
|
|
|
add_shortcode( 'untappd-menu', array( $this, 'menu_shortcode' ) ); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* [untappd-menu] shortcode. |
24
|
|
|
* |
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( array( |
37
|
|
|
'location' => '', |
38
|
|
|
'theme' => '', |
39
|
|
|
), $atts, 'untappd-menu' ); |
40
|
|
|
|
41
|
|
|
// We're going to clean the user input. |
42
|
|
|
$atts = array_map( 'absint', $atts ); |
43
|
|
|
|
44
|
|
|
if ( $atts['location'] < 1 || $atts['theme'] < 1 ){ |
45
|
|
|
return; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
static $untappd_menu = 1; |
49
|
|
|
|
50
|
|
|
$html = '<div id="menu-container-untappd-' . $untappd_menu . '" class="untappd-menu"></div>'; |
51
|
|
|
$html .= '<script type="text/javascript">' . PHP_EOL; |
52
|
|
|
$html .= '!function(e,n){var t=document.createElement("script"),a=document.getElementsByTagName("script")[0];' . PHP_EOL; |
53
|
|
|
$html .= 't.async=1,a.parentNode.insertBefore(t,a),t.onload=t.onreadystatechange=function(e,a){' . PHP_EOL; |
54
|
|
|
$html .= '(a||!t.readyState||/loaded|complete/.test(t.readyState))&&(t.onload=t.onreadystatechange=null,t=void 0,a||n&&n())},' . PHP_EOL; |
55
|
|
|
$html .= 't.src=e}("https://embed-menu-preloader.untappdapi.com/embed-menu-preloader.min.js",function(){' . PHP_EOL; |
56
|
|
|
$html .= 'PreloadEmbedMenu( "menu-container-untappd-' . $untappd_menu . '",' . $atts["location"] . ',' . $atts["theme"] . ' )});' . PHP_EOL; |
57
|
|
|
$html .= '</script>'; |
58
|
|
|
|
59
|
|
|
$untappd_menu++; |
60
|
|
|
|
61
|
|
|
return $html; |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
new Jetpack_Untappd(); |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.