【发布时间】:2018-08-29 08:10:23
【问题描述】:
我对 wordpress 插件开发相对较新,并且我已经阅读了 wordpress 代码,但在卸载功能的最佳实践和简单示例之外,当用户实际卸载时,我对插件可以做的事情并没有太多了解它。
我希望实现的是,当用户卸载我的插件时,会出现一个弹出窗口,询问他们是否只想删除插件文件或插件文件以及插件上传到他们网站的所有内容。对于更多上下文,我的插件的主要功能是将存储在单独服务器上的数据作为帖子迁移到用户的 wordpress 实例中,如果用户选择该选项,我希望删除这些帖子。
以下是我当前的卸载设置,当我在 wordpress 中单击卸载时,wordpress 会卸载我的插件(从其目录中删除插件文件夹和文件),但在此过程中未显示弹出窗口。我最初认为这是一个样式问题,但弹出文件中的 HTML 没有被加载。我还检查了文件路径变量,它是正确的路径。所以我不确定是什么阻止了弹出窗口的显示并允许用户选择是否应将内容与插件一起删除。
非常感谢您对此事的任何帮助或见解!
卸载.php
<?php
//checks to make sure Wordpress is the one requesting the uninstall
if (!defined('WP_UNINSTALL_PLUGIN')) {
die;
}
$my_plugin_file_path = trailingslashit(plugin_dir_path(__FILE__));
include $my_plugin_file_path . 'templates/my-plugin-uninstall-popup.php';
my-plugin-uninstall-popup.php
<!-- styling for popup -->
<!-- end of styling for popup -->
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h2 class="modal-title" id="myModalLabel">Uninstall popup</h2>
</div>
<div class="modal-body">
<form action="<?php echo esc_url( $my_plugin_file_path . 'my-plugin-uninstall-executor.php' ); ?>" method="post">
<label>Do you want to remove the content that this plugin has uploaded?</label>
<input id="delete-content-yes" name="delete-content" value="YES" type="radio" />Yes
<input id="delete-content-no" name="delete-content" value="NO" type="radio" />No
<input type="submit" name="submit" value="Submit" />
</form>
</div>
</div>
</div>
my-plugin-uninstall-executor.php
<?php
if (isset($_POST['delete-content']) && $_POST['delete-content'] === 'YES')
//delete content from user's wordpress db
【问题讨论】: