我有一个插件,它将HTML片段保存在_transients中。 现在,我希望能够让用户通过单击按钮来删除所有相关的瞬变。 我已经设法创建一个按钮,发送适当的请求到options.php页面,获取请求,并执行查询,但问题是,我留在/options.php,我想重定向到我的插件页面。 以下是代码的相关部分:
function fbClearTransients(){ global $wpdb, $_wp_using_ext_object_cache; if(!empty($_POST["fb-clear-transient"]) && intval($_POST["fb-clear-transient"]) == 1) { $sql = "DELETE FROM $wpdb->options WHERE option_name LIKE '%_transient_fb_%'"; $clean = $wpdb -> query( $sql ); } } function fbClearCache() { $clear = fbClearTransients(); } add_action('admin-init', 'fbClearCache'); [...] <form action="options.php" method="post"> <input type="hidden" name="fb-clear-transient" value='1'> <?php submit_button( __('Clear cache'), 'secondary', 'fb_clear_trans_button', false ); ?> </form>所以,总结一下:查询工作,一切正常,除了我没有重定向回我的插件页面,就像使用初始保存按钮 - 保存设置的那个一样。
I have a plugin that keeps HTML snippets in _transients. Now, I want to be able to let the users delete all the related transients by clicking on a button. I've managed to create a button, send proper request to options.php page, get the request, and execute query, but the problem is that I'm left at /options.php and I want to redirect to my plugin page. Here are relevant parts of the code:
function fbClearTransients(){ global $wpdb, $_wp_using_ext_object_cache; if(!empty($_POST["fb-clear-transient"]) && intval($_POST["fb-clear-transient"]) == 1) { $sql = "DELETE FROM $wpdb->options WHERE option_name LIKE '%_transient_fb_%'"; $clean = $wpdb -> query( $sql ); } } function fbClearCache() { $clear = fbClearTransients(); } add_action('admin-init', 'fbClearCache'); [...] <form action="options.php" method="post"> <input type="hidden" name="fb-clear-transient" value='1'> <?php submit_button( __('Clear cache'), 'secondary', 'fb_clear_trans_button', false ); ?> </form>So, to sum up: query works, everything works, except that I'm not redirected back to my plugin page, as with initial Save button - the one that saves the settings.
最满意答案
鉴于我已经修改了原来的查询,将我带到了admin.php?page = myplugin,我需要以某种方式告诉系统我想在那里结束,因此简单地添加:
header('Location: admin.php?page=my-plugin');为我修好了。
Given that I've modified original query that would've take me to the admin.php?page=myplugin, I needed to somehow tell the system I want to end up there, so adding simply:
header('Location: admin.php?page=my-plugin');fixed it for me.
更多推荐
发布评论