| @@ -1,81 +1,162 @@ | ||
| 1 | -<?php | |
| 2 | -namespace Booktics\Assets; | |
| 3 | - | |
| 4 | -/** | |
| 5 | - * Manage all admin scripts and styles | |
| 6 | - */ | |
| 7 | -class Admin_Assets extends Base_Assets { | |
| 8 | - /** | |
| 9 | - * Register single service | |
| 10 | - * | |
| 11 | - * @return void | |
| 12 | - */ | |
| 13 | - public function register() { | |
| 14 | - add_action( 'admin_enqueue_scripts', [$this, 'register_styles_scripts'] ); | |
| 15 | - add_action( 'admin_enqueue_scripts', [$this, 'enqueue'] ); | |
| 16 | - } | |
| 17 | - | |
| 18 | - /** | |
| 19 | - * Enqueue scripts and styles | |
| 20 | - * | |
| 21 | - * @return void | |
| 22 | - */ | |
| 23 | - public function enqueue() { | |
| 24 | - wp_enqueue_style( 'wp-color-picker' ); | |
| 25 | - wp_enqueue_style( 'booktics-admin-style' ); | |
| 26 | - wp_enqueue_style( 'booktics-vendor' ); | |
| 27 | - | |
| 28 | - wp_enqueue_media(); | |
| 29 | - wp_enqueue_script( 'booktics-flatpickr-scripts' ); | |
| 30 | - wp_enqueue_script( 'booktics-packages' ); | |
| 31 | - wp_enqueue_script( 'booktics-dashboard-scripts' ); | |
| 32 | - | |
| 33 | - wp_localize_script( 'booktics-packages', 'booktics', Localize::get_admin() ); | |
| 34 | - wp_localize_script( 'booktics-packages', 'booktics_enabled_modules', booktics_get_enabled_modules() ); | |
| 35 | - } | |
| 36 | - | |
| 37 | - /** | |
| 38 | - * Get all scripts | |
| 39 | - * | |
| 40 | - * @return array List register scripts | |
| 41 | - */ | |
| 42 | - public function get_scripts(): array { | |
| 43 | - $scripts = [ | |
| 44 | - 'booktics-dashboard-scripts' => [ | |
| 45 | - 'src' => booktics()->assets_url . '/build/js/dashboard.js', | |
| 46 | - 'deps' => ['booktics-packages'], | |
| 47 | - 'in_footer' => true, | |
| 48 | - ], | |
| 49 | - 'booktics-flatpickr-scripts' => [ | |
| 50 | - 'src' => booktics()->assets_url . '/js/vendors/flatpickr.js', | |
| 51 | - 'deps' => [], | |
| 52 | - 'in_footer' => true, | |
| 53 | - ], | |
| 54 | - 'booktics-packages' => [ | |
| 55 | - 'src' => booktics()->assets_url . '/build/js/packages.js', | |
| 56 | - 'deps' => [], | |
| 57 | - 'in_footer' => true, | |
| 58 | - ], | |
| 59 | - ]; | |
| 60 | - | |
| 61 | - return apply_filters( 'booktics_admin_assets', $scripts ); | |
| 62 | - } | |
| 63 | - | |
| 64 | - /** | |
| 65 | - * List of register styles | |
| 66 | - * | |
| 67 | - * @return array | |
| 68 | - */ | |
| 69 | - public function get_styles(): array { | |
| 70 | - $styles = [ | |
| 71 | - 'booktics-admin-style' => [ | |
| 72 | - 'src' => booktics()->assets_url . '/build/css/admin.css', | |
| 73 | - ], | |
| 74 | - 'booktics-vendor' => [ | |
| 75 | - 'src' => booktics()->assets_url . '/build/css/vendor.css', | |
| 76 | - ], | |
| 77 | - ]; | |
| 78 | - | |
| 79 | - return apply_filters( 'booktics_admin_styles', $styles ); | |
| 80 | - } | |
| 1 | +<?php | |
| 2 | + | |
| 3 | +namespace Booktics\Assets; | |
| 4 | + | |
| 5 | +if ( ! defined( 'ABSPATH' ) ) exit; | |
| 6 | + | |
| 7 | +/** | |
| 8 | + * Manage all admin scripts and styles | |
| 9 | + */ | |
| 10 | +class Admin_Assets extends Base_Assets { | |
| 11 | + /** | |
| 12 | + * Register single service | |
| 13 | + * | |
| 14 | + * @return void | |
| 15 | + */ | |
| 16 | + public function register() { | |
| 17 | + add_action( 'admin_enqueue_scripts', [ | |
| 18 | + $this, | |
| 19 | + 'register_styles_scripts' | |
| 20 | + ] ); | |
| 21 | + add_action( 'admin_enqueue_scripts', [ $this, 'enqueue' ] ); | |
| 22 | + add_action( 'admin_footer', [ $this, 'admin_helpscout_beacon' ] ); | |
| 23 | + } | |
| 24 | + | |
| 25 | + /** | |
| 26 | + * Enqueue scripts and styles | |
| 27 | + * | |
| 28 | + * @return void | |
| 29 | + */ | |
| 30 | + public function enqueue() { | |
| 31 | + $screen = get_current_screen(); | |
| 32 | + if ( $screen->base !== 'toplevel_page_booktics') { | |
| 33 | + return; | |
| 34 | + } | |
| 35 | + $this->enqueue_i18n_loader(); | |
| 36 | + wp_enqueue_style( 'wp-color-picker' ); | |
| 37 | + wp_enqueue_style( 'booktics-admin-style' ); | |
| 38 | + wp_enqueue_style( 'booktics-vendor' ); | |
| 39 | + | |
| 40 | + wp_enqueue_media(); | |
| 41 | + wp_enqueue_script( 'booktics-flatpickr-scripts' ); | |
| 42 | + wp_enqueue_script( 'booktics-packages' ); | |
| 43 | + wp_enqueue_script( 'booktics-dashboard-scripts' ); | |
| 44 | + | |
| 45 | + wp_localize_script( 'booktics-packages', 'booktics', Localize::get_admin() ); | |
| 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 | + | |
| 52 | + } | |
| 53 | + | |
| 54 | + /** | |
| 55 | + * Get all scripts | |
| 56 | + * | |
| 57 | + * @return array List register scripts | |
| 58 | + */ | |
| 59 | + public function get_scripts(): array { | |
| 60 | + $scripts = [ | |
| 61 | + 'booktics-dashboard-scripts' => [ | |
| 62 | + 'src' => booktics()->assets_url . '/build/js/dashboard.js', | |
| 63 | + 'deps' => [ 'booktics-packages' ], | |
| 64 | + 'in_footer' => true, | |
| 65 | + ], | |
| 66 | + 'booktics-flatpickr-scripts' => [ | |
| 67 | + 'src' => booktics()->assets_url . '/js/vendors/flatpickr.js', | |
| 68 | + 'deps' => [], | |
| 69 | + 'in_footer' => true, | |
| 70 | + ], | |
| 71 | + 'booktics-packages' => [ | |
| 72 | + 'src' => booktics()->assets_url . '/build/js/packages.js', | |
| 73 | + 'deps' => [ | |
| 74 | + 'wp-api-fetch', | |
| 75 | + 'wp-components', | |
| 76 | + 'wp-compose', | |
| 77 | + 'wp-i18n', | |
| 78 | + 'wp-element', | |
| 79 | + 'wp-data', | |
| 80 | + 'wp-hooks', | |
| 81 | + ], | |
| 82 | + 'in_footer' => true, | |
| 83 | + ], | |
| 84 | + ]; | |
| 85 | + | |
| 86 | + return apply_filters( 'booktics_admin_assets', $scripts ); | |
| 87 | + } | |
| 88 | + | |
| 89 | + /** | |
| 90 | + * List of register styles | |
| 91 | + * | |
| 92 | + * @return array | |
| 93 | + */ | |
| 94 | + public function get_styles(): array { | |
| 95 | + $styles = [ | |
| 96 | + 'booktics-admin-style' => [ | |
| 97 | + 'src' => booktics()->assets_url . '/build/css/admin.css', | |
| 98 | + ], | |
| 99 | + 'booktics-vendor' => [ | |
| 100 | + 'src' => booktics()->assets_url . '/build/css/vendor.css', | |
| 101 | + ], | |
| 102 | + ]; | |
| 103 | + | |
| 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 | |
| 161 | + } | |
| 81 | 162 | } |