PluginProbe
Elementor Website Builder – more than just a page builder / 3.24.8
Elementor Website Builder – more than just a page builder v3.24.8
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 4.1.0-beta1 4.1.0-dev1 4.0.7 All 451 releases
elementor / modules / compatibility-tag / compatibility-tag.php

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

84 lines 1.9 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\Plugin;
5 use Elementor\Core\Utils\Version;
6 use Elementor\Core\Base\Base_Object;
7 use Elementor\Core\Utils\Collection;
8
9 if ( ! defined( 'ABSPATH' ) ) {
10 exit; // Exit if accessed directly.
11 }
12
13 class Compatibility_Tag extends Base_Object {
14 const PLUGIN_NOT_EXISTS = 'plugin_not_exists';
15 const HEADER_NOT_EXISTS = 'header_not_exists';
16 const INVALID_VERSION = 'invalid_version';
17 const INCOMPATIBLE = 'incompatible';
18 const COMPATIBLE = 'compatible';
19
20 /**
21 * @var string Holds the header that should be checked.
22 */
23 private $header;
24
25 /**
26 * Compatibility_Tag constructor.
27 *
28 * @param string $header
29 */
30 public function __construct( $header ) {
31 $this->header = $header;
32 }
33
34 /**
35 * Return if plugins is compatible or not.
36 *
37 * @param Version $version
38 * @param array $plugins_names
39 *
40 * @return array
41 * @throws \Exception
42 */
43 public function check( Version $version, array $plugins_names ) {
44 return ( new Collection( $plugins_names ) )
45 ->map_with_keys( function ( $plugin_name ) use ( $version ) {
46 return [ $plugin_name => $this->is_compatible( $version, $plugin_name ) ];
47 } )
48 ->all();
49 }
50
51 /**
52 * Check single plugin if is compatible or not.
53 *
54 * @param Version $version
55 * @param $plugin_name
56 *
57 * @return string
58 * @throws \Exception
59 */
60 private function is_compatible( Version $version, $plugin_name ) {
61 $plugins = Plugin::$instance->wp->get_plugins();
62
63 if ( ! isset( $plugins[ $plugin_name ] ) ) {
64 return self::PLUGIN_NOT_EXISTS;
65 }
66
67 $requested_plugin = $plugins[ $plugin_name ];
68
69 if ( empty( $requested_plugin[ $this->header ] ) ) {
70 return self::HEADER_NOT_EXISTS;
71 }
72
73 if ( ! Version::is_valid_version( $requested_plugin[ $this->header ] ) ) {
74 return self::INVALID_VERSION;
75 }
76
77 if ( $version->compare( '>', $requested_plugin[ $this->header ], Version::PART_MAJOR_2 ) ) {
78 return self::INCOMPATIBLE;
79 }
80
81 return self::COMPATIBLE;
82 }
83 }
84