WordPress table creation throwing errors (and not creating tables)

I am very new to WordPress, and writing a plugin to (ideally) allow our client to update their existing WP site and the dynamic info on our iphone app all in one place. This will require the creation of two tables. I have written what I believe should be creating these tables, but activating the plugin throws this error on my test WordPress site:

The plugin generated 1 characters of unexpected output during activation. If you notice “headers already sent” messages, problems with syndication feeds or other issues, try deactivating or removing this plugin.

Read More

Looking into the database also reveals that the tables were not created. I have looked at a handful of other posts here and elsewhere, but can’t seem to isolate where I am going wrong. Any suggestions?:

<?php
// Plugin info omitted

register_activation_hook(_FILE_, 'event_manager_install');
register_deactivation_hook(_FILE_, 'event_manager_uninstall');

// Installer
function event_manager_install() {
global $wpdb;

// Builds queries for custom event and speakers tables
$event_table = $wpdb->prefix . 'events';
$eventSql = "CREATE TABLE $event_table (
  id mediumint(9) NOT NULL AUTO_INCREMENT,
  venueName VARCHAR(250) DEFAULT '' NOT NULL,
  date datetime DEFAULT '0000-00-00 00:00:00' NOT NULL,
  address text NOT NULL,
  registrationDeadlineDate datetime DEFAULT '0000-00-00 00:00:00' NOT NULL,
  UNIQUE KEY id (id)
);";

$speaker_table = $wpdb->prefix . 'speakers';
$speakerSql = "CREATE TABLE $speaker_table (
  id mediumint(9) NOT NULL AUTO_INCREMENT,
  eventID mediumint(9) NOT NULL,
  speaker text NOT NULL,
  UNIQUE KEY id (id)
);";

// Executes queries
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
dbDelta($eventSql);
dbDelta($speakerSql);
}

// Uninstaller
function event_manager_uninstall() {
global $wpdb;

// Creates queries to delete custom tables
$event_table = $wpdb->prefix . 'events';
$speaker_table  = $wpdb->prefix . 'speakers';
$eventSql = "DROP TABLE " . $event_table . ";";
$speakerSql = "DROP TABLE " . $speaker_table . ";";

// Executes deletion queries
$wpdb->query($eventSql);
$wpdb->query($speakerSql);
}
?>

Related posts

Leave a Reply

1 comment

  1. The problem is that you’ve misspelled the name of the __FILE__ constant. Just replace _FILE_ with __FILE__ (note: two underscores), and it should work just fine.