我正在爲客戶端製作一個插件,我正在嘗試將它安裝在他們的測試服務器上。Wordpress在本地創建插件表,不在生產
當我在本地安裝插件時,一切正常。但是,當我將它安裝在測試服務器上時,表格不會被創建。他們沒有打開調試,並且我沒有收到任何安裝錯誤的消息。我通過使用一個名爲數據庫瀏覽器的插件來驗證這些表沒有被創建。
這是創建表的代碼,其他所有內容都被刪除。有了這個代碼表格創建本地:
<?php
/*
Plugin Name: Integration Rating
*/
class IntegrationRating {
const INTEGRATIONS_TABLE_NAME = "ir_integrations";
const RATINGS_TABLE_NAME = "ir_ratings";
/**
* Called when the plugin is activated. Creates the tables for the plugin.
*/
public static function activate_plugin() {
global $wpdb;
$sqlCreateTable1 = "CREATE TABLE IF NOT EXISTS `" . $wpdb->prefix . IntegrationRating::INTEGRATIONS_TABLE_NAME . "` (
`post_id` bigint(40) unsigned NOT NULL,
`rating` int(11) NOT NULL,
`num_raters` int(11) NOT NULL,
PRIMARY KEY (`post_id`),
CONSTRAINT `post_id` FOREIGN KEY (`post_id`) REFERENCES `" . $wpdb->prefix . "posts` (`ID`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;";
$sqlCreateTable2 = "CREATE TABLE IF NOT EXISTS `" . $wpdb->prefix . IntegrationRating::RATINGS_TABLE_NAME . "` (
`post_id` bigint(40) unsigned NOT NULL,
`rater_email` varchar(255) NOT NULL DEFAULT '',
`rating` int(1) NOT NULL,
PRIMARY KEY (`post_id`,`rater_email`),
CONSTRAINT `ratings_post_id` FOREIGN KEY (`post_id`) REFERENCES `" . $wpdb->prefix . IntegrationRating::INTEGRATIONS_TABLE_NAME . "` (`post_id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;";
$wpdb->query($sqlCreateTable1);
$wpdb->query($sqlCreateTable2);
}
/**
* Called when the plugin is uninstalled. Removes the plugins tables from the database.
*/
public static function uninstall_plugin() {
global $wpdb;
$sqlDropTable1 = 'DROP TABLE IF EXISTS ' . $wpdb->prefix . IntegrationRating::INTEGRATIONS_TABLE_NAME;
$sqlDropTable2 = 'DROP TABLE IF EXISTS ' . $wpdb->prefix . IntegrationRating::RATINGS_TABLE_NAME;
// Delete ratings first because of constraints
$wpdb->query($sqlDropTable2);
$wpdb->query($sqlDropTable1);
}
}
function ir_activate_plugin() {
IntegrationRating::activate_plugin();
}
function ir_uninstall_plugin() {
IntegrationRating::uninstall_plugin();
}
register_activation_hook(__FILE__, 'ir_activate_plugin');
register_uninstall_hook(__FILE__, 'ir_uninstall_plugin');
new IntegrationRating();
我希望有人有一些線索可能是錯的。
猜測,可能是您正在使用的數據庫用戶沒有足夠的權限來更改數據庫架構。 – Aditya