我对WordPress和php完全陌生。我的Wordpress插件中有一个自定义表,我想在停用插件时删除自定义表(卸载时为NO)。 这很容易实现,但在删除表格之前,我想要求确认。
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 );
}
有任何帮助吗?感谢
答案 0 :(得分:1)
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()
}
}
});
});
我在我的情况下使用了