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

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