PluginProbe
MainWP Dashboard: Self-hosted WordPress Management for Agencies / 5.0.3.1
MainWP Dashboard: Self-hosted WordPress Management for Agencies v5.0.3.1
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-system-handler.php

class-mainwp-system-handler.php in MainWP Dashboard: Self-hosted WordPress Management for Agencies 5.0.3.1, at class/class-mainwp-system-handler.php

1,075 lines 39.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * System Handler
4 *
5 * @package MainWP/Dashboard
6 */
7
8 namespace MainWP\Dashboard;
9
10 /**
11 * Class MainWP_System_Handler
12 *
13 * @package MainWP\Dashboard
14 */
15 class MainWP_System_Handler {
16
17 // phpcs:disable WordPress.WP.AlternativeFunctions -- use system functions
18
19 /**
20 * Private static variable to hold the single instance of the class.
21 *
22 * @static
23 *
24 * @var mixed Default null
25 */
26 private static $instance = null;
27
28 /**
29 * Private variable to hold the upgrade version info.
30 *
31 * @var null Version info.
32 */
33 private $upgradeVersionInfo = null;
34
35 /**
36 * Method instance()
37 *
38 * Create public static instance.
39 *
40 * @static
41 * @return MainWP_System
42 */
43 public static function instance() {
44 if ( null === self::$instance ) {
45 self::$instance = new self();
46 }
47
48 return self::$instance;
49 }
50
51 /**
52 * MainWP_System_Handler constructor.
53 *
54 * Run each time the class is called.
55 *
56 * @uses \MainWP\Dashboard\MainWP_Extensions_Handler::get_class_name()
57 */
58 public function __construct() {
59 add_filter( 'mainwp-extension-enabled-check', array( MainWP_Extensions_Handler::get_class_name(), 'is_extension_enabled' ) ); // @deprecated Use 'mainwp_extension_enabled_check' instead.
60 add_filter( 'mainwp_extension_enabled_check', array( MainWP_Extensions_Handler::get_class_name(), 'is_extension_enabled' ) );
61
62 /**
63 * This hook allows you to get a list of sites via the 'mainwp-getsites' filter.
64 *
65 * @link http://codex.mainwp.com/#mainwp-getsites
66 *
67 * @see \MainWP_Extensions::hook_get_sites
68 */
69 add_filter( 'mainwp-getsites', array( MainWP_Extensions_Handler::get_class_name(), 'hook_get_sites' ), 10, 5 ); // @deprecated Use 'mainwp_getsites' instead.
70 add_filter( 'mainwp-getdbsites', array( MainWP_Extensions_Handler::get_class_name(), 'hook_get_db_sites' ), 10, 5 ); // @deprecated Use 'mainwp_getdbsites' instead.
71
72 add_filter( 'mainwp_getsites', array( MainWP_Extensions_Handler::get_class_name(), 'hook_get_sites' ), 10, 5 );
73 add_filter( 'mainwp_getdbsites', array( MainWP_Extensions_Handler::get_class_name(), 'hook_get_db_sites' ), 10, 5 );
74 add_filter( 'mainwp_get_db_websites', array( MainWP_Extensions_Handler::get_class_name(), 'hook_get_db_websites' ), 10, 5 );
75
76 /**
77 * This hook allows you to get a information about groups via the 'mainwp-getgroups' filter.
78 *
79 * @link http://codex.mainwp.com/#mainwp-getgroups
80 *
81 * @see \MainWP_Extensions::hook_get_groups
82 */
83 add_filter( 'mainwp-getgroups', array( MainWP_Extensions_Handler::get_class_name(), 'hook_get_groups' ), 10, 4 ); // @deprecated Use 'mainwp_getgroups' instead.
84 add_filter( 'mainwp_getgroups', array( MainWP_Extensions_Handler::get_class_name(), 'hook_get_groups' ), 10, 4 );
85 add_action( 'mainwp_fetchurlsauthed', array( &$this, 'filter_fetch_urls_authed' ), 10, 7 );
86 add_filter( 'mainwp_fetchurlauthed', array( &$this, 'filter_fetch_url_authed' ), 10, 6 );
87 add_filter( 'mainwp_getsqlwebsites_for_current_user', array( self::class, 'hook_get_sql_websites_for_current_user' ), 10, 4 );
88 add_filter( 'mainwp_fetchurlverifyaction', array( &$this, 'hook_fetch_url_verify_action' ), 10, 4 );
89
90 add_filter(
91 'mainwp_getdashboardsites',
92 array(
93 MainWP_Extensions_Handler::get_class_name(),
94 'hook_get_dashboard_sites',
95 ),
96 10,
97 7
98 );
99
100 // @deprecated Use 'mainwp_manager_getextensions' instead.
101 add_filter(
102 'mainwp-manager-getextensions',
103 array(
104 MainWP_Extensions_Handler::get_class_name(),
105 'hook_get_all_extensions',
106 )
107 );
108
109 add_filter(
110 'mainwp_manager_getextensions',
111 array(
112 MainWP_Extensions_Handler::get_class_name(),
113 'hook_get_all_extensions',
114 )
115 );
116
117 add_action( 'admin_init', array( &$this, 'admin_init' ) );
118
119 if ( false !== get_option( 'mainwp_upgradeVersionInfo' ) && '' !== get_option( 'mainwp_upgradeVersionInfo' ) ) {
120 $this->upgradeVersionInfo = get_option( 'mainwp_upgradeVersionInfo' );
121 if ( ! is_object( $this->upgradeVersionInfo ) ) {
122 $this->upgradeVersionInfo = new \stdClass();
123 }
124 }
125 }
126
127 /**
128 * Method filter_fetch_urls_authed()
129 *
130 * Filter fetch authorized urls.
131 *
132 * @param mixed $pluginFile MainWP extention.
133 * @param string $key MainWP Licence Key.
134 * @param object $dbwebsites Child Sites.
135 * @param string $what Function to perform.
136 * @param array $params Function paramerters.
137 * @param mixed $handle Function handle.
138 * @param mixed $output Function output.
139 *
140 * @return mixed MainWP_Extensions_Handler::hook_fetch_urls_authed() Hook fetch authorized URLs.
141 *
142 * @uses \MainWP\Dashboard\MainWP_Extensions_Handler::hook_fetch_urls_authed()
143 */
144 public function filter_fetch_urls_authed( $pluginFile, $key, $dbwebsites, $what, $params, $handle, $output ) {
145 return MainWP_Extensions_Handler::hook_fetch_urls_authed( $pluginFile, $key, $dbwebsites, $what, $params, $handle, $output );
146 }
147
148 /**
149 * Method filter_fetch_url_authed()
150 *
151 * Filter fetch Authorized URL.
152 *
153 * @param mixed $pluginFile MainWP extention.
154 * @param string $key MainWP licence key.
155 * @param int $websiteId Website ID.
156 * @param string $what Function to perform.
157 * @param array $params Function paramerters.
158 * @param null $raw_response Raw response.
159 *
160 * @return mixed MainWP_Extensions_Handler::hook_fetch_url_authed() Hook fetch authorized URL.
161 *
162 * @uses \MainWP\Dashboard\MainWP_Extensions_Handler::hook_fetch_url_authed()
163 */
164 public function filter_fetch_url_authed( $pluginFile, $key, $websiteId, $what, $params, $raw_response = null ) {
165 return MainWP_Extensions_Handler::hook_fetch_url_authed( $pluginFile, $key, $websiteId, $what, $params, $raw_response );
166 }
167
168 /**
169 * Method hook_fetch_url_verify_action()
170 *
171 * Filter fetch Authorized URL.
172 *
173 * @param mixed $pluginFile MainWP extention.
174 * @param string $childKey Extension child key.
175 * @param int $websiteId Website ID.
176 * @param array $params Function paramerters.
177 *
178 * @return mixed MainWP_Extensions_Handler::hook_fetch_url_authed() Hook fetch authorized URL.
179 */
180 public function hook_fetch_url_verify_action( $pluginFile, $childKey, $websiteId, $params ) {
181 if ( ! is_array( $params ) || ! isset( $params['actionnonce'] ) ) {
182 return false;
183 }
184 $what = 'verify_action';
185 return MainWP_Extensions_Handler::hook_fetch_url_authed( $pluginFile, $childKey, $websiteId, $what, $params );
186 }
187
188 /**
189 * Method apply_filter()
190 *
191 * Apply filter
192 *
193 * @param string $filter The filter.
194 * @param array $value Input value.
195 *
196 * @return array $output Output array.
197 *
198 * @uses \MainWP\Dashboard\MainWP_Extensions_Handler::hook_verify()
199 */
200 public function apply_filters( $filter, $value = array() ) {
201
202 if ( 'mainwp-getmetaboxes' === $filter ) {
203 $output = apply_filters_deprecated( 'mainwp-getmetaboxes', array( $value ), '4.0.7.2', 'mainwp_getmetaboxes' ); // @deprecated Use 'mainwp_getmetaboxes' instead.
204 } else {
205 $output = apply_filters( $filter, $value );
206 }
207
208 if ( ! is_array( $output ) ) {
209 return array();
210 }
211 $count = count( $output );
212 for ( $i = 0; $i < $count; $i++ ) {
213
214 if ( 'mainwp_getmetaboxes' === $filter ) {
215 // pass custom widget.
216 if ( isset( $output[ $i ]['custom'] ) && $output[ $i ]['custom'] && isset( $output[ $i ]['plugin'] ) ) {
217 continue;
218 }
219 }
220 }
221
222 return $output;
223 }
224
225 /**
226 * Method admin_init()
227 *
228 * Do nothing if current user is not an Admin.
229 */
230 public function admin_init() { // phpcs:ignore -- complex function.
231 if ( ! MainWP_System_Utility::is_admin() ) {
232 return;
233 }
234
235 global $pagenow;
236
237 if ( 'plugins.php' === $pagenow && isset( $_GET['do'] ) && 'checkUpgrade' === $_GET['do'] && ( ( time() - $this->upgradeVersionInfo->updated ) > 30 ) ) { // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
238 $this->check_upgrade();
239 delete_site_transient( 'update_plugins' ); // to forced refresh 'update_plugins' transient.
240 wp_safe_redirect( admin_url( 'plugins.php' ) );
241 exit;
242 }
243 }
244
245
246
247 /**
248 * Method hook_get_sql_websites_for_current_user()
249 *
250 * Get sql websites for current user.
251 *
252 * @param mixed $input_value First input filter value.
253 * @param string $pluginFile Extension plugin file to verify.
254 * @param string $key The child-key.
255 * @param mixed $params Input params data.
256 *
257 * @return string sql.
258 */
259 public static function hook_get_sql_websites_for_current_user( $input_value, $pluginFile, $key, $params ) {
260 if ( ! MainWP_Extensions_Handler::hook_verify( $pluginFile, $key ) ) {
261 return false;
262 }
263 return MainWP_DB::instance()->get_sql_wp_for_current_user( $params );
264 }
265 /**
266 * Method handle_manage_sites_screen_settings()
267 *
268 * Handle manage sites screen settings
269 */
270 public function handle_manage_sites_screen_settings() { // phpcs:ignore -- required to achieve desired results, pull request solutions appreciated.
271 if ( isset( $_POST['wp_nonce'] ) && wp_verify_nonce( sanitize_key( $_POST['wp_nonce'] ), 'ManageSitesScrOptions' ) ) {
272 $show_cols = array();
273 foreach ( array_map( 'sanitize_text_field', wp_unslash( $_POST ) ) as $key => $val ) {
274 if ( false !== strpos( $key, 'mainwp_show_column_' ) ) {
275 $col = str_replace( 'mainwp_show_column_', '', $key );
276 $show_cols[ $col ] = 1;
277 }
278 }
279 if ( isset( $_POST['show_columns_name'] ) ) {
280 foreach ( array_map( 'sanitize_text_field', wp_unslash( $_POST['show_columns_name'] ) ) as $col ) {
281 if ( ! isset( $show_cols[ $col ] ) ) {
282 $show_cols[ $col ] = 0; // uncheck, hide columns.
283 }
284 }
285 }
286 MainWP_Utility::update_option( 'mainwp_use_favicon', 1 );
287 MainWP_Utility::update_option( 'mainwp_optimize', ( ! isset( $_POST['mainwp_optimize'] ) ? 0 : 1 ) );
288 $user = wp_get_current_user();
289 if ( $user ) {
290 $val = ( isset( $_POST['mainwp_sitesviewmode'] ) ? sanitize_text_field( wp_unslash( $_POST['mainwp_sitesviewmode'] ) ) : 'grid' );
291 if ( 'grid' !== $val && 'table' !== $val ) {
292 $val = 'grid';
293 }
294 update_user_option( $user->ID, 'mainwp_sitesviewmode', $val, true );
295 update_user_option( $user->ID, 'mainwp_settings_show_manage_sites_columns', $show_cols, true );
296 update_option( 'mainwp_default_sites_per_page', ( isset( $_POST['mainwp_default_sites_per_page'] ) ? intval( $_POST['mainwp_default_sites_per_page'] ) : 25 ) );
297 }
298 } elseif ( isset( $_POST['wp_nonce'] ) && wp_verify_nonce( sanitize_key( $_POST['wp_nonce'] ), 'SreenshotsSitesScrOptions' ) ) {
299 $user = wp_get_current_user();
300 if ( $user ) {
301 $val = ( isset( $_POST['mainwp_sitesviewmode'] ) ? sanitize_text_field( wp_unslash( $_POST['mainwp_sitesviewmode'] ) ) : 'grid' );
302 if ( 'grid' !== $val && 'table' !== $val ) {
303 $val = 'grid';
304 }
305 update_user_option( $user->ID, 'mainwp_sitesviewmode', $val, true );
306 }
307 }
308 }
309
310 /**
311 * Method handle_monitoring_sites_screen_settings()
312 *
313 * Handle monitoring sites screen settings
314 */
315 public function handle_monitoring_sites_screen_settings() {
316 if ( isset( $_POST['wp_nonce'] ) && wp_verify_nonce( sanitize_key( $_POST['wp_nonce'] ), 'MonitoringSitesScrOptions' ) ) {
317 $show_cols = array();
318 foreach ( array_map( 'sanitize_text_field', wp_unslash( $_POST ) ) as $key => $val ) {
319 if ( false !== strpos( $key, 'mainwp_show_column_' ) ) {
320 $col = str_replace( 'mainwp_show_column_', '', $key );
321 $show_cols[ $col ] = 1;
322 }
323 }
324 if ( isset( $_POST['show_columns_name'] ) ) {
325 foreach ( array_map( 'sanitize_text_field', wp_unslash( $_POST['show_columns_name'] ) ) as $col ) {
326 if ( ! isset( $show_cols[ $col ] ) ) {
327 $show_cols[ $col ] = 0; // uncheck, hide columns.
328 }
329 }
330 }
331
332 $user = wp_get_current_user();
333 if ( $user ) {
334 update_user_option( $user->ID, 'mainwp_settings_show_monitoring_sites_columns', $show_cols, true );
335 update_option( 'mainwp_default_monitoring_sites_per_page', ( isset( $_POST['mainwp_default_monitoring_sites_per_page'] ) ? intval( $_POST['mainwp_default_monitoring_sites_per_page'] ) : 25 ) );
336 }
337
338 update_option( 'mainwp_disableSitesChecking', ( ! isset( $_POST['mainwp_disableSitesChecking'] ) ? 1 : 0 ) );
339
340 $val = isset( $_POST['mainwp_frequency_sitesChecking'] ) ? intval( $_POST['mainwp_frequency_sitesChecking'] ) : 1440;
341 update_option( 'mainwp_frequencySitesChecking', $val );
342
343 update_option( 'mainwp_disableSitesHealthMonitoring', ( ! isset( $_POST['mainwp_disable_sitesHealthMonitoring'] ) ? 1 : 0 ) );
344
345 $val = isset( $_POST['mainwp_site_healthThreshold'] ) ? intval( $_POST['mainwp_site_healthThreshold'] ) : 80;
346 update_option( 'mainwp_sitehealthThreshold', $val );
347 }
348 }
349
350 /**
351 * Method handle_clients_screen_settings()
352 *
353 * Handle manage clients screen settings
354 */
355 public function handle_clients_screen_settings() {
356 if ( isset( $_POST['wp_nonce'] ) && wp_verify_nonce( sanitize_key( $_POST['wp_nonce'] ), 'ManageClientsScrOptions' ) ) {
357 $show_cols = array();
358 foreach ( array_map( 'sanitize_text_field', wp_unslash( $_POST ) ) as $key => $val ) {
359 if ( false !== strpos( $key, 'mainwp_show_column_' ) ) {
360 $col = str_replace( 'mainwp_show_column_', '', $key );
361 $show_cols[ $col ] = 1;
362 }
363 }
364 if ( isset( $_POST['show_columns_name'] ) ) {
365 foreach ( array_map( 'sanitize_text_field', wp_unslash( $_POST['show_columns_name'] ) ) as $col ) {
366 if ( ! isset( $show_cols[ $col ] ) ) {
367 $show_cols[ $col ] = 0; // uncheck, hide columns.
368 }
369 }
370 }
371
372 $user = wp_get_current_user();
373 if ( $user ) {
374 update_user_option( $user->ID, 'mainwp_settings_show_manage_clients_columns', $show_cols, true );
375 update_option( 'mainwp_default_manage_clients_per_page', ( isset( $_POST['mainwp_default_manage_clients_per_page'] ) ? intval( $_POST['mainwp_default_manage_clients_per_page'] ) : 25 ) );
376 }
377 }
378 }
379
380 /**
381 * Method handle_clients_screen_settings()
382 *
383 * Handle manage clients screen settings
384 */
385 public function handle_updates_screen_settings() {
386 if ( isset( $_POST['wp_nonce'] ) && wp_verify_nonce( sanitize_key( $_POST['wp_nonce'] ), 'UpdatesScrOptions' ) ) {
387 $val = ( ! isset( $_POST['mainwp_pluginAutomaticDailyUpdate'] ) ? 0 : intval( $_POST['mainwp_pluginAutomaticDailyUpdate'] ) );
388 MainWP_Utility::update_option( 'mainwp_pluginAutomaticDailyUpdate', $val );
389 $val = ( ! isset( $_POST['mainwp_themeAutomaticDailyUpdate'] ) ? 0 : intval( $_POST['mainwp_themeAutomaticDailyUpdate'] ) );
390 MainWP_Utility::update_option( 'mainwp_themeAutomaticDailyUpdate', $val );
391 $val = ( ! isset( $_POST['mainwp_automaticDailyUpdate'] ) ? 0 : intval( $_POST['mainwp_automaticDailyUpdate'] ) );
392 MainWP_Utility::update_option( 'mainwp_automaticDailyUpdate', $val );
393 $val = ( isset( $_POST['mainwp_delay_autoupdate'] ) ? intval( $_POST['mainwp_delay_autoupdate'] ) : 1 );
394 MainWP_Utility::update_option( 'mainwp_delay_autoupdate', $val );
395 $val = ( ! isset( $_POST['mainwp_show_language_updates'] ) ? 0 : 1 );
396 MainWP_Utility::update_option( 'mainwp_show_language_updates', $val );
397 $val = ( ! isset( $_POST['mainwp_disable_update_confirmations'] ) ? 0 : intval( $_POST['mainwp_disable_update_confirmations'] ) );
398 MainWP_Utility::update_option( 'mainwp_disable_update_confirmations', $val );
399 }
400 }
401
402
403 /**
404 * Method handle_mainwp_tools_settings()
405 *
406 * Handle mainwp tools settings.
407 *
408 * @uses \MainWP\Dashboard\MainWP_Twitter::clear_all_twitter_messages()
409 * @uses \MainWP\Dashboard\MainWP_Utility::update_option()
410 */
411 public function handle_mainwp_tools_settings() { // phpcs:ignore -- Current complexity is the only way to achieve desired results, pull request solutions appreciated.
412
413 $user = wp_get_current_user();
414
415 $update_selected_mainwp_themes = false;
416
417 if ( isset( $_GET['page'] ) && 'MainWPTools' === $_GET['page'] ) {
418 if ( isset( $_POST['wp_nonce'] ) && wp_verify_nonce( sanitize_key( $_POST['wp_nonce'] ), 'MainWPTools' ) ) {
419 if ( isset( $_POST['mainwp_restore_info_messages'] ) && ! empty( $_POST['mainwp_restore_info_messages'] ) ) {
420 delete_user_option( $user->ID, 'mainwp_notice_saved_status' );
421 }
422 $enabled_tours = ! isset( $_POST['mainwp-guided-tours-option'] ) ? 0 : 1;
423 MainWP_Utility::update_option( 'mainwp_enable_guided_tours', $enabled_tours );
424
425 if ( isset( $_POST['mainwp_settings_custom_theme'] ) ) {
426 $update_selected_mainwp_themes = true;
427 }
428 }
429 }
430
431 if ( isset( $_POST['wp_scr_options_nonce'] ) && wp_verify_nonce( sanitize_key( $_POST['wp_scr_options_nonce'] ), 'MainWPSelectThemes' ) ) {
432 $update_selected_mainwp_themes = true;
433 }
434
435 if ( $update_selected_mainwp_themes ) {
436 if ( isset( $_POST['mainwp_settings_custom_theme'] ) ) {
437 $custom_theme = sanitize_text_field( wp_unslash( $_POST['mainwp_settings_custom_theme'] ) );
438 update_user_option( $user->ID, 'mainwp_selected_theme', $custom_theme );
439 }
440 }
441
442 $update_screen_options = false;
443 if ( isset( $_POST['wp_nonce'] ) && ( wp_verify_nonce( sanitize_key( $_POST['wp_nonce'] ), 'Settings' ) || wp_verify_nonce( sanitize_key( $_POST['wp_nonce'] ), 'MainWPScrOptions' ) ) ) {
444 $update_screen_options = true;
445 }
446
447 if ( $update_screen_options ) {
448 $show_wids = array();
449 if ( isset( $_POST['mainwp_show_widgets'] ) && is_array( $_POST['mainwp_show_widgets'] ) ) {
450 $selected_wids = array_map( 'sanitize_text_field', wp_unslash( $_POST['mainwp_show_widgets'] ) );
451 foreach ( $selected_wids as $name ) {
452 $show_wids[ $name ] = 1;
453 }
454 }
455
456 if ( isset( $_POST['mainwp_widgets_name'] ) && is_array( $_POST['mainwp_widgets_name'] ) ) {
457 $name_wids = array_map( 'sanitize_text_field', wp_unslash( $_POST['mainwp_widgets_name'] ) );
458 foreach ( $name_wids as $name ) {
459 if ( ! isset( $show_wids[ $name ] ) ) {
460 $show_wids[ $name ] = 0;
461 }
462 }
463 }
464
465 $show_cols = array();
466 if ( isset( $_POST['mainwp_show_columns'] ) && is_array( $_POST['mainwp_show_columns'] ) ) {
467 $selected_cols = array_map( 'sanitize_text_field', wp_unslash( $_POST['mainwp_show_columns'] ) );
468 foreach ( $selected_cols as $name ) {
469 $show_cols[ $name ] = 1;
470 }
471 }
472
473 if ( isset( $_POST['mainwp_columns_name'] ) && is_array( $_POST['mainwp_columns_name'] ) ) {
474 $name_cols = array_map( 'sanitize_text_field', wp_unslash( $_POST['mainwp_columns_name'] ) );
475 foreach ( $name_cols as $name ) {
476 if ( ! isset( $show_cols[ $name ] ) ) {
477 $show_cols[ $name ] = 0;
478 }
479 }
480 }
481
482 $val = ( isset( $_POST['mainwp_sidebarPosition'] ) ? intval( $_POST['mainwp_sidebarPosition'] ) : 1 );
483 if ( $user ) {
484 update_user_option( $user->ID, 'mainwp_settings_show_widgets', $show_wids, true );
485 update_user_option( $user->ID, 'mainwp_sidebarPosition', $val, true );
486
487 if ( isset( $_POST['mainwp_manageposts_show_columns_settings'] ) ) {
488 update_user_option( $user->ID, 'mainwp_manageposts_show_columns', $show_cols, true );
489 }
490
491 if ( isset( $_POST['mainwp_managepages_show_columns_settings'] ) ) {
492 update_user_option( $user->ID, 'mainwp_managepages_show_columns', $show_cols, true );
493 }
494
495 if ( isset( $_POST['mainwp_manageusers_show_columns_settings'] ) ) {
496 update_user_option( $user->ID, 'mainwp_manageusers_show_columns', $show_cols, true );
497 }
498 }
499
500 MainWP_Utility::update_option( 'mainwp_hide_update_everything', ( ! isset( $_POST['hide_update_everything'] ) ? 0 : 1 ) );
501
502 if ( isset( $_POST['reset_overview_settings'] ) && ! empty( $_POST['reset_overview_settings'] ) && isset( $_POST['reset_overview_which_settings'] ) && 'overview_settings' === $_POST['reset_overview_which_settings'] ) {
503 update_user_option( $user->ID, 'mainwp_widgets_sorted_toplevel_page_mainwp_tab', false, true );
504 update_user_option( $user->ID, 'mainwp_widgets_sorted_mainwp_page_managesites', false, true );
505 }
506 }
507
508 $update_clients_screen_options = false;
509 if ( isset( $_POST['wp_scr_options_nonce'] ) && wp_verify_nonce( sanitize_key( $_POST['wp_scr_options_nonce'] ), 'MainWPClientsScrOptions' ) ) {
510 $update_clients_screen_options = true;
511 }
512 if ( $update_clients_screen_options ) {
513
514 $show_wids = array();
515 if ( isset( $_POST['mainwp_show_widgets'] ) && is_array( $_POST['mainwp_show_widgets'] ) ) {
516 $selected_wids = array_map( 'sanitize_text_field', wp_unslash( $_POST['mainwp_show_widgets'] ) );
517 foreach ( $selected_wids as $name ) {
518 $show_wids[ $name ] = 1;
519 }
520 }
521
522 if ( isset( $_POST['mainwp_widgets_name'] ) && is_array( $_POST['mainwp_widgets_name'] ) ) {
523 $name_wids = array_map( 'sanitize_text_field', wp_unslash( $_POST['mainwp_widgets_name'] ) );
524 foreach ( $name_wids as $name ) {
525 if ( ! isset( $show_wids[ $name ] ) ) {
526 $show_wids[ $name ] = 0;
527 }
528 }
529 }
530
531 if ( $user ) {
532 update_user_option( $user->ID, 'mainwp_clients_show_widgets', $show_wids, true );
533 }
534
535 if ( isset( $_POST['reset_client_overview_settings'] ) && ! empty( $_POST['reset_client_overview_settings'] ) ) {
536 update_user_option( $user->ID, 'mainwp_widgets_sorted_mainwp_page_manageclients', false, true );
537 }
538 }
539 }
540
541 /**
542 * Method handle_settings_post()
543 *
544 * Handle saving settings page.
545 *
546 * @uses \MainWP\Dashboard\MainWP_Backup_Handler::handle_settings_post()
547 * @uses \MainWP\Dashboard\MainWP_DB_Common::get_user_extension()
548 * @uses \MainWP\Dashboard\MainWP_DB_Common::update_user_extension()
549 * @uses \MainWP\Dashboard\MainWP_Monitoring_Handler::handle_settings_post()
550 * @uses \MainWP\Dashboard\MainWP_Settings::handle_settings_post()
551 */
552 public function handle_settings_post() { // phpcs:ignore -- complex method.
553
554 if ( isset( $_GET['page'] ) && ( isset( $_POST['wp_nonce'] ) || isset( $_POST['wp_scr_options_nonce'] ) ) ) {
555 $this->include_pluggable();
556 $this->handle_mainwp_tools_settings();
557 $this->handle_manage_sites_screen_settings();
558 $this->handle_monitoring_sites_screen_settings();
559 $this->handle_clients_screen_settings();
560 $this->handle_updates_screen_settings();
561 }
562
563 if ( isset( $_POST['select_mainwp_options_siteview'] ) ) {
564 $this->include_pluggable();
565 if ( check_admin_referer( 'mainwp-admin-nonce' ) ) {
566 $userExtension = MainWP_DB_Common::instance()->get_user_extension();
567 $userExtension->site_view = ( empty( $_POST['select_mainwp_options_siteview'] ) ? MAINWP_VIEW_PER_PLUGIN_THEME : intval( $_POST['select_mainwp_options_siteview'] ) );
568 MainWP_DB_Common::instance()->update_user_extension( $userExtension );
569 }
570 }
571
572 if ( isset( $_POST['select_mainwp_options_plugintheme_view'] ) ) {
573 $this->include_pluggable();
574 if ( check_admin_referer( 'mainwp-admin-nonce' ) ) {
575 $view_per = ( empty( $_POST['select_mainwp_options_plugintheme_view'] ) ? MAINWP_VIEW_PER_PLUGIN_THEME : intval( $_POST['select_mainwp_options_plugintheme_view'] ) );
576 $which = isset( $_POST['whichview'] ) ? sanitize_text_field( wp_unslash( $_POST['whichview'] ) ) : '';
577 if ( 'plugin' === $which ) {
578 MainWP_Utility::update_user_option( 'mainwp_manage_plugin_view', $view_per );
579 } else {
580 MainWP_Utility::update_user_option( 'mainwp_manage_theme_view', $view_per );
581 }
582 }
583 }
584
585 if ( isset( $_POST['submit'] ) && isset( $_POST['wp_nonce'] ) ) {
586 $this->include_pluggable();
587 if ( wp_verify_nonce( sanitize_key( $_POST['wp_nonce'] ), 'Settings' ) ) {
588 $updated = MainWP_Settings::handle_settings_post();
589 $updated |= MainWP_Backup_Handler::handle_settings_post();
590 $updated |= MainWP_Monitoring_Handler::handle_settings_post();
591 $msg = '';
592 if ( $updated ) {
593 $msg = '&message=saved';
594 }
595 wp_safe_redirect( admin_url( 'admin.php?page=Settings' . $msg ) );
596 exit();
597 }
598 }
599
600 if ( isset( $_POST['mainwp_sidebar_position'] ) && isset( $_POST['wp_nonce'] ) && wp_verify_nonce( sanitize_key( $_POST['wp_nonce'] ), 'onchange_sidebarposition' ) ) {
601 $val = isset( $_POST['mainwp_sidebar_position'] ) && ! empty( $_POST['mainwp_sidebar_position'] ) ? 1 : 0;
602 $user = wp_get_current_user();
603 if ( $user ) {
604 update_user_option( $user->ID, 'mainwp_sidebarPosition', $val, true );
605 }
606 return true;
607 }
608
609 if ( isset( $_GET['viewmode'] ) && isset( $_GET['modenonce'] ) ) {
610 $viewmode = sanitize_text_field( wp_unslash( $_GET['viewmode'] ) );
611 $nonce = sanitize_key( $_GET['modenonce'] );
612 if ( ( 'table' === $viewmode || 'grid' === $viewmode ) && wp_verify_nonce( sanitize_key( $nonce ), 'viewmode' ) ) {
613 $user = wp_get_current_user();
614 if ( $user ) {
615 update_user_option( $user->ID, 'mainwp_sitesviewmode', $viewmode, true );
616 wp_safe_redirect( admin_url( 'admin.php?page=managesites' ) );
617 exit;
618 }
619 }
620 }
621 }
622
623 /**
624 * Method include_pluggable()
625 *
626 * Include pluggable functions.
627 */
628 public function include_pluggable() {
629 // may causing of conflict with Post S m t p plugin.
630 if ( ! function_exists( 'wp_create_nonce' ) ) {
631 include_once ABSPATH . WPINC . '/pluggable.php';
632 }
633 }
634
635 /**
636 * Method plugins_api_extension_info()
637 *
638 * Get MainWP Extension api information.
639 *
640 * @param mixed $input_value Return value.
641 * @param mixed $action Action being performed.
642 * @param mixed $arg Action arguments. Should be the plugin slug.
643 *
644 * @return mixed $info|$input_value
645 *
646 * @uses \MainWP\Dashboard\MainWP_API_Handler::get_update_information()
647 * @uses \MainWP\Dashboard\MainWP_Extensions_View::get_available_extensions()
648 * @uses \MainWP\Dashboard\MainWP_System::get_plugin_slug()
649 * @uses \MainWP\Dashboard\MainWP_Extensions_Handler::get_slugs()
650 */
651 public function plugins_api_extension_info( $input_value, $action, $arg ) {
652 if ( 'plugin_information' !== $action ) {
653 return $input_value;
654 }
655
656 if ( is_array( $arg ) ) {
657 $arg = (object) $arg;
658 }
659
660 if ( ! isset( $arg->slug ) || ( '' === $arg->slug ) ) {
661 return $input_value;
662 }
663
664 if ( dirname( MainWP_System::instance()->get_plugin_slug() ) === $arg->slug ) {
665 return $input_value;
666 }
667
668 $result = MainWP_Extensions_Handler::get_slugs();
669 $am_slugs = $result['am_slugs'];
670
671 if ( '' !== $am_slugs ) {
672 $am_slugs = explode( ',', $am_slugs );
673 if ( false !== strpos( $arg->slug, '/' ) ) { // to fix.
674 $dir_slug = dirname( $arg->slug );
675 } else {
676 $dir_slug = $arg->slug;
677 }
678 if ( in_array( $dir_slug, $am_slugs ) ) {
679 $info = MainWP_API_Handler::get_update_information( $dir_slug );
680 if ( is_object( $info ) && property_exists( $info, 'sections' ) ) {
681 if ( ! is_array( $info->sections ) || ! isset( $info->sections['changelog'] ) || empty( $info->sections['changelog'] ) ) {
682 $exts_data = MainWP_Extensions_View::get_available_extensions();
683 if ( isset( $exts_data[ $arg->slug ] ) ) {
684 $ext_info = $exts_data[ $arg->slug ];
685 $changelog_link = rtrim( $ext_info['link'], '/' );
686 $info->sections['changelog'] = '<a href="' . $changelog_link . '#tab-changelog" target="_blank">' . $changelog_link . '#tab-changelog</a>';
687 }
688 }
689 return $info;
690 }
691 return $info;
692 }
693 }
694
695 return $input_value;
696 }
697
698 /**
699 * Method plugins_api_wp_plugins_api_result()
700 *
701 * Hook after get plugins api information.
702 *
703 * @param mixed $res api information value.
704 * @param mixed $action Action being performed.
705 * @param mixed $arg Action arguments. Should be the plugin slug.
706 *
707 * @return mixed $res
708 */
709 public function plugins_api_wp_plugins_api_result( $res, $action, $arg ) {
710
711 if ( 'plugin_information' !== $action ) {
712 return $res;
713 }
714
715 if ( is_object( $res ) && property_exists( $res, 'slug' ) && property_exists( $res, 'sections' ) ) {
716 return $res;
717 }
718
719 if ( ! isset( $_GET['wpplugin'] ) || ! is_numeric( $_GET['wpplugin'] ) || empty( $_GET['wpplugin'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
720 return $res;
721 }
722
723 if ( is_array( $arg ) ) {
724 $arg = (object) $arg;
725 }
726
727 if ( ! isset( $arg->slug ) || ( '' === $arg->slug ) ) {
728 return $res;
729 }
730
731 $site_id = intval( $_GET['wpplugin'] ); // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
732
733 if ( $site_id ) {
734 $website = MainWP_DB::instance()->get_website_by_id( $site_id );
735 if ( $website && ! empty( $website->plugin_upgrades ) ) {
736 $plugin_upgrades = json_decode( $website->plugin_upgrades, true );
737
738 if ( is_array( $plugin_upgrades ) ) {
739 $found_update = false;
740 $empty_sections = false;
741 foreach ( $plugin_upgrades as $plugin_slug => $info ) {
742 if ( false !== strpos( $plugin_slug, $arg->slug ) && isset( $info['update'] ) ) {
743 $found_update = true;
744 if ( isset( $info['update']['slug'] ) && $arg->slug === $info['update']['slug'] && isset( $info['update']['new_version'] ) && ! empty( $info['update']['new_version'] ) && isset( $info['update']['sections'] ) && ! empty( $info['update']['sections'] ) ) {
745 $info_update = (object) $info['update'];
746 $info_update->external = false;
747 return $info_update;
748 }
749 $empty_sections = true;
750 break;
751 }
752 }
753
754 if ( $found_update && $empty_sections ) {
755 try {
756 $info = MainWP_Connect::fetch_url_authed(
757 $website,
758 'plugin_action',
759 array(
760 'action' => 'changelog_info', // try to get changelog from the child site.
761 'slug' => $arg->slug,
762 )
763 );
764 if ( is_array( $info ) && isset( $info['update'] ) && ! empty( $info['update']['sections'] ) ) {
765 $info_update = (object) $info['update'];
766 $info_update->external = true;
767 return $info_update;
768 }
769 } catch ( \Exception $e ) {
770 // error happen.
771 }
772 }
773 }
774 }
775 }
776
777 return $res;
778 }
779
780 /**
781 * Method check_update_custom()
782 *
783 * Check MainWP Extensions for updates.
784 *
785 * @param object $transient Transient information.
786 *
787 * @return object $transient Transient information.
788 *
789 * @uses \MainWP\Dashboard\MainWP_API_Handler::get_upgrade_information()
790 * @uses \MainWP\Dashboard\MainWP_Extensions_Handler::get_indexed_extensions_infor()
791 * @uses \MainWP\Dashboard\MainWP_Extensions_Handler::get_extension_slug()
792 * @uses \MainWP\Dashboard\MainWP_Utility::update_option()
793 */
794 public function check_update_custom( $transient ) { // phpcs:ignore -- Current complexity is the only way to achieve desired results, pull request solutions appreciated.
795 if ( isset( $_POST['action'] ) && ( ( 'update-plugin' === $_POST['action'] ) || ( 'update-selected' === $_POST['action'] ) ) && is_object( $transient ) && property_exists( $transient, 'response' ) ) { // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
796 $extensions = MainWP_Extensions_Handler::get_indexed_extensions_infor( array( 'activated' => true ) );
797 if ( defined( 'DOING_AJAX' ) && isset( $_POST['plugin'] ) && 'update-plugin' === $_POST['action'] ) { // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
798
799 if ( empty( $transient->response ) ) {
800 $transient->response = array();
801 }
802
803 $plugin_slug = sanitize_text_field( wp_unslash( $_POST['plugin'] ) ); // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
804 if ( isset( $extensions[ $plugin_slug ] ) ) {
805
806 if ( ! isset( $transient->response[ $plugin_slug ] ) || ! is_object( $transient->response[ $plugin_slug ] ) || ! property_exists( $transient->response[ $plugin_slug ], 'new_version' ) ) {
807 return $transient;
808 }
809
810 if ( isset( $transient->response[ $plugin_slug ] ) && version_compare( $transient->response[ $plugin_slug ]->new_version, $extensions[ $plugin_slug ]['version'], '=' ) ) {
811 return $transient;
812 }
813
814 $api_slug = dirname( $plugin_slug );
815 $rslt = MainWP_API_Handler::get_upgrade_information( $api_slug );
816
817 if ( ! empty( $rslt ) && is_object( $rslt ) && property_exists( $rslt, 'new_version' ) && ! empty( $rslt->new_version ) && version_compare( $rslt->new_version, $extensions[ $plugin_slug ]['version'], '>' ) ) {
818 $transient->response[ $plugin_slug ] = self::map_rslt_obj( $rslt );
819 }
820
821 return $transient;
822 }
823 } elseif ( 'update-selected' === $_POST['action'] && isset( $_POST['checked'] ) && is_array( $_POST['checked'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
824
825 if ( empty( $transient->response ) ) {
826 $transient->response = array();
827 }
828
829 $updated = false;
830 foreach ( wp_unslash( $_POST['checked'] ) as $plugin_slug ) { // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
831 if ( isset( $extensions[ $plugin_slug ] ) ) {
832
833 if ( ! isset( $transient->response[ $plugin_slug ] ) ) {
834 $transient->response[ $plugin_slug ] = new \stdClass();
835 }
836
837 if ( isset( $transient->response[ $plugin_slug ] ) && version_compare( $transient->response[ $plugin_slug ]->new_version, $extensions[ $plugin_slug ]['version'], '=' ) ) {
838 continue;
839 }
840 $api_slug = dirname( $plugin_slug );
841 $rslt = MainWP_API_Handler::get_upgrade_information( $api_slug );
842 if ( ! empty( $rslt ) && is_object( $rslt ) && property_exists( $rslt, 'new_version' ) && ! empty( $rslt->new_version ) && version_compare( $rslt->new_version, $extensions[ $plugin_slug ]['version'], '>' ) ) {
843 $this->upgradeVersionInfo->result[ $api_slug ] = $rslt;
844 $transient->response[ $plugin_slug ] = self::map_rslt_obj( $rslt );
845 $updated = true;
846 }
847 }
848 }
849 if ( $updated ) {
850 MainWP_Utility::update_option( 'mainwp_upgradeVersionInfo', $this->upgradeVersionInfo );
851 }
852
853 return $transient;
854 }
855 }
856
857 if ( empty( $transient->checked ) ) {
858 return $transient;
859 }
860
861 if ( ! empty( $this->upgradeVersionInfo ) && property_exists( $this->upgradeVersionInfo, 'result' ) && is_array( $this->upgradeVersionInfo->result ) ) {
862 foreach ( $this->upgradeVersionInfo->result as $rslt ) {
863 if ( ! isset( $rslt->slug ) ) {
864 continue;
865 }
866
867 $plugin_slug = MainWP_Extensions_Handler::get_extension_slug( $rslt->slug );
868 if ( isset( $transient->checked[ $plugin_slug ] ) && property_exists( $rslt, 'new_version' ) && ! empty( $rslt->new_version ) && version_compare( $rslt->new_version, $transient->checked[ $plugin_slug ], '>' ) ) {
869 $transient->response[ $plugin_slug ] = self::map_rslt_obj( $rslt );
870 }
871 }
872 }
873
874 return $transient;
875 }
876
877
878 /**
879 * Method map_rslt_obj()
880 *
881 * Map resulting object.
882 *
883 * @param object $result Resulting information.
884 *
885 * @return object $obj Mapped resulting object.
886 */
887 public static function map_rslt_obj( $result ) {
888 $obj = new \stdClass();
889 $obj->slug = $result->slug;
890 $obj->new_version = $result->new_version;
891 $obj->url = 'https://mainwp.com/';
892 $obj->package = $result->package;
893
894 return $obj;
895 }
896
897 /**
898 * Method check_upgrade()
899 *
900 * Check if Extension has an update.
901 *
902 * @uses \MainWP\Dashboard\MainWP_API_Handler::check_exts_upgrade()
903 * @uses \MainWP\Dashboard\MainWP_Utility::update_option()
904 */
905 private function check_upgrade() {
906 $result = MainWP_API_Handler::check_exts_upgrade();
907 if ( null === $this->upgradeVersionInfo ) {
908 $this->upgradeVersionInfo = new \stdClass();
909 }
910 $this->upgradeVersionInfo->updated = time();
911 if ( ! empty( $result ) ) {
912 $this->upgradeVersionInfo->result = $result;
913 }
914 MainWP_Utility::update_option( 'mainwp_upgradeVersionInfo', $this->upgradeVersionInfo );
915 }
916
917 /**
918 * Method pre_check_update_custom()
919 *
920 * Pre-check for extension updates.
921 *
922 * @param object $transient Transient information.
923 *
924 * @return object $transient Transient information.
925 *
926 * @uses \MainWP\Dashboard\MainWP_Extensions_Handler::get_indexed_extensions_infor()
927 * @uses \MainWP\Dashboard\MainWP_Extensions_Handler::get_extension_slug()
928 */
929 public function pre_check_update_custom( $transient ) {
930 if ( ! isset( $transient->checked ) ) {
931 return $transient;
932 }
933
934 if ( ( null === $this->upgradeVersionInfo ) || ! property_exists( $this->upgradeVersionInfo, 'updated' ) || ( ( time() - $this->upgradeVersionInfo->updated ) > 60 ) ) {
935 $this->check_upgrade();
936 }
937
938 if ( empty( $transient->response ) ) {
939 $transient->response = array();
940 }
941
942 if ( ! empty( $this->upgradeVersionInfo ) && property_exists( $this->upgradeVersionInfo, 'result' ) && is_array( $this->upgradeVersionInfo->result ) ) {
943 $extensions = MainWP_Extensions_Handler::get_indexed_extensions_infor( array( 'activated' => true ) );
944 foreach ( $this->upgradeVersionInfo->result as $rslt ) {
945 $plugin_slug = MainWP_Extensions_Handler::get_extension_slug( $rslt->slug );
946 if ( isset( $extensions[ $plugin_slug ] ) && property_exists( $rslt, 'new_version' ) && ! empty( $rslt->new_version ) && version_compare( $rslt->new_version, $extensions[ $plugin_slug ]['version'], '>' ) ) {
947 $transient->response[ $plugin_slug ] = self::map_rslt_obj( $rslt );
948 }
949 }
950 }
951
952 return $transient;
953 }
954
955 /**
956 * Method upload_file()
957 *
958 * Upload a file.
959 *
960 * @param mixed $file File to upload.
961 *
962 * @return void
963 *
964 * @uses \MainWP\Dashboard\MainWP_Utility::ends_with()
965 */
966 public function upload_file( $file ) {
967 header( 'Content-Description: File Transfer' );
968 if ( MainWP_Utility::ends_with( $file, '.tar.gz' ) ) {
969 header( 'Content-Type: application/x-gzip' );
970 header( 'Content-Encoding: gzip' );
971 } else {
972 header( 'Content-Type: application/octet-stream' );
973 }
974 header( 'Content-Disposition: attachment; filename="' . basename( $file ) . '"' );
975 header( 'Expires: 0' );
976 header( 'Cache-Control: must-revalidate' );
977 header( 'Pragma: public' );
978 header( 'Content-Length: ' . filesize( $file ) );
979 while ( ob_get_level() ) {
980 ob_end_clean();
981 }
982 $this->readfile_chunked( $file );
983 exit();
984 }
985
986 /**
987 * Method readfile_chunked()
988 *
989 * Read Chunked File.
990 *
991 * @param mixed $filename Name of file.
992 *
993 * @return mixed echo $buffer|false|$handle.
994 */
995 public function readfile_chunked( $filename ) {
996 $chunksize = 1024;
997 $handle = fopen( $filename, 'rb' );
998 if ( false === $handle ) {
999 return false;
1000 }
1001
1002 while ( ! feof( $handle ) ) {
1003 $buffer = fread( $handle, $chunksize );
1004 echo $buffer; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1005 if ( ob_get_length() ) {
1006 ob_flush();
1007 flush();
1008 }
1009 $buffer = null;
1010 }
1011
1012 return fclose( $handle );
1013 }
1014
1015 /**
1016 * Method activate_redirection()
1017 *
1018 * Redirect after activating MainWP Extension.
1019 *
1020 * @param mixed $location Location to redirect to.
1021 *
1022 * @return $location Admin URL + the page to redirect to.
1023 */
1024 public function activate_redirect( $location ) {
1025 $location = admin_url( 'admin.php?page=Extensions' );
1026 return $location;
1027 }
1028
1029 /**
1030 * Method activate_extension()
1031 *
1032 * Activate MainWP Extension.
1033 *
1034 * @param mixed $ext_key Extension API Key.
1035 * @param array $info Extension Info.
1036 *
1037 * @uses \MainWP\Dashboard\MainWP_Api_Manager::set_activation_info()
1038 * @uses \MainWP\Dashboard\MainWP_Api_Manager_Password_Management::generate_password()
1039 */
1040 public function activate_extension( $ext_key, $info = array() ) {
1041
1042 add_filter( 'wp_redirect', array( $this, 'activate_redirect' ) );
1043
1044 if ( is_array( $info ) && isset( $info['product_id'] ) && isset( $info['software_version'] ) ) {
1045 $act_info = array(
1046 'product_id' => $info['product_id'],
1047 'software_version' => $info['software_version'],
1048 'activated_key' => 'Deactivated',
1049 'instance_id' => MainWP_Api_Manager_Password_Management::generate_password( 12, false ),
1050 );
1051 MainWP_Api_Manager::instance()->set_activation_info( $ext_key, $act_info );
1052 }
1053 }
1054
1055 /**
1056 * Method deactivate_extension()
1057 *
1058 * Deactivate MaiNWP Extension.
1059 *
1060 * @param mixed $ext_key Exnension API Key.
1061 * @param bool $dashboard_only Deactive API Key on dashboard only.
1062 *
1063 * @uses \MainWP\Dashboard\MainWP_Api_Manager::set_activation_info()
1064 */
1065 public function deactivate_extension( $ext_key, $dashboard_only = false ) {
1066 // try to deactivate license.
1067 if ( ! $dashboard_only ) {
1068 $mainwp_api_key = MainWP_Api_Manager_Key::instance()->get_decrypt_master_api_key();
1069 $result = MainWP_Api_Manager::instance()->license_key_deactivation( $ext_key, $mainwp_api_key );
1070 }
1071
1072 MainWP_Api_Manager::instance()->remove_activation_info( $ext_key );
1073 }
1074 }
1075