$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'); ?>options - Two settings_fields in one form|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)

options - Two settings_fields in one form

matteradmin9PV0评论

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.

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far