Skip to content

Instantly share code, notes, and snippets.

@greenhornet79
Created September 2, 2014 19:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save greenhornet79/bd82492924be251dca1c to your computer and use it in GitHub Desktop.
Save greenhornet79/bd82492924be251dca1c to your computer and use it in GitHub Desktop.
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