PluginProbe
Image Optimization – Compress Images and Convert to WebP or AVIF / 1.6.6
Image Optimization – Compress Images and Convert to WebP or AVIF v1.6.6
1.7.6 1.7.5 1.7.4 trunk 1.0.0 1.0.1 1.0.2 1.1.0 1.2.0 1.2.1 1.3.0 1.4.0 1.4.1 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 All 32 releases
image-optimization / classes / utils.php

utils.php in Image Optimization – Compress Images and Convert to WebP or AVIF 1.6.6, at classes/utils.php

134 lines 3.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace ImageOptimization\Classes;
4
5 use ImageOptimization\Classes\Client\Client;
6 use ImageOptimization\Plugin;
7
8 if ( ! defined( 'ABSPATH' ) ) {
9 exit; // Exit if accessed directly.
10 }
11
12 class Utils {
13 /**
14 * get_elementor
15 * @param $instance
16 *
17 * @return \Elementor\Plugin|false|mixed|null
18 */
19 public static function get_elementor( $instance = false ) {
20 static $_instance = null;
21 if ( false !== $instance ) {
22 $_instance = $instance;
23
24 return $instance;
25 }
26 if ( null !== $_instance ) {
27 return $_instance;
28 }
29 if ( class_exists( 'Elementor\Plugin' ) ) {
30 return \Elementor\Plugin::instance(); // @codeCoverageIgnore
31 }
32
33 return false;
34 }
35
36 public static function get_api_client(): ?Client {
37 return Client::get_instance();
38 }
39
40 public static function get_module( $module_name = '' ) {
41 return Plugin::instance()->modules_manager->get_modules( $module_name );
42 }
43
44 public static function get_module_component( $module_name, $component ) {
45 $module = self::get_module( $module_name );
46 if ( $module ) {
47 return $module->get_component( $component );
48 }
49 return null;
50 }
51
52 /**
53 * is_elementor_installed
54 * @return bool
55 */
56 public static function is_elementor_installed(): bool {
57 $plugins = get_plugins();
58 return isset( $plugins['elementor/elementor.php'] );
59 }
60
61 /**
62 * is_elementor_installed_and_active
63 * should be used only after `plugins_loaded` action
64 * @return bool
65 */
66 public static function is_elementor_installed_and_active(): bool {
67 return did_action( 'elementor/loaded' );
68 }
69
70 public static function is_media_page(): bool {
71 $current_screen = get_current_screen();
72
73 if ( ! $current_screen ) {
74 return false;
75 }
76
77 return 'upload' === $current_screen->id && 'attachment' === $current_screen->post_type;
78 }
79
80 public static function is_media_upload_page(): bool {
81 $current_screen = get_current_screen();
82
83 if ( ! $current_screen ) {
84 return false;
85 }
86
87 return 'media' === $current_screen->id && 'add' === $current_screen->action;
88 }
89
90 public static function is_single_attachment_page(): bool {
91 $current_screen = get_current_screen();
92
93 if ( ! $current_screen ) {
94 return false;
95 }
96
97 return 'attachment' === $current_screen->id && 'post' === $current_screen->base;
98 }
99
100 public static function is_plugin_page(): bool {
101 $current_screen = get_current_screen();
102
103 return str_contains( $current_screen->id, 'image-optimization-' );
104 }
105
106 public static function is_plugin_settings_page(): bool {
107 $current_screen = get_current_screen();
108
109 return str_contains( $current_screen->id, 'image-optimization-settings' );
110 }
111
112 public static function is_bulk_optimization_page(): bool {
113 $current_screen = get_current_screen();
114
115 return str_contains( $current_screen->id, 'image-optimization-bulk-optimization' );
116 }
117
118 public static function user_is_admin(): bool {
119 return current_user_can( 'manage_options' );
120 }
121
122 public static function is_wp_dashboard_page(): bool {
123 $current_screen = get_current_screen();
124
125 return str_contains( $current_screen->id, 'dashboard' );
126 }
127
128 public static function is_wp_updates_page(): bool {
129 $current_screen = get_current_screen();
130
131 return str_contains( $current_screen->id, 'update' );
132 }
133 }
134