PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.3
Jetpack – WP Security, Backup, Speed, & Growth v16.3
16.3 16.3-beta 16.3-a.5 16.3-a.7 16.3-a.3 16.3-a.1 16.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 All 508 releases
← All changes | modules/shortcodes/untappd-menu.php +89 -0 16.2-beta → 16.3 View file →
@@ -1,0 +1,89 @@
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 automattic/jetpack
13 + */
14 +
15 +if ( ! defined( 'ABSPATH' ) ) {
16 + exit( 0 );
17 +}
18 +
19 +/**
20 + * Display Untappd data in posts and pages.
21 + *
22 + * @phan-constructor-used-for-side-effects
23 + */
24 +class Jetpack_Untappd {
25 +
26 + /**
27 + * Constructor
28 + */
29 + public function __construct() {
30 + add_action( 'init', array( $this, 'action_init' ) );
31 + }
32 +
33 + /**
34 + * Register our shortcodes.
35 + */
36 + public function action_init() {
37 + add_shortcode( 'untappd-menu', array( $this, 'menu_shortcode' ) );
38 + }
39 +
40 + /**
41 + * [untappd-menu] shortcode.
42 + *
43 + * @param array $atts Shortocde attributes.
44 + * @param string $content Post content.
45 + */
46 + public static function menu_shortcode( $atts, $content = '' ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
47 + // Let's bail if we don't have location or theme.
48 + if ( ! isset( $atts['location'] ) || ! isset( $atts['theme'] ) ) {
49 + if ( current_user_can( 'edit_posts' ) ) {
50 + return __( 'No location or theme ID provided in the untappd-menu shortcode.', 'jetpack' );
51 + }
52 + return;
53 + }
54 +
55 + // Let's apply some defaults.
56 + $atts = shortcode_atts(
57 + array(
58 + 'location' => '',
59 + 'theme' => '',
60 + ),
61 + $atts,
62 + 'untappd-menu'
63 + );
64 +
65 + // We're going to clean the user input.
66 + $atts = array_map( 'absint', $atts );
67 +
68 + if ( $atts['location'] < 1 || $atts['theme'] < 1 ) {
69 + return;
70 + }
71 +
72 + static $untappd_menu = 1;
73 +
74 + $html = '<div id="menu-container-untappd-' . $untappd_menu . '" class="untappd-menu"></div>';
75 + $html .= '<script type="text/javascript">' . PHP_EOL;
76 + $html .= '!function(e,n){var t=document.createElement("script"),a=document.getElementsByTagName("script")[0];' . PHP_EOL;
77 + $html .= 't.async=1,a.parentNode.insertBefore(t,a),t.onload=t.onreadystatechange=function(e,a){' . PHP_EOL;
78 + $html .= '(a||!t.readyState||/loaded|complete/.test(t.readyState))&&(t.onload=t.onreadystatechange=null,t=void 0,a||n&&n())},' . PHP_EOL;
79 + $html .= 't.src=e}("https://embed-menu-preloader.untappdapi.com/embed-menu-preloader.min.js",function(){' . PHP_EOL;
80 + $html .= 'PreloadEmbedMenu( "menu-container-untappd-' . $untappd_menu . '",' . $atts['location'] . ',' . $atts['theme'] . ' )});' . PHP_EOL;
81 + $html .= '</script>';
82 +
83 + ++$untappd_menu;
84 +
85 + return $html;
86 + }
87 +}
88 +
89 +new Jetpack_Untappd();