我对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 );
}
有什么帮助吗?谢谢
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