3 回答
TA贡献1906条经验 获得超10个赞
您需要将表添加到数组中。试试下面的代码:
function on_deactivate() {
global $wpdb;
$tables = array(
$wpdb->prefix . "smsfactory",
$wpdb->prefix . "smsfactorymessagetemplate"
);
foreach ( $tables as $table ) {
$sql = "DROP TABLE IF EXISTS $table";
$wpdb->query($sql);
}
delete_option("my_plugin_db_version");
}
register_deactivation_hook( __FILE__, 'on_deactivate' );
希望能帮到你。
TA贡献1796条经验 获得超7个赞
function delete_tbl_from_db(){
global $wpdb;
$tbl_array = [
$wpdb->prefix . "first_table",
$wpdb->prefix . "second_table",
];
foreach ($tbl_array as $tbl_name) {
$wpdb->query("DROP TABLE IF EXISTS $tbl_name");
}
}
register_uninstall_hook(__FILE__, 'delete_tbl_from_db');
Please check above code.
TA贡献1828条经验 获得超3个赞
function delete_tbl_from_db(){
global $wpdb;
$tbl_array = [
$wpdb->prefix . "smsfactory",
$wpdb->prefix . "smsfactorymessagetemplate",
];
foreach ($tbl_array as $tbl_name) {
$wpdb->query("DROP TABLE IF EXISTS $tbl_name");
}
}
register_deactivation_hook( __FILE__, 'delete_tbl_from_db' );
This is working on my site. Please check it
- 3 回答
- 0 关注
- 123 浏览
添加回答
举报