PluginProbe
Image Optimizer – Compress Images and Convert to WebP or AVIF / 1.3.0
Image Optimizer – Compress Images and Convert to WebP or AVIF v1.3.0
1.7.7 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 All 33 releases
image-optimization / classes / utils.php

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

112 lines 2.6 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_single_attachment_page(): bool {
81 $current_screen = get_current_screen();
82
83 if ( ! $current_screen ) {
84 return false;
85 }
86
87 return 'attachment' === $current_screen->id && 'post' === $current_screen->base;
88 }
89
90 public static function is_plugin_page(): bool {
91 $current_screen = get_current_screen();
92
93 return str_contains( $current_screen->id, 'image-optimization-' );
94 }
95
96 public static function is_plugin_settings_page(): bool {
97 $current_screen = get_current_screen();
98
99 return str_contains( $current_screen->id, 'image-optimization-settings' );
100 }
101
102 public static function is_bulk_optimization_page(): bool {
103 $current_screen = get_current_screen();
104
105 return str_contains( $current_screen->id, 'image-optimization-bulk-optimization' );
106 }
107
108 public static function user_is_admin(): bool {
109 return current_user_can( 'manage_options' );
110 }
111 }
112