PluginProbe
Elementor Website Builder – more than just a page builder / 4.0.7
Elementor Website Builder – more than just a page builder v4.0.7
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 4.0.7, at modules/compatibility-tag/base-module.php

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