/** * plugin_uninstall * * @access public * @static * @param bool $remove_all * @return void */ public static function delete_all_espresso_tables_and_data($remove_all = true) { global $wpdb; $undeleted_tables = array(); // load registry foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) { if (method_exists($model_name, 'instance')) { $model_obj = call_user_func(array($model_name, 'instance')); if ($model_obj instanceof EEM_Base) { foreach ($model_obj->get_tables() as $table) { if (strpos($table->get_table_name(), 'esp_')) { switch (EEH_Activation::delete_unused_db_table($table->get_table_name())) { case false: $undeleted_tables[] = $table->get_table_name(); break; case 0: // echo '<h4 style="color:red;">the table : ' . $table->get_table_name() . ' was not deleted <br /></h4>'; break; default: // echo '<h4>the table : ' . $table->get_table_name() . ' was deleted successfully <br /></h4>'; } } } } } } //there are some tables whose models were removed. //they should be removed when removing all EE core's data $tables_without_models = array('esp_promotion', 'esp_promotion_applied', 'esp_promotion_object', 'esp_promotion_rule', 'esp_rule'); foreach ($tables_without_models as $table) { EEH_Activation::delete_db_table_if_empty($table); } $wp_options_to_delete = array('ee_no_ticket_prices' => true, 'ee_active_messengers' => true, 'ee_has_activated_messenger' => true, 'ee_flush_rewrite_rules' => true, 'ee_config' => false, 'ee_data_migration_current_db_state' => true, 'ee_data_migration_mapping_' => false, 'ee_data_migration_script_' => false, 'ee_data_migrations' => true, 'ee_dms_map' => false, 'ee_notices' => true, 'lang_file_check_' => false, 'ee_maintenance_mode' => true, 'ee_ueip_optin' => true, 'ee_ueip_has_notified' => true, 'ee_plugin_activation_errors' => true, 'ee_id_mapping_from' => false, 'espresso_persistent_admin_notices' => true, 'ee_encryption_key' => true, 'pue_force_upgrade_' => false, 'pue_json_error_' => false, 'pue_install_key_' => false, 'pue_verification_error_' => false, 'pu_dismissed_upgrade_' => false, 'external_updates-' => false, 'ee_extra_data' => true, 'ee_ssn_' => false, 'ee_rss_' => false, 'ee_rte_n_tx_' => false, 'ee_pers_admin_notices' => true, 'ee_job_parameters_' => false, 'ee_upload_directories_incomplete' => true); if (is_main_site()) { $wp_options_to_delete['ee_network_config'] = true; } $undeleted_options = array(); foreach ($wp_options_to_delete as $option_name => $no_wildcard) { if ($no_wildcard) { if (!delete_option($option_name)) { $undeleted_options[] = $option_name; } } else { $option_names_to_delete_from_wildcard = $wpdb->get_col("SELECT option_name FROM {$wpdb->options} WHERE option_name LIKE '%{$option_name}%'"); foreach ($option_names_to_delete_from_wildcard as $option_name_from_wildcard) { if (!delete_option($option_name_from_wildcard)) { $undeleted_options[] = $option_name_from_wildcard; } } } } //also, let's make sure the "ee_config_option_names" wp option stays out by removing the action that adds it remove_action('shutdown', array(EE_Config::instance(), 'shutdown'), 10); if ($remove_all && ($espresso_db_update = get_option('espresso_db_update'))) { $db_update_sans_ee4 = array(); foreach ($espresso_db_update as $version => $times_activated) { if ($version[0] == '3') { //if its NON EE4 $db_update_sans_ee4[$version] = $times_activated; } } update_option('espresso_db_update', $db_update_sans_ee4); } $errors = ''; if (!empty($undeleted_tables)) { $errors .= sprintf(__('The following tables could not be deleted: %s%s', 'event_espresso'), '<br/>', implode(',<br/>', $undeleted_tables)); } if (!empty($undeleted_options)) { $errors .= !empty($undeleted_tables) ? '<br/>' : ''; $errors .= sprintf(__('The following wp-options could not be deleted: %s%s', 'event_espresso'), '<br/>', implode(',<br/>', $undeleted_options)); } if ($errors != '') { EE_Error::add_attention($errors, __FILE__, __FUNCTION__, __LINE__); } }
/** * plugin_uninstall * * @access public * @static * @return void */ public static function delete_all_espresso_tables_and_data($remove_all = TRUE) { // FALSE global $wpdb; $undeleted_tables = array(); // load registry foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) { if (method_exists($model_name, 'instance')) { $model_obj = call_user_func(array($model_name, 'instance')); if ($model_obj instanceof EEM_Base) { foreach ($model_obj->get_tables() as $table) { if (strpos($table->get_table_name(), 'esp_')) { switch (EEH_Activation::delete_unused_db_table($table->get_table_name())) { case FALSE: $undeleted_tables[] = $table->get_table_name(); break; case 0: // echo '<h4 style="color:red;">the table : ' . $table->get_table_name() . ' was not deleted <br /></h4>'; break; default: // echo '<h4>the table : ' . $table->get_table_name() . ' was deleted successully <br /></h4>'; } } } } } } $wp_options_to_delete = array('ee_no_ticket_prices' => TRUE, 'ee_active_messengers' => TRUE, 'ee_flush_rewrite_rules' => TRUE, 'ee_config' => TRUE, 'ee_data_migration_current_db_state' => TRUE, 'ee_data_migration_mapping_' => FALSE, 'ee_data_migration_script_' => FALSE, 'ee_data_migrations' => TRUE, 'ee_notices' => TRUE, 'lang_file_check_' => FALSE, 'ee_maintenance_mode' => TRUE, 'ee_ueip_optin' => TRUE, 'ee_ueip_has_notified' => TRUE, 'ee_plugin_activation_errors' => TRUE, 'ee_id_mapping_from' => FALSE, 'espresso_persistent_admin_notices' => TRUE, 'ee_encryption_key' => TRUE, 'pue_force_upgrade_' => FALSE, 'pue_json_error_' => FALSE, 'pue_install_key_' => FALSE, 'pue_verification_error_' => FALSE, 'pu_dismissed_upgrade_' => FALSE, 'external_updates-' => FALSE, 'ee_extra_data' => TRUE, 'ee_ssn_' => FALSE, 'ee_rss_' => FALSE, 'ee_rte_n_tx_' => FALSE); $undeleted_options = array(); foreach ($wp_options_to_delete as $option_name => $no_wildcard) { $option_name = $no_wildcard ? "= '{$option_name}'" : "LIKE '%{$option_name}%'"; if ($option_id = $wpdb->query("SELECT option_id FROM {$wpdb->options} WHERE option_name {$option_name}")) { switch ($wpdb->query("DELETE FROM {$wpdb->options} WHERE option_name {$option_name}")) { case FALSE: $undeleted_options[] = $option_name; break; case 0: // echo '<h4 style="color:red;">the option : ' . $option_name . ' was not deleted <br /></h4>'; break; default: // echo '<h4>the option : ' . $option_name . ' was deleted successully <br /></h4>'; } } } if ($remove_all && ($espresso_db_update = get_option('espresso_db_update'))) { $db_update_sans_ee4 = array(); foreach ($espresso_db_update as $version => $times_activated) { if ($version[0] == '3') { //if its NON EE4 $db_update_sans_ee4[$version] = $times_activated; } } update_option('espresso_db_update', $db_update_sans_ee4); } $errors = ''; if (!empty($undeleted_tables)) { $errors .= sprintf(__('The following tables could not be deleted: %s%s', 'event_espresso'), '<br/>', implode(',<br/>', $undeleted_tables)); } if (!empty($undeleted_options)) { $errors .= !empty($undeleted_tables) ? '<br/>' : ''; $errors .= sprintf(__('The following wp-options could not be deleted: %s%s', 'event_espresso'), '<br/>', implode(',<br/>', $undeleted_options)); } if ($errors != '') { echo $errors; } }