Field == $column) { $exists = TRUE; break; } } if ($exists === FALSE) { $wpdb->query("ALTER TABLE `".AH_FEED_DETAILS_TABLE."` ADD `".$column."` ".$details); } } // alter column function ah_alter_columns($database, $column, $details, $charset) { $exists = FALSE; foreach ($database as $result) { if ($result->Field == $column) { if ($result->Type == $charset) { $exists = TRUE; break; } } // end if } // end foreach if ($exists === TRUE) { $wpdb->query("ALTER TABLE `".AH_FEED_DETAILS_TABLE."` MODIFY `".$column."` ".$details); } } require_once (ABSPATH.'wp-admin/includes/upgrade.php'); dbDelta($sql); dbDelta($sql2); dbDelta($sql3); global $wpdb; // Find all columns in the feed details table and save them to memory $query = "SHOW COLUMNS FROM `".AH_FEED_DETAILS_TABLE."`"; $columns = $wpdb->get_results($query); ah_alter_columns($columns, 'form_body', 'text', 'char(250)'); ah_find_missing_tables($columns, 'form_categories_parent', ' char(250) NULL '); ah_find_missing_tables($columns, 'form_body_nofollow', ' TINYINT(1) NULL '); ah_find_missing_tables($columns, 'form_vocabulary', ' char(250) NULL '); ah_find_missing_tables($columns, 'form_staggered', ' TINYINT(1) NULL '); } // delete database tables when addon is deleted register_uninstall_hook(__FILE__, 'ah_unistall'); // recursively delete all directory contents and then the directory function ah_deleteDir($path) { return is_file($path) ? @unlink($path) : array_map(__FUNCTION__, glob($path.'/*')) == @rmdir($path); } function ah_unistall() { $sql1 = 'DROP table if exists '.AH_FEED_DETAILS_TABLE; $sql2 = 'DROP table if exists '.AH_TOTAL_FEEDS_TABLES; $sql3 = 'DROP table if exists '.AH_TRACKING_TABLE; global $wpdb; $wpdb->query($sql1); $wpdb->query($sql2); $wpdb->query($sql3); delete_option('affiliate_hoover_plugin_options'); $ah_uploads = wp_upload_dir(); ah_deleteDir($ah_uploads['basedir'].DIRECTORY_SEPARATOR.'affiliate-hoover'); }