PluginProbe
Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF / 2.3.1
Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF v2.3.1
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.3.1, at inc/classes/class-imagify-assets.php

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