PluginProbe
Image Optimizer – Compress Images and Convert to WebP or AVIF / 1.7.6
Image Optimizer – Compress Images and Convert to WebP or AVIF v1.7.6
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 / vendor / elementor / wp-one-package / src / Admin / Services / ManageWidgetState.php

ManageWidgetState.php in Image Optimizer – Compress Images and Convert to WebP or AVIF 1.7.6, at vendor/elementor/wp-one-package/src/Admin/Services/ManageWidgetState.php

69 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace ElementorOne\Admin\Services;
4
5 use ElementorOne\Admin\Helpers\Utils;
6 use ElementorOne\Common\SupportedPlugins;
7
8 if ( ! defined( 'ABSPATH' ) ) {
9 exit;
10 }
11
12 class ManageWidgetState {
13
14 public const STATE_NOT_INSTALLED = 'not_installed';
15 public const STATE_NOT_ACTIVATED = 'not_activated';
16 public const STATE_NOT_CONNECTED = 'not_connected';
17 public const STATE_UPDATE_REQUIRED = 'update_required';
18 public const STATE_ACTIVE = 'active';
19
20 private static ?array $resolved_cache = null;
21
22 public static function clear_resolved_cache(): void {
23 self::$resolved_cache = null;
24 }
25
26 public static function is_delegated_to_manage(): bool {
27 return (bool) apply_filters( 'elementor_one/manage_dashboard_widget_is_delegated', false );
28 }
29
30 public static function resolve(): string {
31 return self::resolve_with_meta()['state'];
32 }
33
34 public static function resolve_with_meta(): array {
35 if ( null !== self::$resolved_cache ) {
36 return self::$resolved_cache;
37 }
38
39 $plugin_data = Utils::get_plugin_data( SupportedPlugins::MANAGE );
40
41 if ( null === $plugin_data ) {
42 $state = self::STATE_NOT_INSTALLED;
43 } elseif ( ! self::is_plugin_active( $plugin_data['_file'] ) ) {
44 $state = self::STATE_NOT_ACTIVATED;
45 } elseif ( ! Utils::is_plugin_connected( SupportedPlugins::MANAGE ) ) {
46 $state = self::STATE_NOT_CONNECTED;
47 } else {
48 $state = self::is_delegated_to_manage()
49 ? self::STATE_ACTIVE
50 : self::STATE_UPDATE_REQUIRED;
51 }
52
53 self::$resolved_cache = [
54 'state' => $state,
55 'isWidgetDelegated' => self::is_delegated_to_manage(),
56 ];
57
58 return self::$resolved_cache;
59 }
60
61 private static function is_plugin_active( string $plugin_file ): bool {
62 if ( ! function_exists( 'is_plugin_active' ) ) {
63 require_once ABSPATH . 'wp-admin/includes/plugin.php';
64 }
65
66 return is_plugin_active( $plugin_file );
67 }
68 }
69