PluginProbe
MainWP Dashboard: Self-hosted WordPress Management for Agencies / 5.3
MainWP Dashboard: Self-hosted WordPress Management for Agencies v5.3
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.3, at class/class-mainwp-system-handler.php

1,055 lines 46.3 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 { // phpcs:ignore Generic.Classes.OpeningBraceSameLine.ContentAfterBrace -- NOSONAR.
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 === static::$instance ) {
45 static::$instance = new self();
46 }
47
48 return static::$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( static::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. NOSONAR - not IP.
204 } else {
205 $output = apply_filters( $filter, $value );
206 }
207
208 if ( ! is_array( $output ) ) {
209 return array();
210 }
211 return $output;
212 }
213
214 /**
215 * Method admin_init()
216 *
217 * Do nothing if current user is not an Admin.
218 */
219 public function admin_init() { // phpcs:ignore -- NOSONAR - complex function.
220 if ( ! MainWP_System_Utility::is_admin() ) {
221 return;
222 }
223
224 global $pagenow;
225
226 if ( 'plugins.php' === $pagenow && isset( $_GET['do'] ) && 'checkUpgrade' === $_GET['do'] && ( ( time() - $this->upgradeVersionInfo->updated ) > 30 ) ) { // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
227 $this->check_upgrade();
228 delete_site_transient( 'update_plugins' ); // to forced refresh 'update_plugins' transient.
229 wp_safe_redirect( admin_url( 'plugins.php' ) );
230 exit;
231 }
232 }
233
234
235
236 /**
237 * Method hook_get_sql_websites_for_current_user()
238 *
239 * Get sql websites for current user.
240 *
241 * @param mixed $input_value First input filter value.
242 * @param string $pluginFile Extension plugin file to verify.
243 * @param string $key The child-key.
244 * @param mixed $params Input params data.
245 *
246 * @return string sql.
247 */
248 public static function hook_get_sql_websites_for_current_user( $input_value, $pluginFile, $key, $params ) {
249 unset( $input_value );
250 if ( ! MainWP_Extensions_Handler::hook_verify( $pluginFile, $key ) ) {
251 return false;
252 }
253 return MainWP_DB::instance()->get_sql_wp_for_current_user( $params );
254 }
255 /**
256 * Method handle_manage_sites_screen_settings()
257 *
258 * Handle manage sites screen settings
259 */
260 public function handle_manage_sites_screen_settings() { // phpcs:ignore -- NOSONAR - required to achieve desired results, pull request solutions appreciated.
261 if ( isset( $_POST['wp_nonce'] ) && wp_verify_nonce( sanitize_key( $_POST['wp_nonce'] ), 'ManageSitesScrOptions' ) ) {
262 $show_cols = array();
263 foreach ( array_map( 'sanitize_text_field', wp_unslash( $_POST ) ) as $key => $val ) {
264 if ( false !== strpos( $key, 'mainwp_show_column_' ) ) {
265 $col = str_replace( 'mainwp_show_column_', '', $key );
266 $show_cols[ $col ] = 1;
267 }
268 }
269 if ( isset( $_POST['show_columns_name'] ) ) {
270 foreach ( array_map( 'sanitize_text_field', wp_unslash( $_POST['show_columns_name'] ) ) as $col ) {
271 if ( ! isset( $show_cols[ $col ] ) ) {
272 $show_cols[ $col ] = 0; // uncheck, hide columns.
273 }
274 }
275 }
276 MainWP_Utility::update_option( 'mainwp_use_favicon', 1 );
277 MainWP_Utility::update_option( 'mainwp_optimize', ( ! isset( $_POST['mainwp_optimize'] ) ? 0 : 1 ) );
278 $user = wp_get_current_user();
279 if ( $user ) {
280 $val = ( isset( $_POST['mainwp_sitesviewmode'] ) ? sanitize_text_field( wp_unslash( $_POST['mainwp_sitesviewmode'] ) ) : 'grid' );
281 if ( 'grid' !== $val && 'table' !== $val ) {
282 $val = 'grid';
283 }
284 update_user_option( $user->ID, 'mainwp_sitesviewmode', $val, true );
285 update_user_option( $user->ID, 'mainwp_settings_show_manage_sites_columns', $show_cols, true );
286 update_option( 'mainwp_default_sites_per_page', ( isset( $_POST['mainwp_default_sites_per_page'] ) ? intval( $_POST['mainwp_default_sites_per_page'] ) : 25 ) );
287 }
288 } elseif ( isset( $_POST['wp_nonce'] ) && wp_verify_nonce( sanitize_key( $_POST['wp_nonce'] ), 'SreenshotsSitesScrOptions' ) ) {
289 $user = wp_get_current_user();
290 if ( $user ) {
291 $val = ( isset( $_POST['mainwp_sitesviewmode'] ) ? sanitize_text_field( wp_unslash( $_POST['mainwp_sitesviewmode'] ) ) : 'grid' );
292 if ( 'grid' !== $val && 'table' !== $val ) {
293 $val = 'grid';
294 }
295 update_user_option( $user->ID, 'mainwp_sitesviewmode', $val, true );
296 }
297 }
298 }
299
300 /**
301 * Method handle_monitoring_sites_screen_settings()
302 *
303 * Handle monitoring sites screen settings
304 */
305 public function handle_monitoring_sites_screen_settings() { // phpcs:ignore -- NOSONAR - complex.
306 if ( isset( $_POST['wp_nonce'] ) && wp_verify_nonce( sanitize_key( $_POST['wp_nonce'] ), 'MonitoringSitesScrOptions' ) ) {
307 $show_cols = array();
308 foreach ( array_map( 'sanitize_text_field', wp_unslash( $_POST ) ) as $key => $val ) {
309 if ( false !== strpos( $key, 'mainwp_show_column_' ) ) {
310 $col = str_replace( 'mainwp_show_column_', '', $key );
311 $show_cols[ $col ] = 1;
312 }
313 }
314 if ( isset( $_POST['show_columns_name'] ) ) {
315 foreach ( array_map( 'sanitize_text_field', wp_unslash( $_POST['show_columns_name'] ) ) as $col ) {
316 if ( ! isset( $show_cols[ $col ] ) ) {
317 $show_cols[ $col ] = 0; // uncheck, hide columns.
318 }
319 }
320 }
321
322 $user = wp_get_current_user();
323 if ( $user ) {
324 update_user_option( $user->ID, 'mainwp_settings_show_monitoring_sites_columns', $show_cols, true );
325 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 ) );
326 }
327
328 update_option( 'mainwp_disableSitesHealthMonitoring', ( ! isset( $_POST['mainwp_disable_sitesHealthMonitoring'] ) ? 1 : 0 ) );
329
330 $val = isset( $_POST['mainwp_site_healthThreshold'] ) ? intval( $_POST['mainwp_site_healthThreshold'] ) : 80;
331 update_option( 'mainwp_sitehealthThreshold', $val );
332 }
333 }
334
335 /**
336 * Method handle_clients_screen_settings()
337 *
338 * Handle manage clients screen settings
339 */
340 public function handle_clients_screen_settings() { // phpcs:ignore -- NOSONAR - complex.
341 if ( isset( $_POST['wp_nonce'] ) && wp_verify_nonce( sanitize_key( $_POST['wp_nonce'] ), 'ManageClientsScrOptions' ) ) {
342 $show_cols = array();
343 foreach ( array_map( 'sanitize_text_field', wp_unslash( $_POST ) ) as $key => $val ) {
344 if ( false !== strpos( $key, 'mainwp_show_column_' ) ) {
345 $col = str_replace( 'mainwp_show_column_', '', $key );
346 $show_cols[ $col ] = 1;
347 }
348 }
349 if ( isset( $_POST['show_columns_name'] ) ) {
350 foreach ( array_map( 'sanitize_text_field', wp_unslash( $_POST['show_columns_name'] ) ) as $col ) {
351 if ( ! isset( $show_cols[ $col ] ) ) {
352 $show_cols[ $col ] = 0; // uncheck, hide columns.
353 }
354 }
355 }
356
357 $user = wp_get_current_user();
358 if ( $user ) {
359 update_user_option( $user->ID, 'mainwp_settings_show_manage_clients_columns', $show_cols, true );
360 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 ) );
361 }
362 }
363 }
364
365 /**
366 * Method handle_clients_screen_settings()
367 *
368 * Handle manage clients screen settings
369 */
370 public function handle_updates_screen_settings() {
371 if ( isset( $_POST['wp_nonce'] ) && wp_verify_nonce( sanitize_key( $_POST['wp_nonce'] ), 'UpdatesScrOptions' ) ) {
372 $val = ( ! isset( $_POST['mainwp_pluginAutomaticDailyUpdate'] ) ? 0 : intval( $_POST['mainwp_pluginAutomaticDailyUpdate'] ) );
373 MainWP_Utility::update_option( 'mainwp_pluginAutomaticDailyUpdate', $val );
374 $val = ( ! isset( $_POST['mainwp_themeAutomaticDailyUpdate'] ) ? 0 : intval( $_POST['mainwp_themeAutomaticDailyUpdate'] ) );
375 MainWP_Utility::update_option( 'mainwp_themeAutomaticDailyUpdate', $val );
376 $val = ( ! isset( $_POST['mainwp_automaticDailyUpdate'] ) ? 0 : intval( $_POST['mainwp_automaticDailyUpdate'] ) );
377 MainWP_Utility::update_option( 'mainwp_automaticDailyUpdate', $val );
378 $val = ( isset( $_POST['mainwp_delay_autoupdate'] ) ? intval( $_POST['mainwp_delay_autoupdate'] ) : 1 );
379 MainWP_Utility::update_option( 'mainwp_delay_autoupdate', $val );
380 $val = ( ! isset( $_POST['mainwp_show_language_updates'] ) ? 0 : 1 );
381 MainWP_Utility::update_option( 'mainwp_show_language_updates', $val );
382 $val = ( ! isset( $_POST['mainwp_disable_update_confirmations'] ) ? 0 : intval( $_POST['mainwp_disable_update_confirmations'] ) );
383 MainWP_Utility::update_option( 'mainwp_disable_update_confirmations', $val );
384 }
385 }
386
387
388 /**
389 * Method handle_mainwp_tools_settings()
390 *
391 * Handle mainwp tools settings.
392 *
393 * @uses \MainWP\Dashboard\MainWP_Twitter::clear_all_twitter_messages()
394 * @uses \MainWP\Dashboard\MainWP_Utility::update_option()
395 */
396 public function handle_mainwp_tools_settings() { // phpcs:ignore -- NOSONAR -Current complexity is the only way to achieve desired results, pull request solutions appreciated.
397
398 $user = wp_get_current_user();
399
400 $update_selected_mainwp_themes = false;
401
402 if ( isset( $_GET['page'] ) && 'MainWPTools' === $_GET['page'] && isset( $_POST['wp_nonce'] ) && wp_verify_nonce( sanitize_key( $_POST['wp_nonce'] ), 'MainWPTools' ) ) {
403 if ( isset( $_POST['mainwp_restore_info_messages'] ) && ! empty( $_POST['mainwp_restore_info_messages'] ) ) {
404 delete_user_option( $user->ID, 'mainwp_notice_saved_status' );
405 }
406 $enabled_tours = ! isset( $_POST['mainwp-guided-tours-option'] ) ? 0 : 1;
407 MainWP_Utility::update_option( 'mainwp_enable_guided_tours', $enabled_tours );
408
409 if ( isset( $_POST['mainwp_settings_custom_theme'] ) ) {
410 $update_selected_mainwp_themes = true;
411 }
412 }
413
414 if ( isset( $_POST['wp_scr_options_nonce'] ) && wp_verify_nonce( sanitize_key( $_POST['wp_scr_options_nonce'] ), 'MainWPSelectThemes' ) ) {
415 $update_selected_mainwp_themes = true;
416 }
417
418 if ( $update_selected_mainwp_themes && isset( $_POST['mainwp_settings_custom_theme'] ) ) {
419 $custom_theme = sanitize_text_field( wp_unslash( $_POST['mainwp_settings_custom_theme'] ) );
420 update_user_option( $user->ID, 'mainwp_selected_theme', $custom_theme );
421 }
422
423 $update_screen_options = false;
424 if ( isset( $_POST['wp_nonce'] ) && ( wp_verify_nonce( sanitize_key( $_POST['wp_nonce'] ), 'Settings' ) || wp_verify_nonce( sanitize_key( $_POST['wp_nonce'] ), 'MainWPScrOptions' ) ) ) {
425 $update_screen_options = true;
426 }
427
428 if ( $update_screen_options ) {
429 $show_wids = array();
430 if ( isset( $_POST['mainwp_show_widgets'] ) && is_array( $_POST['mainwp_show_widgets'] ) ) {
431 $selected_wids = array_map( 'sanitize_text_field', wp_unslash( $_POST['mainwp_show_widgets'] ) );
432 foreach ( $selected_wids as $name ) {
433 $show_wids[ $name ] = 1;
434 }
435 }
436
437 if ( isset( $_POST['mainwp_widgets_name'] ) && is_array( $_POST['mainwp_widgets_name'] ) ) {
438 $name_wids = array_map( 'sanitize_text_field', wp_unslash( $_POST['mainwp_widgets_name'] ) );
439 foreach ( $name_wids as $name ) {
440 if ( ! isset( $show_wids[ $name ] ) ) {
441 $show_wids[ $name ] = 0;
442 }
443 }
444 }
445
446 $show_cols = array();
447 if ( isset( $_POST['mainwp_show_columns'] ) && is_array( $_POST['mainwp_show_columns'] ) ) {
448 $selected_cols = array_map( 'sanitize_text_field', wp_unslash( $_POST['mainwp_show_columns'] ) );
449 foreach ( $selected_cols as $name ) {
450 $show_cols[ $name ] = 1;
451 }
452 }
453
454 if ( isset( $_POST['mainwp_columns_name'] ) && is_array( $_POST['mainwp_columns_name'] ) ) {
455 $name_cols = array_map( 'sanitize_text_field', wp_unslash( $_POST['mainwp_columns_name'] ) );
456 foreach ( $name_cols as $name ) {
457 if ( ! isset( $show_cols[ $name ] ) ) {
458 $show_cols[ $name ] = 0;
459 }
460 }
461 }
462
463 $val = ( isset( $_POST['mainwp_sidebarPosition'] ) ? intval( $_POST['mainwp_sidebarPosition'] ) : 1 );
464 if ( $user ) {
465 update_user_option( $user->ID, 'mainwp_settings_show_widgets', $show_wids, true );
466 update_user_option( $user->ID, 'mainwp_sidebarPosition', $val, true );
467
468 if ( isset( $_POST['mainwp_manageposts_show_columns_settings'] ) ) {
469 update_user_option( $user->ID, 'mainwp_manageposts_show_columns', $show_cols, true );
470 }
471
472 if ( isset( $_POST['mainwp_managepages_show_columns_settings'] ) ) {
473 update_user_option( $user->ID, 'mainwp_managepages_show_columns', $show_cols, true );
474 }
475
476 if ( isset( $_POST['mainwp_manageusers_show_columns_settings'] ) ) {
477 update_user_option( $user->ID, 'mainwp_manageusers_show_columns', $show_cols, true );
478 }
479 }
480
481 MainWP_Utility::update_option( 'mainwp_hide_update_everything', ( ! isset( $_POST['hide_update_everything'] ) ? 0 : 1 ) );
482
483 if ( isset( $_POST['reset_overview_settings'] ) && ! empty( $_POST['reset_overview_settings'] ) && isset( $_POST['reset_overview_which_settings'] ) && 'overview_settings' === $_POST['reset_overview_which_settings'] ) {
484 update_user_option( $user->ID, 'mainwp_widgets_sorted_toplevel_page_mainwp_tab', false, true );
485 update_user_option( $user->ID, 'mainwp_widgets_sorted_mainwp_page_managesites', false, true );
486 }
487 }
488
489 $update_clients_screen_options = false;
490 if ( isset( $_POST['wp_scr_options_nonce'] ) && wp_verify_nonce( sanitize_key( $_POST['wp_scr_options_nonce'] ), 'MainWPClientsScrOptions' ) ) {
491 $update_clients_screen_options = true;
492 }
493 if ( $update_clients_screen_options ) {
494
495 $show_wids = array();
496 if ( isset( $_POST['mainwp_show_widgets'] ) && is_array( $_POST['mainwp_show_widgets'] ) ) {
497 $selected_wids = array_map( 'sanitize_text_field', wp_unslash( $_POST['mainwp_show_widgets'] ) );
498 foreach ( $selected_wids as $name ) {
499 $show_wids[ $name ] = 1;
500 }
501 }
502
503 if ( isset( $_POST['mainwp_widgets_name'] ) && is_array( $_POST['mainwp_widgets_name'] ) ) {
504 $name_wids = array_map( 'sanitize_text_field', wp_unslash( $_POST['mainwp_widgets_name'] ) );
505 foreach ( $name_wids as $name ) {
506 if ( ! isset( $show_wids[ $name ] ) ) {
507 $show_wids[ $name ] = 0;
508 }
509 }
510 }
511
512 if ( $user ) {
513 update_user_option( $user->ID, 'mainwp_clients_show_widgets', $show_wids, true );
514 }
515
516 if ( isset( $_POST['reset_client_overview_settings'] ) && ! empty( $_POST['reset_client_overview_settings'] ) ) {
517 update_user_option( $user->ID, 'mainwp_widgets_sorted_mainwp_page_manageclients', false, true );
518 }
519 }
520 }
521
522 /**
523 * Method handle_settings_post()
524 *
525 * Handle saving settings page.
526 *
527 * @uses \MainWP\Dashboard\MainWP_Backup_Handler::handle_settings_post()
528 * @uses \MainWP\Dashboard\MainWP_DB_Common::get_user_extension()
529 * @uses \MainWP\Dashboard\MainWP_DB_Common::update_user_extension()
530 * @uses \MainWP\Dashboard\MainWP_Monitoring_Handler::handle_settings_post()
531 * @uses \MainWP\Dashboard\MainWP_Settings::handle_settings_post()
532 */
533 public function handle_settings_post() { // phpcs:ignore -- NOSONAR - complex method.
534
535 if ( isset( $_GET['page'] ) && ( isset( $_POST['wp_nonce'] ) || isset( $_POST['wp_scr_options_nonce'] ) ) ) {
536 $this->include_pluggable();
537 $this->handle_mainwp_tools_settings();
538 $this->handle_manage_sites_screen_settings();
539 $this->handle_monitoring_sites_screen_settings();
540 $this->handle_clients_screen_settings();
541 $this->handle_updates_screen_settings();
542 }
543
544 if ( isset( $_POST['select_mainwp_options_siteview'] ) ) {
545 $this->include_pluggable();
546 if ( check_admin_referer( 'mainwp-admin-nonce' ) ) {
547 $userExtension = MainWP_DB_Common::instance()->get_user_extension();
548 $userExtension->site_view = ( empty( $_POST['select_mainwp_options_siteview'] ) ? MAINWP_VIEW_PER_PLUGIN_THEME : intval( $_POST['select_mainwp_options_siteview'] ) );
549 MainWP_DB_Common::instance()->update_user_extension( $userExtension );
550 }
551 }
552
553 if ( isset( $_POST['select_mainwp_options_plugintheme_view'] ) ) {
554 $this->include_pluggable();
555 if ( check_admin_referer( 'mainwp-admin-nonce' ) ) {
556 $view_per = ( empty( $_POST['select_mainwp_options_plugintheme_view'] ) ? MAINWP_VIEW_PER_PLUGIN_THEME : intval( $_POST['select_mainwp_options_plugintheme_view'] ) );
557 $which = isset( $_POST['whichview'] ) ? sanitize_text_field( wp_unslash( $_POST['whichview'] ) ) : '';
558 if ( 'plugin' === $which ) {
559 MainWP_Utility::update_user_option( 'mainwp_manage_plugin_view', $view_per );
560 } else {
561 MainWP_Utility::update_user_option( 'mainwp_manage_theme_view', $view_per );
562 }
563 }
564 }
565
566 if ( isset( $_POST['submit'] ) && isset( $_POST['wp_nonce'] ) ) {
567 $this->include_pluggable();
568 if ( wp_verify_nonce( sanitize_key( $_POST['wp_nonce'] ), 'Settings' ) ) {
569 $updated = MainWP_Settings::handle_settings_post();
570 $updated |= MainWP_Backup_Handler::handle_settings_post();
571 $updated |= MainWP_Monitoring_Handler::handle_settings_post();
572 $msg = '';
573 if ( $updated ) {
574 $msg = '&message=saved';
575 }
576 wp_safe_redirect( admin_url( 'admin.php?page=Settings' . $msg ) );
577 exit();
578 }
579 }
580
581 if ( isset( $_POST['mainwp_sidebar_position'] ) && isset( $_POST['wp_nonce'] ) && wp_verify_nonce( sanitize_key( $_POST['wp_nonce'] ), 'onchange_sidebarposition' ) ) {
582 $val = isset( $_POST['mainwp_sidebar_position'] ) && ! empty( $_POST['mainwp_sidebar_position'] ) ? 1 : 0;
583 $user = wp_get_current_user();
584 if ( $user ) {
585 update_user_option( $user->ID, 'mainwp_sidebarPosition', $val, true );
586 }
587 return true;
588 }
589
590 if ( isset( $_GET['viewmode'] ) && isset( $_GET['modenonce'] ) ) {
591 $viewmode = sanitize_text_field( wp_unslash( $_GET['viewmode'] ) );
592 $nonce = sanitize_key( $_GET['modenonce'] );
593 if ( ( 'table' === $viewmode || 'grid' === $viewmode ) && wp_verify_nonce( sanitize_key( $nonce ), 'viewmode' ) ) {
594 $user = wp_get_current_user();
595 if ( $user ) {
596 update_user_option( $user->ID, 'mainwp_sitesviewmode', $viewmode, true );
597 wp_safe_redirect( admin_url( 'admin.php?page=managesites' ) );
598 exit;
599 }
600 }
601 }
602 }
603
604 /**
605 * Method include_pluggable()
606 *
607 * Include pluggable functions.
608 */
609 public function include_pluggable() {
610 // may causing of conflict with Post S m t p plugin.
611 if ( ! function_exists( 'wp_create_nonce' ) ) {
612 include_once ABSPATH . WPINC . '/pluggable.php'; // NOSONAR - WP compatible.
613 }
614 }
615
616 /**
617 * Method plugins_api_extension_info()
618 *
619 * Get MainWP Extension api information.
620 *
621 * @param mixed $input_value Return value.
622 * @param mixed $action Action being performed.
623 * @param mixed $arg Action arguments. Should be the plugin slug.
624 *
625 * @return mixed $info|$input_value
626 *
627 * @uses \MainWP\Dashboard\MainWP_API_Handler::get_update_information()
628 * @uses \MainWP\Dashboard\MainWP_Extensions_View::get_available_extensions()
629 * @uses \MainWP\Dashboard\MainWP_System::get_plugin_slug()
630 * @uses \MainWP\Dashboard\MainWP_Extensions_Handler::get_slugs()
631 */
632 public function plugins_api_extension_info( $input_value, $action, $arg ) { // phpcs:ignore -- NOSONAR - complex.
633 if ( 'plugin_information' !== $action ) {
634 return $input_value;
635 }
636
637 if ( is_array( $arg ) ) {
638 $arg = (object) $arg;
639 }
640
641 if ( ! isset( $arg->slug ) || ( '' === $arg->slug ) ) {
642 return $input_value;
643 }
644
645 if ( dirname( MainWP_System::instance()->get_plugin_slug() ) === $arg->slug ) {
646 return $input_value;
647 }
648
649 $result = MainWP_Extensions_Handler::get_slugs();
650 $am_slugs = $result['am_slugs'];
651
652 if ( '' !== $am_slugs ) {
653 $am_slugs = explode( ',', $am_slugs );
654 if ( false !== strpos( $arg->slug, '/' ) ) { // to fix.
655 $dir_slug = dirname( $arg->slug );
656 } else {
657 $dir_slug = $arg->slug;
658 }
659 if ( in_array( $dir_slug, $am_slugs ) ) {
660 $info = MainWP_API_Handler::get_update_information( $dir_slug );
661 if ( is_object( $info ) && property_exists( $info, 'sections' ) ) {
662 if ( ! is_array( $info->sections ) || ! isset( $info->sections['changelog'] ) || empty( $info->sections['changelog'] ) ) {
663 $exts_data = MainWP_Extensions_View::get_available_extensions();
664 if ( isset( $exts_data[ $arg->slug ] ) ) {
665 $ext_info = $exts_data[ $arg->slug ];
666 $changelog_link = rtrim( $ext_info['changelog_url'], '/' );
667 $info->sections['changelog'] = '<a href="' . $changelog_link . '" target="_blank">' . $changelog_link . '</a>';
668 }
669 }
670 return $info;
671 }
672 return $info;
673 }
674 }
675
676 return $input_value;
677 }
678
679 /**
680 * Method plugins_api_wp_plugins_api_result()
681 *
682 * Hook after get plugins api information.
683 *
684 * @param mixed $res api information value.
685 * @param mixed $action Action being performed.
686 * @param mixed $arg Action arguments. Should be the plugin slug.
687 *
688 * @return mixed $res
689 */
690 public function plugins_api_wp_plugins_api_result( $res, $action, $arg ) { // phpcs:ignore -- NOSONAR - complex.
691
692 if ( 'plugin_information' !== $action ) {
693 return $res;
694 }
695
696 if ( is_object( $res ) && property_exists( $res, 'slug' ) && property_exists( $res, 'sections' ) ) {
697 return $res;
698 }
699
700 if ( ! isset( $_GET['wpplugin'] ) || ! is_numeric( $_GET['wpplugin'] ) || empty( $_GET['wpplugin'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
701 return $res;
702 }
703
704 if ( is_array( $arg ) ) {
705 $arg = (object) $arg;
706 }
707
708 if ( ! isset( $arg->slug ) || ( '' === $arg->slug ) ) {
709 return $res;
710 }
711
712 $site_id = intval( $_GET['wpplugin'] ); // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
713
714 if ( $site_id ) {
715 $website = MainWP_DB::instance()->get_website_by_id( $site_id );
716 if ( $website && ! empty( $website->plugin_upgrades ) ) {
717 $plugin_upgrades = json_decode( $website->plugin_upgrades, true );
718
719 if ( is_array( $plugin_upgrades ) ) {
720 $found_update = false;
721 $empty_sections = false;
722 foreach ( $plugin_upgrades as $plugin_slug => $info ) {
723 if ( false !== strpos( $plugin_slug, $arg->slug ) && isset( $info['update'] ) ) {
724 $found_update = true;
725 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'] ) ) {
726 $info_update = (object) $info['update'];
727 $info_update->external = false;
728 return $info_update;
729 }
730 $empty_sections = true;
731 break;
732 }
733 }
734
735 if ( $found_update && $empty_sections ) {
736 try {
737 $info = MainWP_Connect::fetch_url_authed(
738 $website,
739 'plugin_action',
740 array(
741 'action' => 'changelog_info', // try to get changelog from the child site.
742 'slug' => $arg->slug,
743 )
744 );
745 if ( is_array( $info ) && isset( $info['update'] ) && ! empty( $info['update']['sections'] ) ) {
746 $info_update = (object) $info['update'];
747 $info_update->external = true;
748 return $info_update;
749 }
750 } catch ( \Exception $e ) {
751 // error happen.
752 }
753 }
754 }
755 }
756 }
757
758 return $res;
759 }
760
761 /**
762 * Method check_update_custom()
763 *
764 * Check MainWP Extensions for updates.
765 *
766 * @param object $transient Transient information.
767 *
768 * @return object $transient Transient information.
769 *
770 * @uses \MainWP\Dashboard\MainWP_API_Handler::get_upgrade_information()
771 * @uses \MainWP\Dashboard\MainWP_Extensions_Handler::get_indexed_extensions_infor()
772 * @uses \MainWP\Dashboard\MainWP_Extensions_Handler::get_extension_slug()
773 * @uses \MainWP\Dashboard\MainWP_Utility::update_option()
774 */
775 public function check_update_custom( $transient ) { // phpcs:ignore -- NOSONAR -Current complexity is the only way to achieve desired results, pull request solutions appreciated.
776 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
777 $extensions = MainWP_Extensions_Handler::get_indexed_extensions_infor( array( 'activated' => true ) );
778 if ( defined( 'DOING_AJAX' ) && isset( $_POST['plugin'] ) && 'update-plugin' === $_POST['action'] ) { // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
779
780 if ( empty( $transient->response ) ) {
781 $transient->response = array();
782 }
783
784 $plugin_slug = sanitize_text_field( wp_unslash( $_POST['plugin'] ) ); // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
785 if ( isset( $extensions[ $plugin_slug ] ) ) {
786
787 if ( ! isset( $transient->response[ $plugin_slug ] ) || ! is_object( $transient->response[ $plugin_slug ] ) || ! property_exists( $transient->response[ $plugin_slug ], 'new_version' ) ) {
788 return $transient;
789 }
790
791 if ( isset( $transient->response[ $plugin_slug ] ) && version_compare( $transient->response[ $plugin_slug ]->new_version, $extensions[ $plugin_slug ]['version'], '=' ) ) {
792 return $transient;
793 }
794
795 $api_slug = dirname( $plugin_slug );
796 $rslt = MainWP_API_Handler::get_upgrade_information( $api_slug );
797
798 if ( ! empty( $rslt ) && is_object( $rslt ) && property_exists( $rslt, 'new_version' ) && ! empty( $rslt->new_version ) && version_compare( $rslt->new_version, $extensions[ $plugin_slug ]['version'], '>' ) ) {
799 $transient->response[ $plugin_slug ] = static::map_rslt_obj( $rslt );
800 }
801
802 return $transient;
803 }
804 } elseif ( 'update-selected' === $_POST['action'] && isset( $_POST['checked'] ) && is_array( $_POST['checked'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
805
806 if ( empty( $transient->response ) ) {
807 $transient->response = array();
808 }
809
810 $updated = false;
811 foreach ( wp_unslash( $_POST['checked'] ) as $plugin_slug ) { // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
812 if ( isset( $extensions[ $plugin_slug ] ) ) {
813
814 if ( ! isset( $transient->response[ $plugin_slug ] ) ) {
815 $transient->response[ $plugin_slug ] = new \stdClass();
816 }
817
818 if ( isset( $transient->response[ $plugin_slug ] ) && version_compare( $transient->response[ $plugin_slug ]->new_version, $extensions[ $plugin_slug ]['version'], '=' ) ) {
819 continue;
820 }
821 $api_slug = dirname( $plugin_slug );
822 $rslt = MainWP_API_Handler::get_upgrade_information( $api_slug );
823 if ( ! empty( $rslt ) && is_object( $rslt ) && property_exists( $rslt, 'new_version' ) && ! empty( $rslt->new_version ) && version_compare( $rslt->new_version, $extensions[ $plugin_slug ]['version'], '>' ) ) {
824 $this->upgradeVersionInfo->result[ $api_slug ] = $rslt;
825 $transient->response[ $plugin_slug ] = static::map_rslt_obj( $rslt );
826 $updated = true;
827 }
828 }
829 }
830 if ( $updated ) {
831 MainWP_Utility::update_option( 'mainwp_upgradeVersionInfo', $this->upgradeVersionInfo );
832 }
833
834 return $transient;
835 }
836 }
837
838 if ( empty( $transient->checked ) ) {
839 return $transient;
840 }
841
842 if ( ! empty( $this->upgradeVersionInfo ) && property_exists( $this->upgradeVersionInfo, 'result' ) && is_array( $this->upgradeVersionInfo->result ) ) {
843 foreach ( $this->upgradeVersionInfo->result as $rslt ) {
844 if ( ! isset( $rslt->slug ) ) {
845 continue;
846 }
847
848 $plugin_slug = MainWP_Extensions_Handler::get_extension_slug( $rslt->slug );
849 if ( isset( $transient->checked[ $plugin_slug ] ) && property_exists( $rslt, 'new_version' ) && ! empty( $rslt->new_version ) && version_compare( $rslt->new_version, $transient->checked[ $plugin_slug ], '>' ) ) {
850 $transient->response[ $plugin_slug ] = static::map_rslt_obj( $rslt );
851 }
852 }
853 }
854
855 return $transient;
856 }
857
858
859 /**
860 * Method map_rslt_obj()
861 *
862 * Map resulting object.
863 *
864 * @param object $result Resulting information.
865 *
866 * @return object $obj Mapped resulting object.
867 */
868 public static function map_rslt_obj( $result ) {
869 $obj = new \stdClass();
870 $obj->slug = $result->slug;
871 $obj->new_version = $result->new_version;
872 $obj->url = 'https://mainwp.com/';
873 $obj->package = $result->package;
874
875 return $obj;
876 }
877
878 /**
879 * Method check_upgrade()
880 *
881 * Check if Extension has an update.
882 *
883 * @uses \MainWP\Dashboard\MainWP_API_Handler::check_exts_upgrade()
884 * @uses \MainWP\Dashboard\MainWP_Utility::update_option()
885 */
886 private function check_upgrade() {
887 $result = MainWP_API_Handler::check_exts_upgrade();
888 if ( null === $this->upgradeVersionInfo ) {
889 $this->upgradeVersionInfo = new \stdClass();
890 }
891 $this->upgradeVersionInfo->updated = time();
892 if ( ! empty( $result ) ) {
893 $this->upgradeVersionInfo->result = $result;
894 }
895 MainWP_Utility::update_option( 'mainwp_upgradeVersionInfo', $this->upgradeVersionInfo );
896 }
897
898 /**
899 * Method pre_check_update_custom()
900 *
901 * Pre-check for extension updates.
902 *
903 * @param object $transient Transient information.
904 *
905 * @return object $transient Transient information.
906 *
907 * @uses \MainWP\Dashboard\MainWP_Extensions_Handler::get_indexed_extensions_infor()
908 * @uses \MainWP\Dashboard\MainWP_Extensions_Handler::get_extension_slug()
909 */
910 public function pre_check_update_custom( $transient ) {
911 if ( ! isset( $transient->checked ) ) {
912 return $transient;
913 }
914
915 if ( ( null === $this->upgradeVersionInfo ) || ! property_exists( $this->upgradeVersionInfo, 'updated' ) || ( ( time() - $this->upgradeVersionInfo->updated ) > 60 ) ) {
916 $this->check_upgrade();
917 }
918
919 if ( empty( $transient->response ) ) {
920 $transient->response = array();
921 }
922
923 if ( ! empty( $this->upgradeVersionInfo ) && property_exists( $this->upgradeVersionInfo, 'result' ) && is_array( $this->upgradeVersionInfo->result ) ) {
924 $extensions = MainWP_Extensions_Handler::get_indexed_extensions_infor( array( 'activated' => true ) );
925 foreach ( $this->upgradeVersionInfo->result as $rslt ) {
926 $plugin_slug = MainWP_Extensions_Handler::get_extension_slug( $rslt->slug );
927 if ( isset( $extensions[ $plugin_slug ] ) && property_exists( $rslt, 'new_version' ) && ! empty( $rslt->new_version ) && version_compare( $rslt->new_version, $extensions[ $plugin_slug ]['version'], '>' ) ) {
928 $transient->response[ $plugin_slug ] = static::map_rslt_obj( $rslt );
929 }
930 }
931 }
932
933 return $transient;
934 }
935
936 /**
937 * Method upload_file()
938 *
939 * Upload a file.
940 *
941 * @param mixed $file File to upload.
942 *
943 * @return void
944 *
945 * @uses \MainWP\Dashboard\MainWP_Utility::ends_with()
946 */
947 public function upload_file( $file ) {
948 header( 'Content-Description: File Transfer' );
949 $dwl_fname = basename( $file );
950 if ( 'tar.gz' === $dwl_fname || '.tar.gz' === $dwl_fname ) {
951 $dwl_fname = 'noname.tar.gz'; // to fix name of zip file.
952 }
953 header( 'Content-Type: application/octet-stream' );
954 header( 'Content-Disposition: attachment; filename="' . $dwl_fname . '"' );
955 header( 'Expires: 0' );
956 header( 'Cache-Control: must-revalidate' );
957 header( 'Pragma: public' );
958 header( 'Content-Length: ' . filesize( $file ) );
959 while ( ob_get_level() ) {
960 ob_end_clean();
961 }
962 $this->readfile_chunked( $file );
963 exit();
964 }
965
966 /**
967 * Method readfile_chunked()
968 *
969 * Read Chunked File.
970 *
971 * @param mixed $filename Name of file.
972 *
973 * @return mixed echo $buffer|false|$handle.
974 */
975 public function readfile_chunked( $filename ) {
976 $chunksize = 1024;
977 $handle = fopen( $filename, 'rb' );
978 if ( false === $handle ) {
979 return false;
980 }
981
982 while ( ! feof( $handle ) ) {
983 $buffer = fread( $handle, $chunksize );
984 echo $buffer; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
985 if ( ob_get_length() ) {
986 ob_flush();
987 flush();
988 }
989 $buffer = null;
990 }
991
992 return fclose( $handle );
993 }
994
995 /**
996 * Method activate_redirection()
997 *
998 * Redirect after activating MainWP Extension.
999 *
1000 * @param mixed $location Location to redirect to.
1001 *
1002 * @return $location Admin URL + the page to redirect to.
1003 */
1004 public function activate_redirect( $location ) {
1005 unset( $location );
1006 return admin_url( 'admin.php?page=Extensions' );
1007 }
1008
1009 /**
1010 * Method activate_extension()
1011 *
1012 * Activate MainWP Extension.
1013 *
1014 * @param mixed $ext_key Extension API Key.
1015 * @param array $info Extension Info.
1016 *
1017 * @uses \MainWP\Dashboard\MainWP_Api_Manager::set_activation_info()
1018 * @uses \MainWP\Dashboard\MainWP_Api_Manager_Password_Management::generate_password()
1019 */
1020 public function activate_extension( $ext_key, $info = array() ) {
1021
1022 add_filter( 'wp_redirect', array( $this, 'activate_redirect' ) );
1023
1024 if ( is_array( $info ) && isset( $info['product_id'] ) && isset( $info['software_version'] ) ) {
1025 $act_info = array(
1026 'product_id' => $info['product_id'],
1027 'software_version' => $info['software_version'],
1028 'activated_key' => 'Deactivated',
1029 'instance_id' => MainWP_Api_Manager_Password_Management::generate_password( 12, false ),
1030 );
1031 MainWP_Api_Manager::instance()->set_activation_info( $ext_key, $act_info );
1032 }
1033 }
1034
1035 /**
1036 * Method deactivate_extension()
1037 *
1038 * Deactivate MaiNWP Extension.
1039 *
1040 * @param mixed $ext_key Exnension API Key.
1041 * @param bool $dashboard_only Deactive API Key on dashboard only.
1042 *
1043 * @uses \MainWP\Dashboard\MainWP_Api_Manager::set_activation_info()
1044 */
1045 public function deactivate_extension( $ext_key, $dashboard_only = false ) {
1046 // try to deactivate license.
1047 if ( ! $dashboard_only ) {
1048 $mainwp_api_key = MainWP_Api_Manager_Key::instance()->get_decrypt_master_api_key();
1049 MainWP_Api_Manager::instance()->license_key_deactivation( $ext_key, $mainwp_api_key );
1050 }
1051
1052 MainWP_Api_Manager::instance()->remove_activation_info( $ext_key );
1053 }
1054 }
1055