Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Create custom database table on WordPress plugin activation
register_activation_hook( __FILE__, 'endo_create_custom_table' );
function endo_create_custom_table() {
global $wpdb;
$table_name = $wpdb->prefix . "custom_table";
$sql = "CREATE TABLE $table_name(
id mediumint(9) NOT NULL AUTO_INCREMENT,
entry_id VARCHAR(50) NOT NULL,
date datetime,
email VARCHAR(50) CHARACTER SET utf8,
param1 VARCHAR(50) CHARACTER SET utf8,
param2 mediumint(1) DEFAULT 0,
UNIQUE KEY id(id)
) COLLATE utf8_general_ci;";
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