1

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

1 回答 1

2

问题是您拼错了__FILE__常量的名称。只需替换_FILE___FILE__(注意:两个下划线),它应该可以正常工作。

于 2012-08-17T20:27:51.903 回答