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
| 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 |