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.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 / base-module.php

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

144 lines 3.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\Utils\Collection;
6 use Elementor\Core\Base\Module as BaseModule;
7
8 if ( ! defined( 'ABSPATH' ) ) {
9 exit; // Exit if accessed directly.
10 }
11
12 abstract class Base_Module extends BaseModule {
13 /**
14 * @var Compatibility_Tag
15 */
16 private $compatibility_tag_service;
17
18 /**
19 * @return string
20 */
21 public function get_name() {
22 return 'compatibility-tag';
23 }
24
25 /**
26 * Return all the plugins
27 *
28 * This protected method created for tests reasons.
29 *
30 * @return Collection
31 */
32 protected function get_plugins() {
33 static $plugins;
34
35 if ( ! $plugins ) {
36 $plugins = new Collection( get_plugins() );
37 }
38
39 return $plugins;
40 }
41
42 /**
43 * @return Compatibility_Tag
44 */
45 protected function get_compatibility_tag_service() {
46 if ( ! $this->compatibility_tag_service ) {
47 $this->compatibility_tag_service = new Compatibility_Tag( $this->get_plugin_header() );
48 }
49
50 return $this->compatibility_tag_service;
51 }
52
53 /**
54 * Add allowed headers to plugins.
55 *
56 * @param array $headers
57 * @param $compatibility_tag_header
58 *
59 * @return array
60 */
61 protected function enable_elementor_headers( array $headers, $compatibility_tag_header ) {
62 $headers[] = $compatibility_tag_header;
63
64 return $headers;
65 }
66
67 /**
68 * @return Collection
69 */
70 protected function get_plugins_to_check() {
71 return $this->get_plugins_with_header();
72 }
73
74 /**
75 * Append a compatibility message to the update plugin warning.
76 *
77 * @param array $args
78 *
79 * @throws \Exception
80 */
81 protected function on_plugin_update_message( array $args ) {
82 $new_version = Version::create_from_string( $args['new_version'] );
83
84 if ( $new_version->compare( '=', $args['Version'], Version::PART_MAJOR_2 ) ) {
85 return;
86 }
87
88 $plugins = $this->get_plugins_to_check();
89 $plugins_compatibility = $this->get_compatibility_tag_service()->check( $new_version, $plugins->keys() );
90
91 $plugins = $plugins->filter( function ( $data, $plugin_name ) use ( $plugins_compatibility ) {
92 return Compatibility_Tag::COMPATIBLE !== $plugins_compatibility[ $plugin_name ];
93 } );
94
95 if ( $plugins->is_empty() ) {
96 return;
97 }
98
99 include __DIR__ . '/views/plugin-update-message-compatibility.php';
100 }
101
102 /**
103 * Get all plugins with specific header.
104 *
105 * @return Collection
106 */
107 private function get_plugins_with_header() {
108 return $this->get_plugins()
109 ->filter( function ( array $plugin ) {
110 return ! empty( $plugin[ $this->get_plugin_header() ] );
111 } );
112 }
113
114 /**
115 * @return string
116 */
117 abstract protected function get_plugin_header();
118
119 /**
120 * @return string
121 */
122 abstract protected function get_plugin_label();
123
124 /**
125 * @return string
126 */
127 abstract protected function get_plugin_name();
128
129 /**
130 * Base_Module constructor.
131 *
132 * @throws \Exception
133 */
134 public function __construct() {
135 add_filter( 'extra_plugin_headers', function ( array $headers ) {
136 return $this->enable_elementor_headers( $headers, $this->get_plugin_header() );
137 } );
138
139 add_action( 'in_plugin_update_message-' . $this->get_plugin_name(), function ( array $args ) {
140 $this->on_plugin_update_message( $args );
141 }, 11 /* After the warning message for backup */ );
142 }
143 }
144