WordPress表创建抛出错误(而不是创建表)

时间:2012-08-17 19:58:41

标签: php mysql wordpress plugins

我是WordPress的新手,并且编写了一个插件(理想情况下)允许我们的客户在一个地方更新他们现有的WP网站和我们的iPhone应用程序上的动态信息。这将需要创建两个表。我写过我认为应该创建这些表的内容,但是激活插件会在我的测试WordPress网站上引发此错误:

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.

查看数据库还会发现未创建表。我在这里和其他地方看了一些其他帖子,但似乎无法隔离我出错的地方。有什么建议吗?:

<?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);
}
?>

1 个答案:

答案 0 :(得分:2)

问题在于你拼错了__FILE__常量的名称。只需将_FILE_替换为__FILE__(注意:两个下划线),它应该可以正常工作。