Trouble with WordPress Settings API: Form Submits When Fields Called Directly, Fails When Using Callbacks

Thank you for the responses Tom! You got me on track, I should have checked the rendered html earlier. Here’s the answer.

The rendered html was showing hidden inputs, for clarity, I’ll just repeat my previous form with the hidden inputs that were being rendered:

<form method="post" action="<?php echo admin_url('admin-post.php'); ?>">
<label>This form wont work</label>
<input type="hidden" name="action" value="snap_save_settings">

//heres the hidden input that do_settings will always render
<input type="hidden" name="action" value="update">

                <?php
                settings_fields('snap_settings_group');
                do_settings_sections('snap-main-settings');
                submit_button();
                ?>
            </form>

The two issues here:

  1. The do_settings is already rendering an action that is hidden, I was adding additional action that wasnt being executed.
  2. do_settings will only execute the “update” action which wont work with admin-post.php, the update action is intended to be used with options.php.

I solved the problem by removing this line:

<input type="hidden" name="action" value="snap_save_settings">

Then posting to options.php rather than admin-post.php

If, like my case, you need to run a custom function (snap_save_settings), then you’ll need to either hook into the updated-options hook or simply don’t use do_settings.

casinojojobetpulibet girişOnwin Güncel Giriştürkçe altyazılı pornocanlı bahis casinocanlı bahis casino siteleriOnwin Güncel Girişholiganbetholiganbet girişholiganbet güncel giriş