コード例 #1
0
 function _do_system_reset()
 {
     global $wpdb, $mgm_init;
     extract($_POST);
     // track
     $status = 'error';
     $message = __('Reset failed', 'mgm');
     $redirect = '';
     // take option
     switch ($reset_type) {
         case 'settntable':
             // user meta
             $wpdb->query("DELETE FROM `{$wpdb->usermeta}` WHERE `meta_key` LIKE 'mgm_%' OR `meta_key` LIKE '_mgm_%'");
             // post meta
             $wpdb->query("DELETE FROM `{$wpdb->postmeta}` WHERE `meta_key` LIKE '_mgm_%' ");
             // loop tables
             foreach (mgm_get_tables() as $table) {
                 // do not clear countries table
                 if ($table == TBL_MGM_COUNTRY) {
                     continue;
                 }
                 // truncate
                 $wpdb->query('TRUNCATE ' . $table);
             }
             // set messages
             $status = 'success';
             $message = __('Settings and Table reset completed successfully.', 'mgm');
         case 'settonly':
             // option meta
             $wpdb->query("DELETE FROM `{$wpdb->options}` WHERE `option_name` LIKE 'mgm_%' AND option_name NOT IN('mgm_version','mgm_upgrade_id','mgm_auth','mgm_auth_options')");
             // set messages
             if ($reset_type == 'settonly') {
                 $status = 'success';
                 $message = __('Settings reset completed successfully.', 'mgm');
             }
             break;
         case 'fullreset':
             // plugin basename
             $plugin = untrailingslashit(MGM_PLUGIN_NAME);
             // if active
             if (is_plugin_active($plugin)) {
                 // post meta explicitly
                 $wpdb->query("DELETE FROM `{$wpdb->postmeta}` WHERE `meta_key` LIKE '_mgm_%' ");
                 // deactivate first
                 deactivate_plugins($plugin, true);
                 // remove all
                 $mgm_init->deactivate(true);
                 // send deactivation
                 mgm_get_class('auth')->notify_deactivation();
                 // sleep 2 sec
                 sleep(2);
                 // redirect
                 $status = 'success';
                 $message = __('MagicMembers deactivated successfully. You will be redirected to Plugins page.', 'mgm');
                 $redirect = 'plugins.php?deactivate=true&plugin_status=active&paged=1';
             } else {
                 $status = 'error';
                 $message = __('MagicMembers already deactivated', 'mgm');
             }
             break;
         case 'licensereset':
             // delete option
             delete_option('mgm_auth_options');
             delete_option('mgm_auth');
             // old key
             // clear dashboard cache
             mgm_delete_transients();
             // response
             $status = 'success';
             $message = __('License reset completed successfully.', 'mgm');
             $redirect = 'admin.php?page=mgm/admin';
             break;
         case 'dashcachereset':
             // clear dashboard cache
             mgm_delete_transients();
             // response
             $status = 'success';
             $message = __('Dashboard cache reset completed successfully.', 'mgm');
             break;
         case 'sidebarwidgetreset':
             // delete option
             delete_option('mgm_sidebar_widget_options');
             delete_option('mgm_sidebar_widget');
             // old key
             // response
             $status = 'success';
             $message = __('Sidebar Widget Settings reset completed successfully.', 'mgm');
             break;
     }
     // response
     return json_encode(array('status' => $status, 'message' => $message, 'redirect' => $redirect));
 }
コード例 #2
0
 function deactivate($force = false)
 {
     global $wpdb;
     // if remove by force
     if ($force) {
         // uninstall options
         $wpdb->query("DELETE FROM `{$wpdb->options}` WHERE `option_name` LIKE 'mgm_%' ");
         // user meta
         $wpdb->query("DELETE FROM `{$wpdb->usermeta}` WHERE `meta_key` LIKE 'mgm_%' OR `meta_key` LIKE '_mgm_%'");
         // post meta
         $wpdb->query("DELETE FROM `{$wpdb->postmeta}` WHERE `meta_key` LIKE '_mgm_%' ");
         // tables
         foreach (mgm_get_tables() as $table) {
             $wpdb->query("DROP TABLE IF EXISTS `{$table}`");
         }
     }
     // clear event hooks
     foreach (mgm_get_defined_schedules() as $schedule_name => $event_name) {
         wp_clear_scheduled_hook($event_name);
     }
     // clear dashboard cache
     mgm_delete_transients();
 }