First, I know this question has been asked countless times but I feel like I have gone through every previous post and tried everything I've come across without any success, including the WordPress Codex. I've put 12+ hours into trying to create custom DB tables in my Wordpress database and nothing has worked. The plugin claims to be activated but the tables never appear in PhpMyAdmin.
I've considered just changing course and using custom post types but my entire site is based around a database and I want to do everything possible to ensure solid performance. I've been trying to avoid using custom post types because I don't really want every query to have to search through all of the other stuff that is already in the default WordPress tables.
I'm including the code of what I'm actually trying to do, just for the big picture, but I've even attempted to just create a super simple generic table with only 3 fields and still got nowhere.
With debugging set to true, the notice I'm seeing is a Notice about the use of an undefined constant, which is the function name that I use in the register_activation_hook at the end of the code.
I so appreciate any help on this!
<?php
/*
Plugin Name: Kati’s Custom School Table
Description: This plugin will create a custom table to store user school based data in a more specialized way.
Author: KatiKati
Version: 1.0
*/
function customtables_activate()
{
global $wpdb;
$table_name = $wpdb->prefix . 'school';
$sql = "CREATE TABLE $table_name (
fk_ggid int(6) NOT NULL,
/* is_in fields contain the current school enrollment information of the child account
*/
is_in_school VARCHAR(100) NULL,
is_in_teacher VARCHAR(100) NULL,
is_in_kinder TINYINT(1) default 0,
is_in_grade1 TINYINT(1) default 0,
is_in_grade2 TINYINT(1) default 0,
is_in_grade3 TINYINT(1) default 0,
is_in_grade4 TINYINT(1) default 0,
is_in_grade5 TINYINT(1) default 0,
is_in_grade6 TINYINT(1) default 0,
is_in_grade7 TINYINT(1) default 0,
is_in_grade8 TINYINT(1) default 0,
is_in_grade9 TINYINT(1) default 0,
is_in_grade10 TINYINT(1) default 0,
is_in_grade11 TINYINT(1) default 0,
is_in_grade12 TINYINT(1) default 0,
PRIMARY KEY (fk_ggid)
);";
require_once(ABSPATH . ‘wp-admin/includes/upgrade.php’);
dbDelta($sql);
}
register_activation_hook(__FILE__, ‘customtables_activate’);