$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>theme development - Unable to delete option|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

theme development - Unable to delete option

matteradmin9PV0评论

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')

Share Improve this question edited Dec 5, 2018 at 16:04 Krzysiek Dróżdż 25.6k9 gold badges53 silver badges74 bronze badges asked Dec 5, 2018 at 16:01 user145078user145078
Add a comment  | 

1 Answer 1

Reset to default 0

You'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' );

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far