options - Two settings_fields in one form

admin2025-06-04  2

I am trying to add my own plugin option to the Easy digital downloads plugin. The sample code is here:

I have added another register setting in the register_option

  register_setting('owlish_settings_group','owlish_display_notes');

And in the form I get the option

$displaynotes = get_option( 'owlish_display_notes' );

and I have there two settings_fields callings

<?php settings_fields('owlish_license'); ?>
<?php settings_fields('owlish_settings_group'); ?>

And in the form I have the checkbox above the submit button

  <table class="form-table">
  <tr>
    <th scope="row"><?php _e('Show notes?', 'owlish-textdomain'); ?></th>
    <td id="front-static-pages">
    <fieldset>
    <legend class="screen-reader-text"><span><?php _e('Show notes?', 'owlish-textdomain'); ?></span></legend>
    <ul>
    <li><input type="checkbox" name="owlish_display_notes" value="1" id="owlish_display_notes" <?php checked('1'==$displaynotes); ?> /><label for="show_notes"> <?php _e('show notes', 'owlish-textdomain'); ?></label></li>
    </ul>
    </fieldset>
    </td>
  </tr>
  </table> 

This is all I added to the EDD sample code. The problem is, I can only save one of those options. If I have the both settings_fields calls active, only the owlish_display_notes are saved. If I comment the settings_fields('owlish_settings_group'); out, then the license is saved, but not the notes.

This is driving me nuts. I am ok with the settings saved in each table row in the options for now, it just should work.

What am I missing here? Thanks so much

I am trying to add my own plugin option to the Easy digital downloads plugin. The sample code is here:

http://docs.easydigitaldownloads/article/383-automatic-upgrades-for-wordpress-plugins

I have added another register setting in the register_option

  register_setting('owlish_settings_group','owlish_display_notes');

And in the form I get the option

$displaynotes = get_option( 'owlish_display_notes' );

and I have there two settings_fields callings

<?php settings_fields('owlish_license'); ?>
<?php settings_fields('owlish_settings_group'); ?>

And in the form I have the checkbox above the submit button

  <table class="form-table">
  <tr>
    <th scope="row"><?php _e('Show notes?', 'owlish-textdomain'); ?></th>
    <td id="front-static-pages">
    <fieldset>
    <legend class="screen-reader-text"><span><?php _e('Show notes?', 'owlish-textdomain'); ?></span></legend>
    <ul>
    <li><input type="checkbox" name="owlish_display_notes" value="1" id="owlish_display_notes" <?php checked('1'==$displaynotes); ?> /><label for="show_notes"> <?php _e('show notes', 'owlish-textdomain'); ?></label></li>
    </ul>
    </fieldset>
    </td>
  </tr>
  </table> 

This is all I added to the EDD sample code. The problem is, I can only save one of those options. If I have the both settings_fields calls active, only the owlish_display_notes are saved. If I comment the settings_fields('owlish_settings_group'); out, then the license is saved, but not the notes.

This is driving me nuts. I am ok with the settings saved in each table row in the options for now, it just should work.

What am I missing here? Thanks so much

Share Improve this question asked Jun 23, 2015 at 11:27 OwlOwl 2314 silver badges15 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

take a look at https://tommcfarlin/multiple-sections-on-wordpress-options-pages/

You can...

add_settings_section("owlish_license", "SECTION NAME", null, "theme-options");
add_settings_section("owlish_settings_group", "SECTION NAME 2", null, "theme-options");

add_settings_field("owlish_display_notes", "Display Notes", "callback1", "theme-options", "owlish_license");
register_setting('owlish_settings_all','owlish_display_notes');

add_settings_field("owlish_display_notes2", "Display Notes 2", "callback2", "theme-options", "owlish_settings_group");
register_setting('owlish_settings_all','owlish_display_notes2');

after you can use this wrapper on page

settings_fields("owlish_settings_all");
do_settings_sections("theme-options");

Have a nice day.

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1749004175a315539.html

最新回复(0)