Php 管理员用户可以添加/生成的Wordpress后端自定义设置字段

Php 管理员用户可以添加/生成的Wordpress后端自定义设置字段,php,wordpress,woocommerce,Php,Wordpress,Woocommerce,简而言之,我试图实现的是让用户通过后端向自定义插件添加一些管理设置字段,然后根据需要填充它们 因此,默认设置页面将有一个设置字段: 位置(使用设置位置\ id):(用户在此处输入位置并将其存储在数据库中) 我想做的是有一个按钮,上面写着“添加另一个位置”,它将自动创建一个ID为Location_id2的新设置字段。添加第三个字段将创建第三个字段,并按顺序分配ID。(理想情况下,我希望提供删除任何字段的选项,但这是第二个要求。) 这些字段将保存在数据库中,以便稍后在前端使用get\u选项('loc

简而言之,我试图实现的是让用户通过后端向自定义插件添加一些管理设置字段,然后根据需要填充它们

因此,默认设置页面将有一个设置字段:

位置(使用设置位置\ id):(用户在此处输入位置并将其存储在数据库中)

我想做的是有一个按钮,上面写着“添加另一个位置”,它将自动创建一个ID为Location_id2的新设置字段。添加第三个字段将创建第三个字段,并按顺序分配ID。(理想情况下,我希望提供删除任何字段的选项,但这是第二个要求。)

这些字段将保存在数据库中,以便稍后在前端使用
get\u选项('location\u id')
调用它们

我目前拥有的代码是针对单个设置字段的

add_action('admin_menu', 'mycustom_menu');

function mycustom_menu() {

    //create new top-level menu
    add_menu_page('mycustom Connect', 'mycustom Connect', 'administrator', __FILE__, 'mycustom_settings_page' , plugins_url('/images/icon1.png', __FILE__) );

    //call register settings function
    add_action( 'admin_init', 'register_mycustom_settings' );
}


function register_mycustom_settings() {
    //register our settings
    register_setting( 'mycustom-settings-group', 'location_id' );
}

function mycustom_settings_page() {
?>
<div class="wrap">

<h1><strong></strong>mycustom Settings</strong></strong></h1>

<form autocomplete="off" method="post" action="options.php">
    <?php settings_fields( 'mycustom-settings-group' ); ?>
    <?php do_settings_sections( 'mycustom-settings-group' ); ?>
    <table class="form-table">
        <tr valign="top">
        <th scope="row">Location ID</th>
        <td><input autocomplete="off" type="text" name="location_id" value="<?php echo esc_attr( get_option('location_id') ); ?>" /></td>
        </tr>

    </table>

    <?php submit_button(); ?>

</form>
</div>
<?php }
add_操作(“管理菜单”、“我的自定义菜单”);
函数mycustom_菜单(){
//创建新的顶级菜单
添加菜单页面(“我的自定义连接”、“我的自定义连接”、“管理员”、“文件”、“我的自定义设置页面”、插件url('/images/icon1.png',文件));
//呼叫寄存器设置功能
添加操作('admin_init','register_mycustom_settings');
}
函数寄存器\我的自定义\设置(){
//注册我们的设置
注册设置(“我的自定义设置组”、“位置设置id”);
}
函数mycustom_设置_页面(){
?>
我的自定义设置
位置ID