Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 31 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
| Jetpack_Untappd | |
0.00% |
0 / 28 |
|
0.00% |
0 / 3 |
72 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| action_init | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| menu_shortcode | |
0.00% |
0 / 26 |
|
0.00% |
0 / 1 |
42 | |||
| 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(); |