admin管理员组文章数量:1130349
I am able to delete the option with form action admin-post.php but it gives me a blank page after clicking the button
<form action="<?php echo admin_url('admin-post.php'); ?>" method="post">
<input type="hidden" name="action" value="my_media_update">
<input type="submit" value="Update Media Titles and ALT Text">
</form>
public function kh_update_media_seo() {
delete_option('myoption');
}
add_action( 'admin_post_my_media_update', 'kh_update_media_seo' );
if I change the action ="admin_url('admin.php?page=mycustomoptionspage');" it redirects to my original page but does not delete the option -> delete_option('myoption')
I am able to delete the option with form action admin-post.php but it gives me a blank page after clicking the button
<form action="<?php echo admin_url('admin-post.php'); ?>" method="post">
<input type="hidden" name="action" value="my_media_update">
<input type="submit" value="Update Media Titles and ALT Text">
</form>
public function kh_update_media_seo() {
delete_option('myoption');
}
add_action( 'admin_post_my_media_update', 'kh_update_media_seo' );
if I change the action ="admin_url('admin.php?page=mycustomoptionspage');" it redirects to my original page but does not delete the option -> delete_option('myoption')
1 Answer
Reset to default 0You're almost there... If you send the request to admin-post.php, then only your callback will print the response. And since your callback doesn't print anything, then you're getting blank screen.
Most of the time what you want to do is to perform a redirect inside such callback:
public function kh_update_media_seo() {
delete_option('myoption');
wp_redirect( admin_url('admin.php?page=mycustomoptionspage') );
exit;
}
add_action( 'admin_post_my_media_update', 'kh_update_media_seo' );
I am able to delete the option with form action admin-post.php but it gives me a blank page after clicking the button
<form action="<?php echo admin_url('admin-post.php'); ?>" method="post">
<input type="hidden" name="action" value="my_media_update">
<input type="submit" value="Update Media Titles and ALT Text">
</form>
public function kh_update_media_seo() {
delete_option('myoption');
}
add_action( 'admin_post_my_media_update', 'kh_update_media_seo' );
if I change the action ="admin_url('admin.php?page=mycustomoptionspage');" it redirects to my original page but does not delete the option -> delete_option('myoption')
I am able to delete the option with form action admin-post.php but it gives me a blank page after clicking the button
<form action="<?php echo admin_url('admin-post.php'); ?>" method="post">
<input type="hidden" name="action" value="my_media_update">
<input type="submit" value="Update Media Titles and ALT Text">
</form>
public function kh_update_media_seo() {
delete_option('myoption');
}
add_action( 'admin_post_my_media_update', 'kh_update_media_seo' );
if I change the action ="admin_url('admin.php?page=mycustomoptionspage');" it redirects to my original page but does not delete the option -> delete_option('myoption')
1 Answer
Reset to default 0You're almost there... If you send the request to admin-post.php, then only your callback will print the response. And since your callback doesn't print anything, then you're getting blank screen.
Most of the time what you want to do is to perform a redirect inside such callback:
public function kh_update_media_seo() {
delete_option('myoption');
wp_redirect( admin_url('admin.php?page=mycustomoptionspage') );
exit;
}
add_action( 'admin_post_my_media_update', 'kh_update_media_seo' );
本文标签: theme developmentUnable to delete option
版权声明:本文标题:theme development - Unable to delete option 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749126616a2319887.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论