Skip to content

Instantly share code, notes, and snippets.

@sabbir1991
Last active February 27, 2017 07:04
Show Gist options
  • Save sabbir1991/106eebd14a2dd05e1256 to your computer and use it in GitHub Desktop.
Save sabbir1991/106eebd14a2dd05e1256 to your computer and use it in GitHub Desktop.
Add DB Table from wp plugin
<?php
register_activation_hook( __FILE__, 'plugin_activate' );
function plugin_activate() {
global $wpdb;
$table_name = $wpdb->prefix . 'wpems_class';
$sql = "CREATE TABLE IF NOT EXISTS {$table_name} (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`class_name` varchar(255) DEFAULT NULL,
`class_numeric_name` int(11) DEFAULT NULL,
`teacher_id` int(11) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;";
require_once ABSPATH . 'wp-admin/includes/upgrade.php';
dbDelta( $sql );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment