有没有办法添加settings fields 动态地?
我有自己的Settings API 选项生成器就像Chip Bennet的一样Oenology Theme, 一切都很完美,但我找不到创建动态字段的方法。
下面是我如何添加选项字段的。
1。首先,我描述所有字段:
 function my_options() {
    $options = array(
         array(
            \'id\' => \'1\',
            \'title\' => \'1\', 
            \'type\' => \'foo\',
            \'description\' =>  \'bar\',
        ),
          array(
            \'id\' => \'2\',
            \'title\' => \'2\', 
            \'type\' => \'foo\',
            \'description\' =>  \'bar\',
        ),
    );
   return $options;
 }
 2。然后生成字段:
foreach(my_options() as $field) {
    add_settings_field(
       $field[\'id\'],
       $field[\'title\'],
       "something",
       "else",
       "goes",
       "there"
    );
}
 然后执行:
   <?php $opts = get_option(\'my_theme_settings_api\'); 
   var_dump($opts); ?>
 返回所有字段。
但是如果要“动态”生成一些字段,例如基于其他数组,就像这样:
function my_options() {
   // $myarray = some array of elements taken from different source, like json data from other website etc.
   $count = 0;
   foreach($myarray as $something) {
        $count++;
        $options[] = array(
            \'id\' => \'something\'. $count,
            \'title\' => $something[\'title\'],
            \'type\' => \'type\',
            \'desription\' => $something[\'description\'],
        );
   return $options;
 }
 然后我将使用
do_settings_sections() 但我无法将它们保存在管理页面上
var_dump($opts); 就像上面的例子一样,这些选项并不存在。
有什么线索吗?