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

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

84 lines 2.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php //phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
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 * @package Jetpack
13 */
14
15 /**
16 * Display Untappd data in posts and pages.
17 */
18 class Jetpack_Untappd {
19
20 /**
21 * Constructor
22 */
23 public function __construct() {
24 add_action( 'init', array( $this, 'action_init' ) );
25 }
26
27 /**
28 * Register our shortcodes.
29 */
30 public function action_init() {
31 add_shortcode( 'untappd-menu', array( $this, 'menu_shortcode' ) );
32 }
33
34 /**
35 * [untappd-menu] shortcode.
36 *
37 * @param array $atts Shortocde attributes.
38 * @param string $content Post content.
39 */
40 public static function menu_shortcode( $atts, $content = '' ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
41 // Let's bail if we don't have location or theme.
42 if ( ! isset( $atts['location'] ) || ! isset( $atts['theme'] ) ) {
43 if ( current_user_can( 'edit_posts' ) ) {
44 return __( 'No location or theme ID provided in the untappd-menu shortcode.', 'jetpack' );
45 }
46 return;
47 }
48
49 // Let's apply some defaults.
50 $atts = shortcode_atts(
51 array(
52 'location' => '',
53 'theme' => '',
54 ),
55 $atts,
56 'untappd-menu'
57 );
58
59 // We're going to clean the user input.
60 $atts = array_map( 'absint', $atts );
61
62 if ( $atts['location'] < 1 || $atts['theme'] < 1 ) {
63 return;
64 }
65
66 static $untappd_menu = 1;
67
68 $html = '<div id="menu-container-untappd-' . $untappd_menu . '" class="untappd-menu"></div>';
69 $html .= '<script type="text/javascript">' . PHP_EOL;
70 $html .= '!function(e,n){var t=document.createElement("script"),a=document.getElementsByTagName("script")[0];' . PHP_EOL;
71 $html .= 't.async=1,a.parentNode.insertBefore(t,a),t.onload=t.onreadystatechange=function(e,a){' . PHP_EOL;
72 $html .= '(a||!t.readyState||/loaded|complete/.test(t.readyState))&&(t.onload=t.onreadystatechange=null,t=void 0,a||n&&n())},' . PHP_EOL;
73 $html .= 't.src=e}("https://embed-menu-preloader.untappdapi.com/embed-menu-preloader.min.js",function(){' . PHP_EOL;
74 $html .= 'PreloadEmbedMenu( "menu-container-untappd-' . $untappd_menu . '",' . $atts['location'] . ',' . $atts['theme'] . ' )});' . PHP_EOL;
75 $html .= '</script>';
76
77 $untappd_menu++;
78
79 return $html;
80 }
81 }
82
83 new Jetpack_Untappd();
84