gpt4 book ai didi

php - 确认消息以在停用插件时删除自定义表

转载 作者:行者123 更新时间:2023-11-29 02:58:38 24 4
gpt4 key购买 nike

我对 WordPress 和 php 完全陌生。我的 Wordpress 插件中有一个自定义表格,我想在停用插件时删除自定义表格(卸载时否)。这很容易完成,但在删除表格之前我想请求确认。

function va_deactivation() {
.... //unregisters settings

//Asks for confirmation - Code here


//If answer is yes proceed to delete. If no, doesn't execute the following code
global $wpdb;
$pa_table = $wpdb->prefix."tableName";
$sql = 'DROP TABLE IF EXISTS '.$pa_table;
$wpdb->query( $sql );

}

有什么帮助吗?谢谢

最佳答案

jQuery(function () {
jQuery('.deactivate a').click(function (e) {
let url = jQuery(this).attr('href');
let regex = /[?&]([^=#]+)=([^&#]*)/g,
params = {},
match;
while (match = regex.exec(url)) {
params[match[1]] = match[2];
}
if(params.plugin === "{plugin_name}%2F{plugin_name}.php"){
let delete_confirm = confirm("You are going deactivate this plugin");
if (delete_confirm !== true) {
e.preventDefault()
}
}
});
});

我在我的案例中使用了这个

但最好使用 register_uninstall_hook

关于php - 确认消息以在停用插件时删除自定义表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27316284/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com