我正在尝试将自己的插件选项添加到Easy digital downloads插件中。示例代码如下:
http://docs.easydigitaldownloads.com/article/383-automatic-upgrades-for-wordpress-plugins
我在register\\u选项中添加了另一个寄存器设置
register_setting(\'owlish_settings_group\',\'owlish_display_notes\');
以这种形式,我可以选择
$displaynotes = get_option( \'owlish_display_notes\' );
我有两个settings\\u fields calling
<?php settings_fields(\'owlish_license\'); ?>
<?php settings_fields(\'owlish_settings_group\'); ?>
在表单中,我在提交按钮上方有一个复选框
<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>
这就是我添加到EDD示例代码中的全部内容。问题是,我只能保存其中一个选项。如果两个settings\\u字段调用都处于活动状态,则只有
owlish_display_notes
已保存。如果我对
settings_fields(\'owlish_settings_group\');
out,则会保存许可证,但不会保存注释。
这快把我逼疯了。我现在对选项中每个表格行中保存的设置都很满意,应该可以了。
我错过了什么?非常感谢
SO网友:JKLIR
看看https://tommcfarlin.com/multiple-sections-on-wordpress-options-pages/
你可以。。。
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\');
之后,您可以在第页上使用此包装器
settings_fields("owlish_settings_all");
do_settings_sections("theme-options");
祝你今天愉快。