PluginProbe
MainWP Dashboard: Self-hosted WordPress Management for Agencies / 5.0
MainWP Dashboard: Self-hosted WordPress Management for Agencies v5.0
6.2 6.1.8 6.1.7 6.1.6 6.1.5 6.1.4 6.1.3 6.1.2 6.1.1 6.1 6.0.12 6.0.11 4.6.0.1 5.0 5.0.1 5.0.2 5.0.3 5.0.3.1 5.0.3.2 5.1 5.1.1 5.2 5.2.1 5.2.2 5.3 All 153 releases
mainwp / class / class-mainwp-premium-update.php

class-mainwp-premium-update.php in MainWP Dashboard: Self-hosted WordPress Management for Agencies 5.0, at class/class-mainwp-premium-update.php

353 lines 9.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * MainWP Premium Update
4 *
5 * MainWP Premium Update functions.
6 *
7 * @package MainWP/Dashboard
8 */
9
10 namespace MainWP\Dashboard;
11
12 // phpcs:disable WordPress.DB.RestrictedFunctions, WordPress.WP.AlternativeFunctions, WordPress.PHP.NoSilencedErrors -- Using cURL functions.
13
14 /**
15 * Class MainWP_Premium_Update
16 *
17 * @package MainWP\Dashboard
18 *
19 * Check for premium plugin updates.
20 */
21 class MainWP_Premium_Update {
22
23 /**
24 * Method get_class_name()
25 *
26 * Get Class Name.
27 *
28 * @return object
29 */
30 public static function get_class_name() {
31 return __CLASS__;
32 }
33
34 /**
35 * Method check_premium_updates()
36 *
37 * Check for Premium Plugin updates.
38 *
39 * @param array $updates Array of updates.
40 * @param mixed $type Type of update.
41 *
42 * @return boolean true|false.
43 */
44 public static function check_premium_updates( $updates, $type ) {
45
46 if ( ! is_array( $updates ) || empty( $updates ) ) {
47 return false;
48 }
49
50 if ( 'plugin' === $type ) {
51
52 $premiums = array(
53 'ithemes-security-pro/ithemes-security-pro.php',
54 'monarch/monarch.php',
55 'cornerstone/cornerstone.php',
56 'updraftplus/updraftplus.php',
57 'wp-all-import-pro/wp-all-import-pro.php',
58 'bbq-pro/bbq-pro.php',
59 'seedprod-coming-soon-pro-5/seedprod-coming-soon-pro-5.php',
60 'oxygen/functions.php',
61 'elementor-pro/elementor-pro.php',
62 'bbpowerpack/bb-powerpack.php',
63 'bb-ultimate-addon/bb-ultimate-addon.php',
64 'webarx/webarx.php',
65 'leco-client-portal/leco-client-portal.php',
66 'elementor-extras/elementor-extras.php',
67 'wp-schema-pro/wp-schema-pro.php',
68 'convertpro/convertpro.php',
69 'astra-addon/astra-addon.php',
70 'astra-portfolio/astra-portfolio.php',
71 'astra-pro-sites/astra-pro-sites.php',
72 'custom-facebook-feed-pro/custom-facebook-feed.php',
73 'convertpro/convertpro.php',
74 'convertpro-addon/convertpro-addon.php',
75 'wp-schema-pro/wp-schema-pro.php',
76 'ultimate-elementor/ultimate-elementor.php',
77 'gp-premium/gp-premium.php',
78 'flying-press/flying-press.php',
79 'wp-rocket/wp-rocket.php',
80 'fluentformpro/fluentformpro.php',
81 'fluentform-signature/fluentform-signature.php',
82 'fluentcampaign-pro/fluentcampaign-pro.php',
83 'fluent-support-pro/fluent-support-pro.php',
84 'ninja-tables-pro/ninja-tables-pro.php',
85 'fluent-booking-pro/fluent-booking-pro.php',
86 'wp-social-ninja-pro/wp-social-ninja-pro.php',
87 'wp-payment-form-pro/wp-payment-form-pro.php',
88 );
89
90 /**
91 * Filter: mainwp_detect_premiums_updates
92 *
93 * Use mainwp_detect_premium_plugins_update instead.
94 *
95 * @deprecated
96 */
97 $premiums = apply_filters( 'mainwp_detect_premiums_updates', $premiums );
98
99 /**
100 * Filter: mainwp_detect_premium_plugins_update
101 *
102 * Filters supported premium plugins to fix compatiblity issues with detecting premium plugins updates.
103 *
104 * @since Unknown
105 */
106 $premiums = apply_filters( 'mainwp_detect_premium_plugins_update', $premiums );
107
108 if ( is_array( $premiums ) && 0 < count( $premiums ) ) {
109 foreach ( $updates as $info ) {
110 if ( isset( $info['slug'] ) ) {
111 if ( in_array( $info['slug'], $premiums ) ) {
112 return true;
113 } elseif ( false !== strpos( $info['slug'], 'yith-' ) ) {
114 return true;
115 }
116 }
117 }
118 }
119 } elseif ( 'theme' === $type ) {
120
121 $premiums = array();
122
123 /**
124 * Filter: mainwp_detect_premium_themes_update
125 *
126 * Filters supported premium themes to fix compatiblity issues with detecting premium themes updates.
127 *
128 * @since Unknown
129 */
130 $premiums = apply_filters( 'mainwp_detect_premium_themes_update', $premiums );
131
132 if ( is_array( $premiums ) && 0 < count( $premiums ) ) {
133 foreach ( $updates as $info ) {
134 if ( isset( $info['slug'] ) ) {
135 if ( in_array( $info['slug'], $premiums ) ) {
136 return true;
137 }
138 }
139 }
140 }
141 }
142
143 return false;
144 }
145
146 /**
147 * Method maybe_request_premium_updates()
148 *
149 * @param mixed $website Child Site info.
150 * @param mixed $what stats|upgradeplugintheme What function to perform.
151 * @param mixed $params plugin|theme Update Type.
152 *
153 * @return mixed $request_update
154 */
155 public static function maybe_request_premium_updates( $website, $what, $params ) { // phpcs:ignore -- Current complexity is the only way to achieve desired results, pull request solutions appreciated.
156 $request_update = false;
157 if ( 'stats' === $what || ( 'upgradeplugintheme' === $what && isset( $params['type'] ) ) ) {
158
159 $update_type = '';
160
161 $check_premi_plugins = array();
162 $check_premi_themes = array();
163
164 if ( 'stats' === $what ) {
165 if ( '' !== $website->plugins ) {
166 $check_premi_plugins = json_decode( $website->plugins, 1 );
167 }
168 if ( '' !== $website->themes ) {
169 $check_premi_themes = json_decode( $website->themes, 1 );
170 }
171 } elseif ( 'upgradeplugintheme' === $what ) {
172 $update_type = ( isset( $params['type'] ) ) ? $params['type'] : '';
173 if ( 'plugin' === $update_type ) {
174 if ( '' !== $website->plugins ) {
175 $check_premi_plugins = json_decode( $website->plugins, 1 );
176 }
177 } elseif ( 'theme' === $update_type ) {
178 if ( '' !== $website->themes ) {
179 $check_premi_themes = json_decode( $website->themes, 1 );
180 }
181 }
182 }
183
184 if ( self::check_premium_updates( $check_premi_plugins, 'plugin' ) ) {
185 self::try_to_detect_premiums_update( $website, 'plugin' );
186 }
187
188 if ( self::check_premium_updates( $check_premi_themes, 'theme' ) ) {
189 self::try_to_detect_premiums_update( $website, 'theme' );
190 }
191
192 if ( 'upgradeplugintheme' === $what ) {
193 if ( 'plugin' === $update_type || 'theme' === $update_type ) {
194 if ( self::check_request_update_premium( $params['list'], $update_type ) ) {
195 self::request_premiums_update( $website, $update_type, $params['list'] );
196 $request_update = true;
197 }
198 }
199 }
200 }
201
202 return $request_update;
203 }
204
205 /**
206 * Method check_request_update_premium()
207 *
208 * Check if any updates are on the premiums list.
209 *
210 * @param array $list_items List of updates.
211 * @param string $type Type of update. plugin|theme.
212 *
213 * @return bool true|false.
214 */
215 public static function check_request_update_premium( $list_items, $type ) {
216
217 $updates = explode( ',', $list_items );
218
219 if ( ! is_array( $updates ) || empty( $updates ) ) {
220 return false;
221 }
222
223 if ( 1 < count( $updates ) ) {
224 return false;
225 }
226
227 if ( 'plugin' === $type ) {
228
229 $update_premiums = array(
230 'yith-woocommerce-request-a-quote-premium/init.php',
231 );
232
233 /**
234 * Filter: mainwp_request_update_premium_plugins
235 *
236 * Filters supported premium plugins to fix compatibility problmes with updating premium plugins.
237 *
238 * @since Unknown
239 */
240 $update_premiums = apply_filters( 'mainwp_request_update_premium_plugins', $update_premiums );
241
242 if ( is_array( $update_premiums ) && 0 < count( $update_premiums ) ) {
243 foreach ( $updates as $slug ) {
244 if ( ! empty( $slug ) ) {
245 if ( in_array( $slug, $update_premiums ) ) {
246 return true;
247 }
248 }
249 }
250 }
251 } elseif ( 'theme' === $type ) {
252
253 $update_premiums = array();
254
255 /**
256 * Filter: mainwp_request_update_premium_themes
257 *
258 * Filters supported premium themes to fix compatibility problmes with updating premium themes.
259 *
260 * @since Unknown
261 */
262 $update_premiums = apply_filters( 'mainwp_request_update_premium_themes', $update_premiums );
263 if ( is_array( $update_premiums ) && 0 < count( $update_premiums ) ) {
264 foreach ( $themes as $slug ) {
265 if ( ! empty( $slug ) ) {
266 if ( in_array( $slug, $update_premiums ) ) {
267 return true;
268 }
269 }
270 }
271 }
272 }
273 return false;
274 }
275
276 /**
277 * Method redirect_request_site()
278 *
279 * Redirect to requested Site.
280 *
281 * @param mixed $website Child Site.
282 * @param mixed $where_url page to redirerct to.
283 *
284 * @uses \MainWP\Dashboard\MainWP_Connect::get_get_data_authed()
285 * @uses \MainWP\Dashboard\MainWP_Logger::debug()
286 * @uses \MainWP\Dashboard\MainWP_System::$version
287 */
288 public static function redirect_request_site( $website, $where_url ) {
289
290 $request_url = MainWP_Connect::get_get_data_authed( $website, $where_url );
291
292 $agent = 'Mozilla/5.0 (compatible; MainWP/' . MainWP_System::$version . '; +http://mainwp.com)';
293 $args = array(
294 'timeout' => 25,
295 'httpversion' => '1.1',
296 'User-Agent' => $agent,
297 );
298
299 if ( ! empty( $website->http_user ) && ! empty( $website->http_pass ) ) {
300 $args['headers'] = array(
301 'Authorization' => 'Basic ' . base64_encode( $website->http_user . ':' . stripslashes( $website->http_pass ) ), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode used for http encoding compatible.
302 );
303 }
304
305 MainWP_Logger::instance()->debug( ' :: tryRequest :: [website=' . $website->url . ']' );
306 return wp_remote_get( $request_url, $args );
307 }
308
309 /**
310 * Method request_premiums_update()
311 *
312 * Request to update plugin or theme.
313 *
314 * @param mixed $website Child Site to update.
315 * @param mixed $type Type of update, plugin|theme.
316 * @param mixed $list_items list of plugins & themes installed.
317 *
318 * @return mixed null|true.
319 */
320 public static function request_premiums_update( $website, $type, $list_items ) {
321 if ( 'plugin' === $type ) {
322 $where_url = 'plugins.php?_request_update_premiums_type=plugin&list=' . $list_items;
323 } elseif ( 'theme' === $type ) {
324 $where_url = 'update-core.php?_request_update_premiums_type=theme&list=' . $list_items;
325 } else {
326 return null;
327 }
328 self::redirect_request_site( $website, $where_url );
329 return true;
330 }
331
332 /**
333 * Method try_to_detect_premiums_update()
334 *
335 * Try to detect if pugin and themes are premium.
336 *
337 * @param mixed $website Child Site.
338 * @param mixed $type Type of update, plugin|theme.
339 *
340 * @return mixed false|self::redirect_request_site()
341 */
342 public static function try_to_detect_premiums_update( $website, $type ) {
343 if ( 'plugin' === $type ) {
344 $where_url = 'plugins.php?_detect_plugins_updates=yes';
345 } elseif ( 'theme' === $type ) {
346 $where_url = 'update-core.php?_detect_themes_updates=yes';
347 } else {
348 return false;
349 }
350 self::redirect_request_site( $website, $where_url );
351 }
352 }
353