Created
September 2, 2014 19:22
-
-
Save greenhornet79/bd82492924be251dca1c to your computer and use it in GitHub Desktop.
Create custom database table on WordPress plugin activation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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