add this code in your plugin function :
1 2 3 4 5 6 |
function activate_myplugin() { require_once plugin_dir_path( __FILE__ ) . 'includes/activator.php'; myActivator::activate(); } register_activation_hook( __FILE__, 'activate_myplugin' ); |
add this code to “includes/activator.php”
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
<?php class myActivator { public static function activate() { require_once( ABSPATH . '/wp-admin/includes/upgrade.php' ); global $wpdb; $db_table_name = $wpdb->prefix . 'your_table_name'; if( $wpdb->get_var( "SHOW TABLES LIKE '$db_table_name'" ) != $db_table_name ) { if ( ! empty( $wpdb->charset ) ) $charset_collate = "DEFAULT CHARACTER SET $wpdb->charset"; if ( ! empty( $wpdb->collate ) ) $charset_collate .= " COLLATE $wpdb->collate"; $sql = "CREATE TABLE " . $db_table_name . " ( `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT, `date_modified` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', `marketplace` varchar(30) NOT NULL DEFAULT '', `sku` varchar(20) NOT NULL DEFAULT '', `description` longtext NULL, `price` double NULL PRIMARY KEY (`id`) ) $charset_collate;"; dbDelta( $sql ); } } } |
You can edit query for table structur like you want. thanks