admin管理员组文章数量:1297097
I wanted to explore more options and thats the reason for me building my first WP Plugin. I tryed to follow the coding standards, but I am struggeling hard right now. I am trying to drop my created database tables, when the uninstall hook is triggered. I am trying for 6 Hours now, using google, youtube, stackoverflow and more, but not getting any working result for me.
When I activate my plugin, I create 2 tables in my database. I want to delete these two tables, while uninstall this plugin.
My code:
// create uninstall hook
register_uninstall_hook( __FILE__ , 'uninstall_function' );
function uninstall_function() {
global $wpdb;
$table_name = $wpdb->prefix . "one_of_two_tables";
$sql_delete = "DROP TABLE IF EXISTS $table_name";
$wpdb->query( $sql_delete );
}
I also tryed this (found on stackoverflow):
function delete_plugin_database_tables(){
global $wpdb;
$tableArray = [
$wpdb->prefix . "table_name1",
$wpdb->prefix . "table_name2",
];
foreach ($tableArray as $tablename) {
$wpdb->query("DROP TABLE IF EXISTS $tablename");
}
}
This code is inside of the plugin main file, not in the uninstall.php and it is wrapped by the activation function (hook). I dont know anymore.. any help :D?
Update! So just to let you know: Its working with an uninstall.php. Not the way I wanted to do it, but its working for now. If someone does know why my uninstall hook is not working, just let me know. Otherwise I use the uninstall.php for now on.
本文标签: pluginsDROP TABLE with uninstall hook not working
版权声明:本文标题:plugins - DROP TABLE with uninstall hook not working 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741618158a2388653.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论