PluginProbe
Elementor Website Builder – more than just a page builder / 3.19.4
Elementor Website Builder – more than just a page builder v3.19.4
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 / core / admin / canary-deployment.php

canary-deployment.php in Elementor Website Builder – more than just a page builder 3.19.4, at core/admin/canary-deployment.php

191 lines 5.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Elementor\Core\Admin;
3
4 use Elementor\Api;
5 use Elementor\Core\Base\Module;
6
7 if ( ! defined( 'ABSPATH' ) ) {
8 exit; // Exit if accessed directly.
9 }
10
11 // TODO: Move this class to pro version for better architecture.
12 class Canary_Deployment extends Module {
13
14 const CURRENT_VERSION = ELEMENTOR_VERSION;
15 const PLUGIN_BASE = ELEMENTOR_PLUGIN_BASE;
16
17 private $canary_deployment_info = null;
18
19 /**
20 * Get module name.
21 *
22 * Retrieve the module name.
23 *
24 * @since 2.6.0
25 * @access public
26 *
27 * @return string Module name.
28 */
29 public function get_name() {
30 return 'canary-deployment';
31 }
32
33 /**
34 * Check version.
35 *
36 * @since 2.6.0
37 * @access public
38 *
39 * @param object $transient Plugin updates data.
40 *
41 * @return object Plugin updates data.
42 */
43 public function check_version( $transient ) {
44 // First transient before the real check.
45 if ( ! isset( $transient->response ) ) {
46 return $transient;
47 }
48
49 // Placeholder
50 $stable_version = '0.0.0';
51
52 if ( ! empty( $transient->response[ static::PLUGIN_BASE ]->new_version ) ) {
53 $stable_version = $transient->response[ static::PLUGIN_BASE ]->new_version;
54 }
55
56 if ( null === $this->canary_deployment_info ) {
57 $this->canary_deployment_info = $this->get_canary_deployment_info();
58 }
59
60 // Can be false - if canary version is not available.
61 if ( empty( $this->canary_deployment_info ) ) {
62 return $transient;
63 }
64
65 if ( ! version_compare( $this->canary_deployment_info['new_version'], $stable_version, '>' ) ) {
66 return $transient;
67 }
68
69 $canary_deployment_info = $this->canary_deployment_info;
70
71 // Most of plugin info comes from the $transient but on first check - the response is empty.
72 if ( ! empty( $transient->response[ static::PLUGIN_BASE ] ) ) {
73 $canary_deployment_info = array_merge( (array) $transient->response[ static::PLUGIN_BASE ], $canary_deployment_info );
74 }
75
76 $transient->response[ static::PLUGIN_BASE ] = (object) $canary_deployment_info;
77
78 return $transient;
79 }
80
81 protected function get_canary_deployment_remote_info( $force ) {
82 return Api::get_canary_deployment_info( $force );
83 }
84
85 private function get_canary_deployment_info() {
86 global $pagenow;
87
88 $force = 'update-core.php' === $pagenow && isset( $_GET['force-check'] );
89
90 $canary_deployment = $this->get_canary_deployment_remote_info( $force );
91
92 if ( empty( $canary_deployment['plugin_info']['new_version'] ) ) {
93 return false;
94 }
95
96 $canary_version = $canary_deployment['plugin_info']['new_version'];
97
98 if ( version_compare( $canary_version, static::CURRENT_VERSION, '<=' ) ) {
99 return false;
100 }
101
102 if ( ! empty( $canary_deployment['conditions'] ) && ! $this->check_conditions( $canary_deployment['conditions'] ) ) {
103 return false;
104 }
105
106 return $canary_deployment['plugin_info'];
107 }
108
109 private function check_conditions( $groups ) {
110 foreach ( $groups as $group ) {
111 if ( $this->check_group( $group ) ) {
112 return true;
113 }
114 }
115
116 return false;
117 }
118
119 private function check_group( $group ) {
120 $is_or_relation = ! empty( $group['relation'] ) && 'OR' === $group['relation'];
121 unset( $group['relation'] );
122 $result = false;
123
124 foreach ( $group as $condition ) {
125 // Reset results for each condition.
126 $result = false;
127 switch ( $condition['type'] ) {
128 case 'wordpress': // phpcs:ignore WordPress.WP.CapitalPDangit.Misspelled
129 // include an unmodified $wp_version
130 include ABSPATH . WPINC . '/version.php';
131 $result = version_compare( $wp_version, $condition['version'], $condition['operator'] );
132 break;
133 case 'multisite':
134 $result = is_multisite() === $condition['multisite'];
135 break;
136 case 'language':
137 $in_array = in_array( get_locale(), $condition['languages'], true );
138 $result = 'in' === $condition['operator'] ? $in_array : ! $in_array;
139 break;
140 case 'plugin':
141 if ( ! empty( $condition['plugin_file'] ) ) {
142 $plugin_file = $condition['plugin_file']; // For PHP Unit tests.
143 } else {
144 $plugin_file = WP_PLUGIN_DIR . '/' . $condition['plugin']; // Default.
145 }
146
147 $version = '';
148
149 if ( is_plugin_active( $condition['plugin'] ) && file_exists( $plugin_file ) ) {
150 $plugin_data = get_plugin_data( $plugin_file );
151 if ( isset( $plugin_data['Version'] ) ) {
152 $version = $plugin_data['Version'];
153 }
154 }
155
156 $result = version_compare( $version, $condition['version'], $condition['operator'] );
157 break;
158 case 'theme':
159 $theme = wp_get_theme();
160 if ( wp_get_theme()->parent() ) {
161 $theme = wp_get_theme()->parent();
162 }
163
164 if ( $theme->get_template() === $condition['theme'] ) {
165 $version = $theme->version;
166 } else {
167 $version = '';
168 }
169
170 $result = version_compare( $version, $condition['version'], $condition['operator'] );
171 break;
172
173 }
174
175 if ( ( $is_or_relation && $result ) || ( ! $is_or_relation && ! $result ) ) {
176 return $result;
177 }
178 }
179
180 return $result;
181 }
182
183 /**
184 * @since 2.6.0
185 * @access public
186 */
187 public function __construct() {
188 add_filter( 'pre_set_site_transient_update_plugins', [ $this, 'check_version' ] );
189 }
190 }
191