PluginProbe
Elementor Website Builder – more than just a page builder / 3.1.0-dev2
Elementor Website Builder – more than just a page builder v3.1.0-dev2
4.3.1 4.3.0 4.3.0-beta3 4.3.0-beta2 4.3.0-beta1 4.2.4 4.2.3 4.2.2 4.2.1 4.2.0 4.1.5 4.2.0-beta2 4.2.0-dev2 4.2.0-beta1 4.1.4 4.1.3 4.1.2 4.1.1 4.1.0 4.1.0-beta3 4.1.0-dev3 4.0.9 4.1.0-beta2 4.1.0-dev2 4.0.8 All 454 releases
elementor / modules / compatibility-tag / compatibility-tag.php

compatibility-tag.php in Elementor Website Builder – more than just a page builder 3.1.0-dev2, at modules/compatibility-tag/compatibility-tag.php

103 lines 2.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Elementor\Modules\CompatibilityTag;
3
4 use Elementor\Core\Utils\Version;
5 use Elementor\Core\Base\Base_Object;
6 use Elementor\Core\Utils\Collection;
7
8 if ( ! defined( 'ABSPATH' ) ) {
9 exit; // Exit if accessed directly.
10 }
11
12 class Compatibility_Tag extends Base_Object {
13 const PLUGIN_NOT_EXISTS = 'plugin_not_exists';
14 const HEADER_NOT_EXISTS = 'header_not_exists';
15 const INVALID_VERSION = 'invalid_version';
16 const INCOMPATIBLE = 'incompatible';
17 const COMPATIBLE = 'compatible';
18
19 /**
20 * @var string Holds the header that should be checked.
21 */
22 private $header;
23
24 /**
25 * @var array[] All the installed plugins
26 */
27 private $plugins;
28
29 /**
30 * Compatibility_Tag constructor.
31 *
32 * @param string $header
33 */
34 public function __construct( $header ) {
35 $this->header = $header;
36 }
37
38 /**
39 * Return if plugins is compatible or not.
40 *
41 * @param Version $version
42 * @param array $plugins_names
43 *
44 * @return array
45 * @throws \Exception
46 */
47 public function check( Version $version, array $plugins_names ) {
48 return ( new Collection( $plugins_names ) )
49 ->map_with_keys( function ( $plugin_name ) use ( $version ) {
50 return [ $plugin_name => $this->is_compatible( $version, $plugin_name ) ];
51 } )
52 ->all();
53 }
54
55 /**
56 * Get all the plugins in the current site.
57 *
58 * This method is protected to allow mock it in the tests.
59 *
60 * @return array[]
61 */
62 protected function get_plugins() {
63 if ( ! $this->plugins ) {
64 $this->plugins = get_plugins();
65 }
66
67 return $this->plugins;
68 }
69
70 /**
71 * Check single plugin if is compatible or not.
72 *
73 * @param Version $version
74 * @param $plugin_name
75 *
76 * @return string
77 * @throws \Exception
78 */
79 private function is_compatible( Version $version, $plugin_name ) {
80 $plugins = $this->get_plugins();
81
82 if ( ! isset( $plugins[ $plugin_name ] ) ) {
83 return self::PLUGIN_NOT_EXISTS;
84 }
85
86 $requested_plugin = $plugins[ $plugin_name ];
87
88 if ( empty( $requested_plugin[ $this->header ] ) ) {
89 return self::HEADER_NOT_EXISTS;
90 }
91
92 if ( ! Version::is_valid_version( $requested_plugin[ $this->header ] ) ) {
93 return self::INVALID_VERSION;
94 }
95
96 if ( $version->compare( '>', $requested_plugin[ $this->header ], Version::PART_MAJOR_2 ) ) {
97 return self::INCOMPATIBLE;
98 }
99
100 return self::COMPATIBLE;
101 }
102 }
103