| @@ -1,8 +1,10 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | namespace Booktics\Assets; |
| 4 | 4 | |
| 5 | +if ( ! defined( 'ABSPATH' ) ) exit; | |
| 6 | + | |
| 5 | 7 | /** |
| 6 | 8 | * Manage all admin scripts and styles |
| 7 | 9 | */ |
| 8 | 10 | class Admin_Assets extends Base_Assets { |
| @@ -16,8 +18,9 @@ | ||
| 16 | 18 | $this, |
| 17 | 19 | 'register_styles_scripts' |
| 18 | 20 | ] ); |
| 19 | 21 | add_action( 'admin_enqueue_scripts', [ $this, 'enqueue' ] ); |
| 22 | + add_action( 'admin_footer', [ $this, 'admin_helpscout_beacon' ] ); | |
| 20 | 23 | } |
| 21 | 24 | |
| 22 | 25 | /** |
| 23 | 26 | * Enqueue scripts and styles |
| @@ -24,12 +27,13 @@ | ||
| 24 | 27 | * |
| 25 | 28 | * @return void |
| 26 | 29 | */ |
| 27 | 30 | public function enqueue() { |
| 28 | - $screen = get_current_screen(); | |
| 31 | + $screen = get_current_screen(); | |
| 29 | 32 | if ( $screen->base !== 'toplevel_page_booktics') { |
| 30 | 33 | return; |
| 31 | 34 | } |
| 35 | + $this->enqueue_i18n_loader(); | |
| 32 | 36 | wp_enqueue_style( 'wp-color-picker' ); |
| 33 | 37 | wp_enqueue_style( 'booktics-admin-style' ); |
| 34 | 38 | wp_enqueue_style( 'booktics-vendor' ); |
| 35 | 39 | |
| @@ -39,8 +43,13 @@ | ||
| 39 | 43 | wp_enqueue_script( 'booktics-dashboard-scripts' ); |
| 40 | 44 | |
| 41 | 45 | wp_localize_script( 'booktics-packages', 'booktics', Localize::get_admin() ); |
| 42 | 46 | wp_localize_script( 'booktics-packages', 'booktics_enabled_modules', booktics_get_enabled_modules() ); |
| 47 | + | |
| 48 | + if ( function_exists( 'wp_set_script_translations' ) ) { | |
| 49 | + wp_set_script_translations( 'booktics-dashboard-scripts', 'booktics' ); | |
| 50 | + } | |
| 51 | + | |
| 43 | 52 | } |
| 44 | 53 | |
| 45 | 54 | /** |
| 46 | 55 | * Get all scripts |
| @@ -64,9 +73,12 @@ | ||
| 64 | 73 | 'deps' => [ |
| 65 | 74 | 'wp-api-fetch', |
| 66 | 75 | 'wp-components', |
| 67 | 76 | 'wp-compose', |
| 68 | - 'wp-i18n' | |
| 77 | + 'wp-i18n', | |
| 78 | + 'wp-element', | |
| 79 | + 'wp-data', | |
| 80 | + 'wp-hooks', | |
| 69 | 81 | ], |
| 70 | 82 | 'in_footer' => true, |
| 71 | 83 | ], |
| 72 | 84 | ]; |
| @@ -89,6 +101,62 @@ | ||
| 89 | 101 | ], |
| 90 | 102 | ]; |
| 91 | 103 | |
| 92 | 104 | return apply_filters( 'booktics_admin_styles', $styles ); |
| 105 | + } | |
| 106 | + | |
| 107 | + /** | |
| 108 | + * Add HelpScout script to admin footer | |
| 109 | + * | |
| 110 | + * @return void | |
| 111 | + */ | |
| 112 | + public function admin_helpscout_beacon() { | |
| 113 | + $screen = function_exists( 'get_current_screen' ) ? get_current_screen() : null; | |
| 114 | + $is_booktics_screen = false; | |
| 115 | + | |
| 116 | + if ( $screen ) { | |
| 117 | + $screen_id = isset( $screen->id ) ? $screen->id : ''; | |
| 118 | + | |
| 119 | + // Check: only load on Booktics top-level admin page | |
| 120 | + if ( 'toplevel_page_booktics' === $screen_id ) { | |
| 121 | + $is_booktics_screen = true; | |
| 122 | + } | |
| 123 | + } | |
| 124 | + | |
| 125 | + // Allow overriding detection via filter. | |
| 126 | + $is_booktics_screen = apply_filters( 'booktics_is_admin_screen', $is_booktics_screen, $screen ); | |
| 127 | + | |
| 128 | + if ( ! $is_booktics_screen ) { | |
| 129 | + return; | |
| 130 | + } | |
| 131 | + ?> | |
| 132 | +<script type="text/javascript"> | |
| 133 | +! function(e, t, n) { | |
| 134 | + function a() { | |
| 135 | + var e = t.getElementsByTagName("script")[0], | |
| 136 | + n = t.createElement("script"); | |
| 137 | + n.type = "text/javascript", n.async = !0, n.src = "https://beacon-v2.helpscout.net", e.parentNode.insertBefore( | |
| 138 | + n, e) | |
| 139 | + } | |
| 140 | + if (e.Beacon = n = function(t, n, a) { | |
| 141 | + e.Beacon.readyQueue.push({ | |
| 142 | + method: t, | |
| 143 | + options: n, | |
| 144 | + data: a | |
| 145 | + }) | |
| 146 | + }, n.readyQueue = [], "complete" === t.readyState) a(); | |
| 147 | + else if (e.attachEvent) e.attachEvent("onload", a); | |
| 148 | + else e.addEventListener("load", a, !1) | |
| 149 | +}(window, document, window.Beacon || function() {}); | |
| 150 | +</script> | |
| 151 | +<script type="text/javascript"> | |
| 152 | +window.Beacon('config', { | |
| 153 | + color: "#22B855", | |
| 154 | +}); | |
| 155 | +window.Beacon('init', '0f1a82db-0aa9-4bac-accc-ee1bb81d4940'); | |
| 156 | +window.Beacon('on', 'ready', function() { | |
| 157 | + window.Beacon('close'); | |
| 158 | +}); | |
| 159 | +</script> | |
| 160 | +<?php | |
| 93 | 161 | } |
| 94 | 162 | } |