run(); } function cb(){ echo "welcome to first metabox showcase"; } function myplugin_update_db_check() { global $kz_db_version, $wpdb; $table_name = TABLE_NAME; $current_version = get_site_option( 'kz_db_version' ); //update_site_option('kz_db_version', '1.0.4'); exit; // var_dump($table_name); exit; if ( get_site_option( 'kz_db_version' ) != $kz_db_version ) { Custom_Widget_Area_Activator::activate(); if(!!$current_version && $current_version < '1.1.0'){ $row = $wpdb->get_results( "SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE table_name = '$table_name' AND column_name = 'cwa_type'" ); if(empty($row)){ $x = $wpdb->query("ALTER TABLE $table_name ADD cwa_type varchar (10) "); $updaterow = $wpdb->get_results( "SELECT id FROM $table_name"); foreach ($updaterow as $data) { # code... $up = $wpdb->update($table_name, array('cwa_type'=> 'widget'), array('id'=>$data->id)); } } } //new updates if(!!$current_version && $current_version < '1.2.5'){ $row = $wpdb->get_results( "SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE table_name = '$table_name' AND column_name = 'cwa_type'" ); if(empty($row)){ $x = $wpdb->query("ALTER TABLE $table_name MODIFY COLUMN cwa_widget_wrapper text, MODIFY COLUMN cwa_widget_header_wrapper text "); } } } run_plugin_name(); } add_action( 'plugins_loaded', 'myplugin_update_db_check' );