PluginProbe
Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF / 2.2.2
Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF v2.2.2
2.3.4 2.3.3 2.3.2 2.3.1 2.3.0 2.2.9 2.2.8 trunk 1.10 1.3.3 1.3.4 1.3.5 1.3.5.1 1.3.5.2 1.3.6 1.3.6.1 1.4 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.5 All 103 releases
imagify / inc / classes / class-imagify-assets.php

class-imagify-assets.php in Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF 2.2.2, at inc/classes/class-imagify-assets.php

798 lines 22.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 use Imagify\Notices\Notices;
3
4 /**
5 * Class that handles stylesheets and JavaScripts.
6 *
7 * @since 1.6.10
8 */
9 class Imagify_Assets extends Imagify_Assets_Deprecated {
10
11 /**
12 * Class version.
13 *
14 * @var string
15 */
16 const VERSION = '1.0.4';
17
18 /**
19 * Prefix used for stylesheet handles.
20 *
21 * @var string
22 */
23 const CSS_PREFIX = 'imagify-';
24
25 /**
26 * Prefix used for script handles.
27 *
28 * @var string
29 */
30 const JS_PREFIX = 'imagify-';
31
32 /**
33 * An array containing our registered styles.
34 *
35 * @var array
36 */
37 protected $styles = [];
38
39 /**
40 * An array containing our registered scripts.
41 *
42 * @var array
43 */
44 protected $scripts = [];
45
46 /**
47 * Current handle.
48 *
49 * @var string
50 */
51 protected $current_handle;
52
53 /**
54 * Current handle type.
55 *
56 * @var string 'css' or 'js'.
57 */
58 protected $current_handle_type;
59
60 /**
61 * Array of scripts that should be localized when they are enqueued.
62 *
63 * @var array
64 */
65 protected $deferred_localizations = [];
66
67 /**
68 * A "random" script version to use when debug is on.
69 *
70 * @var int
71 */
72 protected static $version;
73
74 /**
75 * The single instance of the class.
76 *
77 * @var object
78 */
79 protected static $_instance;
80
81 /**
82 * The constructor.
83 *
84 * @return void
85 */
86 protected function __construct() {
87 if ( ! isset( self::$version ) ) {
88 self::$version = time();
89 }
90 }
91
92
93 /** ----------------------------------------------------------------------------------------- */
94 /** PUBLIC METHODS ========================================================================== */
95 /** ----------------------------------------------------------------------------------------- */
96
97 /**
98 * Get the main Instance.
99 *
100 * @since 1.6.10
101 *
102 * @return object Main instance.
103 */
104 public static function get_instance() {
105 if ( ! isset( self::$_instance ) ) {
106 self::$_instance = new self();
107 }
108
109 return self::$_instance;
110 }
111
112 /**
113 * Launch the hooks.
114 *
115 * @since 1.6.10
116 */
117 public function init() {
118 if ( ! is_admin() ) {
119 add_action( 'wp_enqueue_scripts', [ $this, 'enqueue_styles_and_scripts_frontend' ] );
120 return;
121 }
122
123 add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_styles_and_scripts' ], IMAGIFY_INT_MAX );
124 add_action( 'wp_enqueue_media', [ $this, 'enqueue_media_modal' ] );
125 }
126
127 /**
128 * Enqueue stylesheets and scripts for the frontend.
129 *
130 * @since 1.6.10
131 */
132 public function enqueue_styles_and_scripts_frontend() {
133 if ( ! $this->is_admin_bar_item_showing() ) {
134 return;
135 }
136
137 $this->register_style( 'admin-bar' );
138 $this->register_script( 'admin-bar', 'admin-bar', [ 'jquery' ] );
139
140 $this->enqueue_assets( 'admin-bar' )->localize( 'imagifyAdminBar' );
141 }
142
143 /**
144 * Register stylesheets and scripts for the administration area.
145 *
146 * @since 1.6.10
147 */
148 public function register_styles_and_scripts() {
149 static $done = false;
150
151 if ( $done ) {
152 return;
153 }
154 $done = true;
155
156 /**
157 * 3rd Party Styles.
158 */
159 $this->register_style( 'sweetalert-core', 'sweetalert2', [], '4.6.6' );
160
161 /**
162 * Imagify Styles.
163 */
164 $this->register_style( 'sweetalert', 'sweetalert-custom', [ 'sweetalert-core' ] );
165
166 $this->register_style( 'admin-bar' );
167
168 $this->register_style( 'admin' );
169
170 $this->register_style( 'notices', 'notices', [ 'admin' ] ); // Needs SweetAlert on some cases.
171
172 $this->register_style( 'twentytwenty', 'twentytwenty', [ 'admin' ] );
173
174 $this->register_style( 'pricing-modal', 'pricing-modal', [ 'admin' ] );
175
176 $this->register_style( 'bulk', 'bulk', [ 'sweetalert', 'admin' ] );
177
178 $this->register_style( 'options', 'options', [ 'sweetalert', 'admin' ] );
179
180 $this->register_style( 'files-list', 'files-list', [ 'admin' ] );
181
182 /**
183 * 3rd Party Scripts.
184 */
185 $this->register_script( 'promise-polyfill', 'es6-promise.auto', [], '4.1.1' );
186
187 $this->register_script( 'sweetalert', 'sweetalert2', [ 'promise-polyfill' ], '4.6.6' )->localize( 'imagifySwal' );
188
189 $this->register_bud_script( 'runtime', 'runtime' );
190 $this->register_bud_script( 'chart', 'chart', [ 'runtime' ], '4.4.0' );
191
192 $this->register_script( 'event-move', 'jquery.event.move', [ 'jquery' ], '2.0.1' );
193
194 /**
195 * Imagify Scripts.
196 */
197 $this->register_script( 'admin-bar', 'admin-bar', [ 'jquery' ] )->defer_localization( 'imagifyAdminBar' );
198
199 $this->register_script( 'admin', 'admin', [ 'jquery' ] );
200
201 $this->register_script( 'notices', 'notices', [ 'jquery', 'admin' ] )->defer_localization( 'imagifyNotices' ); // Needs SweetAlert on some cases.
202
203 $this->register_script( 'twentytwenty', 'jquery.twentytwenty', [ 'jquery', 'event-move', 'chart', 'admin' ] )->defer_localization( 'imagifyTTT' );
204
205 $this->register_script( 'beat', 'beat', [ 'jquery' ] )->localize( 'imagifybeatSettings' );
206
207 $this->register_script( 'media-modal', 'media-modal', [ 'jquery', 'beat', 'underscore', 'chart', 'admin' ] )->localize( 'imagifyModal' );
208
209 $this->register_script( 'pricing-modal', 'pricing-modal', [ 'jquery', 'admin' ] )->defer_localization( 'imagifyPricingModal' );
210
211 $this->register_script( 'library', 'library', [ 'jquery', 'media-modal' ] )->defer_localization( 'imagifyLibrary' );
212
213 $this->register_script( 'async', 'imagify-gulp' );
214
215 $this->register_bud_script( 'bulk', 'bulk', [ 'jquery', 'beat', 'underscore', 'chart', 'sweetalert', 'async', 'admin' ] )->defer_localization( 'imagifyBulk' );
216
217 $this->register_script( 'options', 'options', [ 'jquery', 'beat', 'sweetalert', 'underscore', 'admin' ] )->defer_localization( 'imagifyOptions' );
218
219 $this->register_script( 'files-list', 'files-list', [ 'jquery', 'beat', 'underscore', 'chart', 'admin' ] )->defer_localization( 'imagifyFiles' );
220 }
221
222 /**
223 * Enqueue stylesheets and scripts for the administration area.
224 *
225 * @since 1.6.10
226 */
227 public function enqueue_styles_and_scripts() {
228 static $done = false;
229
230 if ( $done ) {
231 return;
232 }
233 $done = true;
234
235 /*
236 * Register stylesheets and scripts.
237 */
238 $this->register_styles_and_scripts();
239
240 /**
241 * Admin bar.
242 */
243 if ( $this->is_admin_bar_item_showing() ) {
244 $this->enqueue_assets( 'admin-bar' );
245 }
246
247 /**
248 * Notices.
249 */
250 $notices = Notices::get_instance();
251
252 if ( $notices->has_notices() ) {
253 if ( $notices->display_welcome_steps() || $notices->display_wrong_api_key() ) {
254 // This is where we display things about the API key.
255 $this->enqueue_assets( 'sweetalert' );
256 }
257
258 $this->enqueue_assets( 'notices' );
259 }
260
261 /**
262 * Loaded in the library and attachment edition.
263 */
264 if ( imagify_is_screen( 'library' ) || imagify_is_screen( 'attachment' ) ) {
265 $this->enqueue_assets( 'twentytwenty' );
266 }
267
268 /**
269 * Loaded in the library.
270 */
271 if ( imagify_is_screen( 'library' ) ) {
272 $this->enqueue_style( 'admin' )->enqueue_script( 'library' );
273 }
274
275 /**
276 * Loaded in the bulk optimization page.
277 */
278 if ( imagify_is_screen( 'bulk' ) ) {
279 $this->enqueue_assets( [ 'pricing-modal', 'bulk' ] );
280 }
281
282 /*
283 * Loaded in the settings page.
284 */
285 if ( imagify_is_screen( 'imagify-settings' ) ) {
286 $this->enqueue_assets( [ 'sweetalert', 'notices', 'twentytwenty', 'pricing-modal', 'options' ] );
287 }
288
289 /*
290 * Loaded in the files list page.
291 */
292 if ( imagify_is_screen( 'files-list' ) ) {
293 $this->enqueue_assets( [ 'files-list', 'twentytwenty' ] );
294 }
295
296 /**
297 * Triggered after Imagify CSS and JS have been enqueued.
298 *
299 * @since 1.6.10
300 */
301 do_action( 'imagify_assets_enqueued' );
302 }
303
304 /**
305 * Enqueue stylesheets and scripts for the media modal.
306 *
307 * @since 1.6.10
308 */
309 public function enqueue_media_modal() {
310 static $done = false;
311
312 if ( $done ) {
313 return;
314 }
315 $done = true;
316
317 /*
318 * Register stylesheets and scripts.
319 */
320 $this->register_styles_and_scripts();
321
322 $this->enqueue_style( 'admin' )->enqueue_script( 'media-modal' );
323
324 // When the optimization buttons are displayed in the media modal, they are fetched through ajax, so they can’t print the "processing" button template in the footer.
325 Imagify_Views::get_instance()->print_js_template_in_footer( 'button/processing' );
326
327 /**
328 * Triggered after Imagify CSS and JS have been enqueued for the media modal.
329 *
330 * @since 1.6.10
331 */
332 do_action( 'imagify_media_modal_assets_enqueued' );
333 }
334
335
336
337 /** ----------------------------------------------------------------------------------------- */
338 /** PUBLIC TOOLS ============================================================================ */
339 /** ----------------------------------------------------------------------------------------- */
340
341 /**
342 * Register a style.
343 *
344 * @since 1.6.10
345 *
346 * @param string $handle Name of the stylesheet. Should be unique.
347 * @param string|null $file_name The file name, without the extension. If null, $handle is used.
348 * @param array $dependencies An array of registered stylesheet handles this stylesheet depends on.
349 * @param string|null $version String specifying stylesheet version number. If set to null, the plugin version is used. If SCRIPT_DEBUG is true, a random string is used.
350 * @return object This class instance.
351 */
352 public function register_style( $handle, $file_name = null, $dependencies = [], $version = null ) {
353 // If we register it, it's one of our styles.
354 $this->styles[ $handle ] = 1;
355 $this->current_handle = $handle;
356 $this->current_handle_type = 'css';
357
358 $file_name = $file_name ? $file_name : $handle;
359 $version = $version ? $version : IMAGIFY_VERSION;
360 $version = $this->is_debug() ? self::$version : $version;
361 $extension = $this->is_debug() ? '.css' : '.min.css';
362 $handle = self::CSS_PREFIX . $handle;
363 $dependencies = $this->prefix_dependencies( $dependencies, 'css' );
364
365 wp_register_style(
366 $handle,
367 IMAGIFY_URL . 'assets/css/' . $file_name . $extension,
368 $dependencies,
369 $version
370 );
371
372 return $this;
373 }
374
375 /**
376 * Enqueue a style.
377 *
378 * @since 1.6.10
379 *
380 * @param string|array $handles Name of the stylesheet. Should be unique. Can be an array to enqueue several stylesheets.
381 * @return object This class instance.
382 */
383 public function enqueue_style( $handles ) {
384 $handles = (array) $handles;
385
386 foreach ( $handles as $handle ) {
387 $this->current_handle = $handle;
388 $this->current_handle_type = 'css';
389
390 if ( ! empty( $this->styles[ $handle ] ) ) {
391 // If we registered it, it's one of our styles.
392 $handle = self::CSS_PREFIX . $handle;
393 }
394
395 wp_enqueue_style( $handle );
396 }
397
398 return $this;
399 }
400
401 /**
402 * Dequeue a style.
403 *
404 * @since 1.6.10
405 *
406 * @param string|array $handles Name of the stylesheet. Should be unique. Can be an array to dequeue several stylesheets.
407 * @return object This class instance.
408 */
409 public function dequeue_style( $handles ) {
410 $handles = (array) $handles;
411
412 foreach ( $handles as $handle ) {
413 $this->current_handle = $handle;
414 $this->current_handle_type = 'css';
415
416 if ( ! empty( $this->styles[ $handle ] ) ) {
417 // If we registered it, it's one of our styles.
418 $handle = self::CSS_PREFIX . $handle;
419 }
420
421 wp_dequeue_style( $handle );
422 }
423
424 return $this;
425 }
426
427 /**
428 * Register a script.
429 *
430 * @since 1.6.10
431 *
432 * @param string $handle Name of the script. Should be unique.
433 * @param string|null $file_name The file name, without the extension. If null, $handle is used.
434 * @param array $dependencies An array of registered script handles this script depends on.
435 * @param string|null $version String specifying script version number. If set to null, the plugin version is used. If SCRIPT_DEBUG is true, a random string is used.
436 * @return object This class instance.
437 */
438 public function register_script( $handle, $file_name = null, $dependencies = [], $version = null ) {
439 // If we register it, it's one of our scripts.
440 $this->scripts[ $handle ] = 1;
441 // Set the current handler and handler type.
442 $this->current_handle = $handle;
443 $this->current_handle_type = 'js';
444
445 $file_name = $file_name ? $file_name : $handle;
446 $version = $version ? $version : IMAGIFY_VERSION;
447 $version = $this->is_debug() ? self::$version : $version;
448 $extension = $this->is_debug() ? '.js' : '.min.js';
449 $handle = self::JS_PREFIX . $handle;
450 $dependencies = $this->prefix_dependencies( $dependencies );
451
452 wp_register_script(
453 $handle,
454 IMAGIFY_URL . 'assets/js/' . $file_name . $extension,
455 $dependencies,
456 $version,
457 true
458 );
459
460 return $this;
461 }
462
463 /**
464 * Register a script.
465 *
466 * @since 1.6.10
467 *
468 * @param string $handle Name of the script. Should be unique.
469 * @param string|null $file_name The file name, without the extension. If null, $handle is used.
470 * @param array $dependencies An array of registered script handles this script depends on.
471 * @param string|null $version String specifying script version number. If set to null, the plugin version is used. If SCRIPT_DEBUG is true, a random string is used.
472 * @return object This class instance.
473 */
474 public function register_bud_script( $handle, $file_name = null, $dependencies = [], $version = null ) {
475 // If we register it, it's one of our scripts.
476 $this->scripts[ $handle ] = 1;
477 // Set the current handler and handler type.
478 $this->current_handle = $handle;
479 $this->current_handle_type = 'js';
480
481 $file_name = $file_name ? $file_name : $handle;
482 $version = $version ? $version : IMAGIFY_VERSION;
483 $version = $this->is_debug() ? self::$version : $version;
484 $extension = '.js';
485 $handle = self::JS_PREFIX . $handle;
486 $dependencies = $this->prefix_dependencies( $dependencies );
487
488 wp_register_script(
489 $handle,
490 IMAGIFY_URL . 'assets/admin/js/' . $file_name . $extension,
491 $dependencies,
492 $version,
493 true
494 );
495
496 return $this;
497 }
498
499 /**
500 * Enqueue a script.
501 *
502 * @since 1.6.10
503 *
504 * @param string|array $handles Name of the script. Should be unique. Can be an array to enqueue several scripts.
505 * @return object This class instance.
506 */
507 public function enqueue_script( $handles ) {
508 $handles = (array) $handles;
509
510 foreach ( $handles as $handle ) {
511 // Enqueue the corresponding style.
512 if ( ! empty( $this->styles[ $handle ] ) ) {
513 $this->enqueue_style( $handle );
514 }
515
516 $this->current_handle = $handle;
517 $this->current_handle_type = 'js';
518
519 if ( ! empty( $this->scripts[ $handle ] ) ) {
520 // If we registered it, it's one of our scripts.
521 $handle = self::JS_PREFIX . $handle;
522 }
523
524 wp_enqueue_script( $handle );
525
526 // Deferred localization.
527 if ( ! empty( $this->deferred_localizations[ $this->current_handle ] ) ) {
528 array_map( [ $this, 'localize' ], $this->deferred_localizations[ $this->current_handle ] );
529 unset( $this->deferred_localizations[ $this->current_handle ] );
530 }
531 }
532
533 return $this;
534 }
535
536 /**
537 * Dequeue a script.
538 *
539 * @since 1.6.10
540 *
541 * @param string|array $handles Name of the script. Should be unique. Can be an array to dequeue several scripts.
542 * @return object This class instance.
543 */
544 public function dequeue_script( $handles ) {
545 $handles = (array) $handles;
546
547 foreach ( $handles as $handle ) {
548 // Enqueue the corresponding style.
549 if ( ! empty( $this->styles[ $handle ] ) ) {
550 $this->dequeue_style( $handle );
551 }
552
553 $this->current_handle = $handle;
554 $this->current_handle_type = 'js';
555
556 if ( ! empty( $this->scripts[ $handle ] ) ) {
557 // If we registered it, it's one of our scripts.
558 $handle = self::JS_PREFIX . $handle;
559 }
560
561 wp_dequeue_script( $handle );
562 }
563
564 return $this;
565 }
566
567 /**
568 * Localize a script.
569 *
570 * @since 1.6.10
571 *
572 * @param string $handle Name of the script. Should be unique.
573 * @param string $object_name Name for the JavaScript object. Passed directly, so it should be qualified JS variable. Example: '/[a-zA-Z0-9_]+/'.
574 * @param string|array|null $l10n The data itself. The data can be either a single or multi-dimensional array. If null, $handle is used.
575 * @return object This class instance.
576 */
577 public function localize_script( $handle, $object_name, $l10n = null ) {
578 $this->current_handle = $handle;
579 $this->current_handle_type = 'js';
580
581 if ( ! isset( $l10n ) ) {
582 $l10n = $handle;
583 }
584
585 if ( is_string( $l10n ) ) {
586 $l10n = $this->get_localization_data( $l10n );
587 }
588
589 if ( ! $l10n ) {
590 return $this;
591 }
592
593 if ( ! empty( $this->scripts[ $handle ] ) ) {
594 // If we registered it, it's one of our scripts.
595 $handle = self::JS_PREFIX . $handle;
596 }
597
598 wp_localize_script( $handle, $object_name, $l10n );
599
600 return $this;
601 }
602
603 /**
604 * Enqueue a style and a script that have the same handle.
605 *
606 * @since 1.6.10
607 *
608 * @param string|array $handles Name of the script. Should be unique. Can be an array to enqueue several scripts.
609 * @return object This class instance.
610 */
611 public function enqueue_assets( $handles ) {
612 $handles = (array) $handles;
613
614 foreach ( $handles as $handle ) {
615 $this->enqueue_script( $handle );
616 }
617
618 return $this;
619 }
620
621 /**
622 * Dequeue a style and a script that have the same handle.
623 *
624 * @since 1.6.10
625 *
626 * @param string|array $handles Name of the script. Should be unique. Can be an array to dequeue several scripts.
627 * @return object This class instance.
628 */
629 public function dequeue_assets( $handles ) {
630 $handles = (array) $handles;
631
632 foreach ( $handles as $handle ) {
633 $this->dequeue_style( $handle );
634 $this->dequeue_script( $handle );
635 }
636
637 return $this;
638 }
639
640 /**
641 * Enqueue the current script or style.
642 *
643 * @since 1.6.10
644 *
645 * @return object This class instance.
646 */
647 public function enqueue() {
648 if ( 'js' === $this->current_handle_type ) {
649 $this->enqueue_script( $this->current_handle );
650 } elseif ( 'css' === $this->current_handle_type ) {
651 $this->enqueue_style( $this->current_handle );
652 }
653
654 return $this;
655 }
656
657 /**
658 * Localize the current script.
659 *
660 * @since 1.6.10
661 *
662 * @param string $object_name Name for the JavaScript object. Passed directly, so it should be qualified JS variable. Example: '/[a-zA-Z0-9_]+/'.
663 * @param string|array|null $l10n The data itself. The data can be either a single or multi-dimensional array. If null, $handle is used.
664 * @return object This class instance.
665 */
666 public function localize( $object_name, $l10n = null ) {
667 return $this->localize_script( $this->current_handle, $object_name, $l10n );
668 }
669
670 /**
671 * Localize the current script when it is enqueued with `$this->enqueue()` or `$this->enqueue_script()`. This should be used right after `$this->register_script()`.
672 * Be careful, it won't work if the script is enqueued because it's a dependency.
673 * This is handy to not forget to localize the script later. It also prevents to localize the script right away, and maybe execute all localizations while the script is not enqueued (so we localize for nothing).
674 *
675 * @since 1.6.10
676 *
677 * @param string $object_name Name for the JavaScript object. Passed directly, so it should be qualified JS variable. Example: '/[a-zA-Z0-9_]+/'.
678 * @return object This class instance.
679 */
680 public function defer_localization( $object_name ) {
681 if ( ! isset( $this->deferred_localizations[ $this->current_handle ] ) ) {
682 $this->deferred_localizations[ $this->current_handle ] = [];
683 }
684
685 $this->deferred_localizations[ $this->current_handle ][ $object_name ] = $object_name;
686
687 return $this;
688 }
689
690 /**
691 * Remove a deferred localization.
692 *
693 * @since 1.6.10
694 *
695 * @param string $handle Name of the script. Should be unique.
696 * @param string $object_name Name for the JavaScript object. Passed directly, so it should be qualified JS variable. Example: '/[a-zA-Z0-9_]+/'.
697 * @return object This class instance.
698 */
699 public function remove_deferred_localization( $handle, $object_name = null ) {
700 if ( empty( $this->deferred_localizations[ $handle ] ) ) {
701 return $this;
702 }
703
704 if ( $object_name ) {
705 unset( $this->deferred_localizations[ $handle ][ $object_name ] );
706 } else {
707 unset( $this->deferred_localizations[ $handle ] );
708 }
709
710 return $this;
711 }
712
713 /**
714 * Get all translations we can use with wp_localize_script().
715 *
716 * @since 1.6.10
717 *
718 * @param string $context The translation context.
719 * @param array $more_data More data to merge.
720 * @return array $translations The translations.
721 */
722 public function get_localization_data( $context, $more_data = [] ) {
723 $data = get_imagify_localize_script_translations( $context );
724
725 if ( $more_data ) {
726 return array_merge( $data, $more_data );
727 }
728
729 return $data;
730 }
731
732
733 /** ----------------------------------------------------------------------------------------- */
734 /** INTERNAL TOOLS ========================================================================== */
735 /** ----------------------------------------------------------------------------------------- */
736
737 /**
738 * Prefix the dependencies if they are ours.
739 *
740 * @since 1.6.10
741 *
742 * @param array $dependencies An array of registered script handles this script depends on.
743 * @param string $type Type of dependency: css or js.
744 * @return array
745 */
746 protected function prefix_dependencies( $dependencies, $type = 'js' ) {
747 if ( ! $dependencies ) {
748 return [];
749 }
750
751 if ( 'js' === $type ) {
752 $prefix = self::JS_PREFIX;
753 $scripts = $this->scripts;
754 } else {
755 $prefix = self::CSS_PREFIX;
756 $scripts = $this->styles;
757 }
758
759 $depts = [];
760
761 foreach ( $dependencies as $dept ) {
762 if ( ! empty( $scripts[ $dept ] ) ) {
763 $depts[] = $prefix . $dept;
764 } else {
765 $depts[] = $dept;
766 }
767 }
768
769 return $depts;
770 }
771
772 /**
773 * Tell if debug is on.
774 *
775 * @since 1.6.10
776 *
777 * @return bool
778 */
779 protected function is_debug() {
780 return defined( 'IMAGIFY_DEBUG' ) && IMAGIFY_DEBUG || defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG;
781 }
782
783 /**
784 * Tell if the admin bar item is displaying.
785 *
786 * @since 1.6.10
787 *
788 * @return bool
789 */
790 protected function is_admin_bar_item_showing() {
791 if ( defined( 'IMAGIFY_HIDDEN_ACCOUNT' ) && IMAGIFY_HIDDEN_ACCOUNT ) {
792 return false;
793 }
794
795 return get_imagify_option( 'api_key' ) && is_admin_bar_showing() && imagify_get_context( 'wp' )->current_user_can( 'manage' ) && get_imagify_option( 'admin_bar_menu' );
796 }
797 }
798