I based this code from the codex on the docs. I placed it in my main plugin file but it's not creating the database table. Have I missed something?
// Database setup and hooks
function core_createdb() {
global $wpdb;
$table_name = $wpdb->prefix . 'core_logs';
$wpdb_collate = $wpdb->collate;
$sql =
"CREATE TABLE {$table_name} (
timestamp DATE NOT NULL,
logid INT NOT NULL AUTO_INCREMENT,
userid INT DEFAULT NULL,
actiontype TINYTEXT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT 'undefined',
userip VARCHAR CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT 'unknown',
actioncontent VARCHAR CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
botactioncomment VARCHAR CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
botactionmade BOOLEAN DEFAULT '0',
flaglevel TINYINT DEFAULT '0',
PRIMARY KEY (logid),
KEY useridkey (userid)
)
COLLATE {$wpdb_collate}";
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
dbDelta($sql);
$success = empty($wpdb->last_error);
return $success;
}
// Create Database
add_action('init', 'core_createdb');
$sql = "CREATE TABLE
wp.
wpcore_logs` (logid
INT NOT NULL AUTO_INCREMENT ,userid
INT NULL DEFAULT NULL ,actiontype
TINYTEXT NULL DEFAULT NULL ,actioncontent
VARCHAR NOT NULL ,botactionmade
BOOLEAN NOT NULL DEFAULT FALSE ,botactioncomment
VARCHAR NOT NULL ,flaglevel
INT NOT NULL ,timestamp
TIMESTAMP NOT NULL ,userip
VARCHAR NOT NULL ,iplocation
VARCHAR NOT NULL , PRIMARY KEY (logid
))";` Error is here: pastebin.com/tKytesgF