$tableDesign) { if ($wpdb->get_var("show tables like '$tableName'") != $tableName) { $wpdb->query($tableDesign); } } // run the upgrade function alc_upgrade(); // do we need to add/set the url trigger ? if (!get_option('alc_url_trigger')) { add_option('alc_url_trigger', ALC_DEFAULTURLTRIGGER); } } function alc_uninstall() { global $wpdb, $table_prefix; // remove data $wpdb->query("DELETE FROM {$table_prefix}alc_link"); $wpdb->query("DELETE FROM {$table_prefix}alc_address"); $wpdb->query("DELETE FROM {$table_prefix}alc_redirectlog"); // remove db tables $wpdb->query("DROP TABLE {$table_prefix}alc_link"); $wpdb->query("DROP TABLE {$table_prefix}alc_address"); $wpdb->query("DROP TABLE {$table_prefix}alc_redirectlog"); // remove options delete_option('alc_url_trigger'); delete_option('alc_db_version'); } function alc_upgrade() { global $wpdb, $table_prefix, $alc_db_version; // TODO: dont run if the plugin is inactive.. // dont try to upgrade if the tables are not installed if(!$wpdb->get_var("SHOW TABLES LIKE '{$table_prefix}alc_link'")) { return; } // get the current database version $currentDbVersion = (int)get_option('alc_db_version'); // database updates $dbChanges = array(); // version 2 change $dbChanges[2][] = "ALTER TABLE `{$table_prefix}alc_link` ADD `searchTextDelimiter` CHAR(1) NULL AFTER `searchText`;"; // do we need to upgrade the database? if ($alc_db_version > $currentDbVersion) { // run through the upgrades version by version for ($version = $currentDbVersion ; $version <= $alc_db_version ; $version++) { // is this an array ? if (is_array($dbChanges[$version])) { // iterate through the changes for each version foreach ($dbChanges[$version] as $change) { if ($change) { $wpdb->query($change); } } } } // update the database version option update_option('alc_db_version', $alc_db_version); } } ?>