卸載鉤子不能正常工作,因爲當我卸載插件時,表格不會被丟棄。請幫我解決一下這個。以下是我正在使用的代碼。請告訴我我錯過了什麼。Wordpress插件卸載不工作
register_uninstall_hook(__FILE__, 'plugin_db_uninstall');
function plugin_db_uninstall() {
global $wpdb;
$table_name = $wpdb->prefix."user_master";
$wpdb->query("DROP TABLE IF EXISTS $table_name");
$table_name = $wpdb->prefix."candidate_master";
$wpdb->query("DROP TABLE IF EXISTS $table_name");
}
全碼
define('TXTFOLDER', plugins_url()."/candidate_section/txtfiles");
function candidate_install() {
if (!file_exists(TXTFOLDER)) {
mkdir(TXTFOLDER, 0777);
}
}
function candidate_section_create_table()
{
global $wpdb;
$sql =
"CREATE TABLE IF NOT EXISTS `".$wpdb->prefix."user_master`
(
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`name` varchar(255) NOT NULL,
`email` varchar(255) NOT,NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;";
dbDelta($sql);
$sql1 =
"CREATE TABLE IF NOT EXISTS `".$wpdb->prefix."candidate_master`
(
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`user_id` bigint(20) NOT NULL,
`position` varchar(255) NOT NULL,
`status` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;";
dbDelta($sql1);
}
function plugin_db_uninstall() {
global $wpdb;
$table_name = $wpdb->prefix."user_master";
$wpdb->query("DROP TABLE IF EXISTS $table_name");
$table_name = $wpdb->prefix."candidate_master";
$wpdb->query("DROP TABLE IF EXISTS $table_name");
}
if (is_admin()) {
add_action('admin_menu', 'candidate_menu');
register_activation_hook(__FILE__, 'candidate_install');
register_activation_hook(__FILE__, 'candidate_section_create_table');
register_uninstall_hook(__FILE__, 'plugin_db_uninstall');
}