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

782 lines 21.7 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( 'helpers', 'helpers' );
180
181 $this->register_script( 'admin', 'admin', [ 'jquery', 'helpers' ] );
182
183 $this->register_script( 'notices', 'notices', [ 'jquery', 'admin' ] )->defer_localization( 'imagifyNotices' ); // Needs SweetAlert on some cases.
184
185 $this->register_script( 'twentytwenty', 'jquery.twentytwenty', [ 'jquery', 'event-move', 'chart', 'admin' ] )->defer_localization( 'imagifyTTT' );
186
187 $this->register_script( 'beat', 'beat', [ 'jquery' ] )->localize( 'imagifybeatSettings' );
188
189 $this->register_script( 'media-modal', 'media-modal', [ 'jquery', 'beat', 'underscore', 'chart', 'admin' ] )->localize( 'imagifyModal' );
190
191 $this->register_script( 'pricing-modal', 'pricing-modal', [ 'jquery', 'admin' ] )->defer_localization( 'imagifyPricingModal' );
192
193 $this->register_script( 'library', 'library', [ 'jquery', 'media-modal' ] )->defer_localization( 'imagifyLibrary' );
194
195 $this->register_script( 'async', 'imagify-gulp' );
196
197 $this->register_bud_script( 'bulk', 'bulk', [ 'jquery', 'beat', 'underscore', 'chart', 'sweetalert', 'async', 'admin' ] )->defer_localization( 'imagifyBulk' );
198
199 $this->register_script( 'options', 'options', [ 'jquery', 'beat', 'sweetalert', 'underscore', 'admin' ] )->defer_localization( 'imagifyOptions' );
200
201 $this->register_script( 'files-list', 'files-list', [ 'jquery', 'beat', 'underscore', 'chart', 'admin' ] )->defer_localization( 'imagifyFiles' );
202 }
203
204 /**
205 * Enqueue stylesheets and scripts for the administration area.
206 *
207 * @since 1.6.10
208 */
209 public function enqueue_styles_and_scripts() {
210 static $done = false;
211
212 if ( $done ) {
213 return;
214 }
215 $done = true;
216
217 /*
218 * Register stylesheets and scripts.
219 */
220 $this->register_styles_and_scripts();
221
222 /**
223 * Admin bar.
224 */
225 if ( $this->is_admin_bar_item_showing() ) {
226 $this->enqueue_assets( 'admin-bar' );
227 }
228
229 /**
230 * Notices.
231 */
232 $notices = Notices::get_instance();
233
234 if ( $notices->has_notices() ) {
235 if ( $notices->display_welcome_steps() || $notices->display_wrong_api_key() ) {
236 // This is where we display things about the API key.
237 $this->enqueue_assets( 'sweetalert' );
238 }
239
240 $this->enqueue_assets( 'notices' );
241 }
242
243 /**
244 * Loaded in the library and attachment edition.
245 */
246 if ( imagify_is_screen( 'library' ) || imagify_is_screen( 'attachment' ) ) {
247 $this->enqueue_assets( 'twentytwenty' );
248 }
249
250 /**
251 * Loaded in the library.
252 */
253 if ( imagify_is_screen( 'library' ) ) {
254 $this->enqueue_style( 'admin' )->enqueue_script( 'library' );
255 }
256
257 /**
258 * Loaded in the bulk optimization page.
259 */
260 if ( imagify_is_screen( 'bulk' ) ) {
261 $this->enqueue_assets( 'bulk' );
262 }
263
264 /*
265 * Loaded in the settings page.
266 */
267 if ( imagify_is_screen( 'imagify-settings' ) ) {
268 $this->enqueue_assets( [ 'sweetalert', 'notices', 'twentytwenty', 'options' ] );
269 }
270
271 /*
272 * Loaded in the files list page.
273 */
274 if ( imagify_is_screen( 'files-list' ) ) {
275 $this->enqueue_assets( [ 'files-list', 'twentytwenty' ] );
276 }
277
278 $this->enqueue_assets( 'pricing-modal' );
279
280 /**
281 * Triggered after Imagify CSS and JS have been enqueued.
282 *
283 * @since 1.6.10
284 */
285 do_action( 'imagify_assets_enqueued' );
286 }
287
288 /**
289 * Enqueue stylesheets and scripts for the media modal.
290 *
291 * @since 1.6.10
292 */
293 public function enqueue_media_modal() {
294 static $done = false;
295
296 if ( $done ) {
297 return;
298 }
299 $done = true;
300
301 /*
302 * Register stylesheets and scripts.
303 */
304 $this->register_styles_and_scripts();
305
306 $this->enqueue_style( 'admin' )->enqueue_script( 'media-modal' );
307
308 // 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.
309 Imagify_Views::get_instance()->print_js_template_in_footer( 'button/processing' );
310
311 /**
312 * Triggered after Imagify CSS and JS have been enqueued for the media modal.
313 *
314 * @since 1.6.10
315 */
316 do_action( 'imagify_media_modal_assets_enqueued' );
317 }
318
319
320
321 /** ----------------------------------------------------------------------------------------- */
322 /** PUBLIC TOOLS ============================================================================ */
323 /** ----------------------------------------------------------------------------------------- */
324
325 /**
326 * Register a style.
327 *
328 * @since 1.6.10
329 *
330 * @param string $handle Name of the stylesheet. Should be unique.
331 * @param string|null $file_name The file name, without the extension. If null, $handle is used.
332 * @param array $dependencies An array of registered stylesheet handles this stylesheet depends on.
333 * @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.
334 * @return object This class instance.
335 */
336 public function register_style( $handle, $file_name = null, $dependencies = [], $version = null ) {
337 // If we register it, it's one of our styles.
338 $this->styles[ $handle ] = 1;
339 $this->current_handle = $handle;
340 $this->current_handle_type = 'css';
341
342 $file_name = $file_name ? $file_name : $handle;
343 $version = $version ? $version : IMAGIFY_VERSION;
344 $version = $this->is_debug() ? self::$version : $version;
345 $extension = $this->is_debug() ? '.css' : '.min.css';
346 $handle = self::CSS_PREFIX . $handle;
347 $dependencies = $this->prefix_dependencies( $dependencies, 'css' );
348
349 wp_register_style(
350 $handle,
351 IMAGIFY_URL . 'assets/css/' . $file_name . $extension,
352 $dependencies,
353 $version
354 );
355
356 return $this;
357 }
358
359 /**
360 * Enqueue a style.
361 *
362 * @since 1.6.10
363 *
364 * @param string|array $handles Name of the stylesheet. Should be unique. Can be an array to enqueue several stylesheets.
365 * @return object This class instance.
366 */
367 public function enqueue_style( $handles ) {
368 $handles = (array) $handles;
369
370 foreach ( $handles as $handle ) {
371 $this->current_handle = $handle;
372 $this->current_handle_type = 'css';
373
374 if ( ! empty( $this->styles[ $handle ] ) ) {
375 // If we registered it, it's one of our styles.
376 $handle = self::CSS_PREFIX . $handle;
377 }
378
379 wp_enqueue_style( $handle );
380 }
381
382 return $this;
383 }
384
385 /**
386 * Dequeue a style.
387 *
388 * @since 1.6.10
389 *
390 * @param string|array $handles Name of the stylesheet. Should be unique. Can be an array to dequeue several stylesheets.
391 * @return object This class instance.
392 */
393 public function dequeue_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_dequeue_style( $handle );
406 }
407
408 return $this;
409 }
410
411 /**
412 * Register a script.
413 *
414 * @since 1.6.10
415 *
416 * @param string $handle Name of the script. Should be unique.
417 * @param string|null $file_name The file name, without the extension. If null, $handle is used.
418 * @param array $dependencies An array of registered script handles this script depends on.
419 * @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.
420 * @return object This class instance.
421 */
422 public function register_script( $handle, $file_name = null, $dependencies = [], $version = null ) {
423 // If we register it, it's one of our scripts.
424 $this->scripts[ $handle ] = 1;
425 // Set the current handler and handler type.
426 $this->current_handle = $handle;
427 $this->current_handle_type = 'js';
428
429 $file_name = $file_name ? $file_name : $handle;
430 $version = $version ? $version : IMAGIFY_VERSION;
431 $version = $this->is_debug() ? self::$version : $version;
432 $extension = $this->is_debug() ? '.js' : '.min.js';
433 $handle = self::JS_PREFIX . $handle;
434 $dependencies = $this->prefix_dependencies( $dependencies );
435
436 wp_register_script(
437 $handle,
438 IMAGIFY_URL . 'assets/js/' . $file_name . $extension,
439 $dependencies,
440 $version,
441 true
442 );
443
444 return $this;
445 }
446
447 /**
448 * Register a script.
449 *
450 * @since 1.6.10
451 *
452 * @param string $handle Name of the script. Should be unique.
453 * @param string|null $file_name The file name, without the extension. If null, $handle is used.
454 * @param array $dependencies An array of registered script handles this script depends on.
455 * @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.
456 * @return object This class instance.
457 */
458 public function register_bud_script( $handle, $file_name = null, $dependencies = [], $version = null ) {
459 // If we register it, it's one of our scripts.
460 $this->scripts[ $handle ] = 1;
461 // Set the current handler and handler type.
462 $this->current_handle = $handle;
463 $this->current_handle_type = 'js';
464
465 $file_name = $file_name ? $file_name : $handle;
466 $version = $version ? $version : IMAGIFY_VERSION;
467 $version = $this->is_debug() ? self::$version : $version;
468 $extension = '.js';
469 $handle = self::JS_PREFIX . $handle;
470 $dependencies = $this->prefix_dependencies( $dependencies );
471
472 wp_register_script(
473 $handle,
474 IMAGIFY_URL . 'assets/admin/js/' . $file_name . $extension,
475 $dependencies,
476 $version,
477 true
478 );
479
480 return $this;
481 }
482
483 /**
484 * Enqueue a script.
485 *
486 * @since 1.6.10
487 *
488 * @param string|array $handles Name of the script. Should be unique. Can be an array to enqueue several scripts.
489 * @return object This class instance.
490 */
491 public function enqueue_script( $handles ) {
492 $handles = (array) $handles;
493
494 foreach ( $handles as $handle ) {
495 // Enqueue the corresponding style.
496 if ( ! empty( $this->styles[ $handle ] ) ) {
497 $this->enqueue_style( $handle );
498 }
499
500 $this->current_handle = $handle;
501 $this->current_handle_type = 'js';
502
503 if ( ! empty( $this->scripts[ $handle ] ) ) {
504 // If we registered it, it's one of our scripts.
505 $handle = self::JS_PREFIX . $handle;
506 }
507
508 wp_enqueue_script( $handle );
509
510 // Deferred localization.
511 if ( ! empty( $this->deferred_localizations[ $this->current_handle ] ) ) {
512 array_map( [ $this, 'localize' ], $this->deferred_localizations[ $this->current_handle ] );
513 unset( $this->deferred_localizations[ $this->current_handle ] );
514 }
515 }
516
517 return $this;
518 }
519
520 /**
521 * Dequeue a script.
522 *
523 * @since 1.6.10
524 *
525 * @param string|array $handles Name of the script. Should be unique. Can be an array to dequeue several scripts.
526 * @return object This class instance.
527 */
528 public function dequeue_script( $handles ) {
529 $handles = (array) $handles;
530
531 foreach ( $handles as $handle ) {
532 // Enqueue the corresponding style.
533 if ( ! empty( $this->styles[ $handle ] ) ) {
534 $this->dequeue_style( $handle );
535 }
536
537 $this->current_handle = $handle;
538 $this->current_handle_type = 'js';
539
540 if ( ! empty( $this->scripts[ $handle ] ) ) {
541 // If we registered it, it's one of our scripts.
542 $handle = self::JS_PREFIX . $handle;
543 }
544
545 wp_dequeue_script( $handle );
546 }
547
548 return $this;
549 }
550
551 /**
552 * Localize a script.
553 *
554 * @since 1.6.10
555 *
556 * @param string $handle Name of the script. Should be unique.
557 * @param string $object_name Name for the JavaScript object. Passed directly, so it should be qualified JS variable. Example: '/[a-zA-Z0-9_]+/'.
558 * @param string|array|null $l10n The data itself. The data can be either a single or multi-dimensional array. If null, $handle is used.
559 * @return object This class instance.
560 */
561 public function localize_script( $handle, $object_name, $l10n = null ) {
562 $this->current_handle = $handle;
563 $this->current_handle_type = 'js';
564
565 if ( ! isset( $l10n ) ) {
566 $l10n = $handle;
567 }
568
569 if ( is_string( $l10n ) ) {
570 $l10n = $this->get_localization_data( $l10n );
571 }
572
573 if ( ! $l10n ) {
574 return $this;
575 }
576
577 if ( ! empty( $this->scripts[ $handle ] ) ) {
578 // If we registered it, it's one of our scripts.
579 $handle = self::JS_PREFIX . $handle;
580 }
581
582 wp_localize_script( $handle, $object_name, $l10n );
583
584 return $this;
585 }
586
587 /**
588 * Enqueue a style and a script that have the same handle.
589 *
590 * @since 1.6.10
591 *
592 * @param string|array $handles Name of the script. Should be unique. Can be an array to enqueue several scripts.
593 * @return object This class instance.
594 */
595 public function enqueue_assets( $handles ) {
596 $handles = (array) $handles;
597
598 foreach ( $handles as $handle ) {
599 $this->enqueue_script( $handle );
600 }
601
602 return $this;
603 }
604
605 /**
606 * Dequeue a style and a script that have the same handle.
607 *
608 * @since 1.6.10
609 *
610 * @param string|array $handles Name of the script. Should be unique. Can be an array to dequeue several scripts.
611 * @return object This class instance.
612 */
613 public function dequeue_assets( $handles ) {
614 $handles = (array) $handles;
615
616 foreach ( $handles as $handle ) {
617 $this->dequeue_style( $handle );
618 $this->dequeue_script( $handle );
619 }
620
621 return $this;
622 }
623
624 /**
625 * Enqueue the current script or style.
626 *
627 * @since 1.6.10
628 *
629 * @return object This class instance.
630 */
631 public function enqueue() {
632 if ( 'js' === $this->current_handle_type ) {
633 $this->enqueue_script( $this->current_handle );
634 } elseif ( 'css' === $this->current_handle_type ) {
635 $this->enqueue_style( $this->current_handle );
636 }
637
638 return $this;
639 }
640
641 /**
642 * Localize the current script.
643 *
644 * @since 1.6.10
645 *
646 * @param string $object_name Name for the JavaScript object. Passed directly, so it should be qualified JS variable. Example: '/[a-zA-Z0-9_]+/'.
647 * @param string|array|null $l10n The data itself. The data can be either a single or multi-dimensional array. If null, $handle is used.
648 * @return object This class instance.
649 */
650 public function localize( $object_name, $l10n = null ) {
651 return $this->localize_script( $this->current_handle, $object_name, $l10n );
652 }
653
654 /**
655 * Localize the current script when it is enqueued with `$this->enqueue()` or `$this->enqueue_script()`. This should be used right after `$this->register_script()`.
656 * Be careful, it won't work if the script is enqueued because it's a dependency.
657 * 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).
658 *
659 * @since 1.6.10
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 ] = [];
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 *
679 * @param string $handle Name of the script. Should be unique.
680 * @param string $object_name Name for the JavaScript object. Passed directly, so it should be qualified JS variable. Example: '/[a-zA-Z0-9_]+/'.
681 * @return object This class instance.
682 */
683 public function remove_deferred_localization( $handle, $object_name = null ) {
684 if ( empty( $this->deferred_localizations[ $handle ] ) ) {
685 return $this;
686 }
687
688 if ( $object_name ) {
689 unset( $this->deferred_localizations[ $handle ][ $object_name ] );
690 } else {
691 unset( $this->deferred_localizations[ $handle ] );
692 }
693
694 return $this;
695 }
696
697 /**
698 * Get all translations we can use with wp_localize_script().
699 *
700 * @since 1.6.10
701 *
702 * @param string $context The translation context.
703 * @param array $more_data More data to merge.
704 * @return array $translations The translations.
705 */
706 public function get_localization_data( $context, $more_data = [] ) {
707 $data = get_imagify_localize_script_translations( $context );
708
709 if ( $more_data ) {
710 return array_merge( $data, $more_data );
711 }
712
713 return $data;
714 }
715
716
717 /** ----------------------------------------------------------------------------------------- */
718 /** INTERNAL TOOLS ========================================================================== */
719 /** ----------------------------------------------------------------------------------------- */
720
721 /**
722 * Prefix the dependencies if they are ours.
723 *
724 * @since 1.6.10
725 *
726 * @param array $dependencies An array of registered script handles this script depends on.
727 * @param string $type Type of dependency: css or js.
728 * @return array
729 */
730 protected function prefix_dependencies( $dependencies, $type = 'js' ) {
731 if ( ! $dependencies ) {
732 return [];
733 }
734
735 if ( 'js' === $type ) {
736 $prefix = self::JS_PREFIX;
737 $scripts = $this->scripts;
738 } else {
739 $prefix = self::CSS_PREFIX;
740 $scripts = $this->styles;
741 }
742
743 $depts = [];
744
745 foreach ( $dependencies as $dept ) {
746 if ( ! empty( $scripts[ $dept ] ) ) {
747 $depts[] = $prefix . $dept;
748 } else {
749 $depts[] = $dept;
750 }
751 }
752
753 return $depts;
754 }
755
756 /**
757 * Tell if debug is on.
758 *
759 * @since 1.6.10
760 *
761 * @return bool
762 */
763 protected function is_debug() {
764 return ( defined( 'IMAGIFY_DEBUG' ) && IMAGIFY_DEBUG ) || ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG );
765 }
766
767 /**
768 * Tell if the admin bar item is displaying.
769 *
770 * @since 1.6.10
771 *
772 * @return bool
773 */
774 protected function is_admin_bar_item_showing() {
775 if ( defined( 'IMAGIFY_HIDDEN_ACCOUNT' ) && IMAGIFY_HIDDEN_ACCOUNT ) {
776 return false;
777 }
778
779 return get_imagify_option( 'api_key' ) && is_admin_bar_showing() && imagify_get_context( 'wp' )->current_user_can( 'manage' ) && get_imagify_option( 'admin_bar_menu' );
780 }
781 }
782