当激活我正在使用的插件时,试图在wpdb中创建一个表,并出现错误“插件生成了2694个字符的意外输出…”
我一直在浏览代码,并在google上搜索了大量内容,试图找出我做错了什么,但没有成功。有人能看看我是否有什么明显的东西没看到吗?非常感谢。
Note: 插件仍然可以激活并创建菜单,但它不会在数据库中创建表。
<?php
// plugin details in comment at top
defined(\'ABSPATH\') or die(\'You should not be here…\');
function tmadm_activation() {
flush_rewrite_rules();
}
register_activation_hook( __FILE__, \'tmadm_activation\' );
function tmadm_deactivation() {
flush_rewrite_rules();
}
register_deactivation_hook( __FILE__, \'tmadm_deactivation\' );
// Insert "Students" Table to WP Database
global $tmadm_db_version;
$tmadm_db_version = \'0.1.0\';
function tmadm_install() {
global $wpdb;
global $jal_db_version;
$table_name = $wpdb->prefix . \'tmadm_students\';
$charset_collate = $wpdb->get_charset_collate();
$sql = "CREATE TABLE $table_name (
id int NOT NULL AUTO_INCREMENT,
studentnumber text NOT NULL,
dojang text NOT NULL,
firstname tinytext NOT NULL,
lastname tinytext NOT NULL,
title text NOT NULL,
gender text NOT NULL,
bbtitle text,
titleid text,
instructorcertexpire datetime DEFAULT \'0000-00-00 00:00:00\',
wwcnumber text,
wwcexpire date DEFAULT \'0000-00-00\',
firstaidnumber text,
firstaidrto text,
firstaidexpire date DEFAULT \'0000-00-00\',
cprexpire date DEFAULT \'0000-00-00\',
streetaddress NOT NULL,
suburbaddress NOT NULL,
postcodeaddress NOT NULL,
phhome text,
phwork text,
phmobile text,
email text NOT NULL,
dateofbirth date NOT NULL,
height text NOT NULL,
weight text NOT NULL,
lastupdated date NOT NULL,
beltsize text NOT NULL,
uniformsize text NOT NULL,
occupation text NOT NULL,
nationality text,
emergencycontact text NOT NULL,
relationship text NOT NULL,
phhomeemergency text NOT NULL,
phworkemergency text NOT NULL,
phmobileemergency text NOT NULL,
reference text,
referenceinternet text,
applicationdate date DEFAULT \'0000-00-00\' NOT NULL,
currentrank text NOT NULL,
rankid text NOT NULL,
ranktitle text NOT NULL,
consentpart1 text NOT NULL,
consentpart2 text NOT NULL,
consentpart3 text NOT NULL,
consentpart4 text NOT NULL,
consentpart5 text NOT NULL,
consentpart6 text NOT NULL,
consentpart7 text NOT NULL,
consentpart8 text NOT NULL,
consentpart9 text NOT NULL,
consentpart10 text NOT NULL,
consentpart11 text NOT NULL,
consentpart12 text NOT NULL,
completeconsent text NOT NULL,
Consentby text NOT NULL,
active text NOT NULL,
agreedfee text,
autobilled text,
billfrequency text,
newfee text,
PRIMARY KEY (id)
) $charset_collate;";
require_once( ABSPATH . \'wp-admin/includes/upgrade.php\' );
dbDelta( $sql );
add_option( \'tmadm_db_version\', $tmadm_db_version );
}
// Insert initial data into Students Table
function tmadm_install_data() {
global $wpdb;
$table_name = $wpdb->prefix . \'tmadm_students\';
$wpdb->insert(
$table_name,
array(
\'studentnumber\' => \'00XX1\',
//rest of this data removed as it contains personal data
)
);
}
register_activation_hook(__FILE__, \'tmadm_install\');
register_activation_hook(__FILE__, \'tmadm_install_data\');
// Plugin Settings Menu
add_action( \'admin_menu\', \'tmadm_admin_menu\' );
function tmadm_admin_menu() {
add_menu_page( \'TMA Dojang Manager\', \'Dojang Manager\', \'manage_options\', \'tmadm_settings\', \'tmadm_settings_page\', \'\', 50 );
add_submenu_page( \'tmadm_settings\', \'General Settings\', \'General Settings\', \'manage_options\', \'tmadm_settings\', \'tmadm_settings_page\' );
add_submenu_page( \'tmadm_settings\', \'Dojang Settings\', \'Dojang Management\', \'manage_options\', \'tmadm_settings\', \'tmadm_settings_page\' );
add_submenu_page( \'tmadm_settings\', \'Instructor Settings\', \'Instructor Management\', \'manage_options\', \'tmadm_settings\', \'tmadm_settings_page\' );
add_submenu_page( \'tmadm_settings\', \'Student Settings\', \'Student Management\', \'manage_options\', \'tmadm_settings\', \'tmadm_settings_page\' );
}
function tmadm_settings_page(){
include \'admin/tmadm-admin-page.php\';
}
?>