动态将设置组添加到插件设置页面

问题描述

我正在构建一个插件,其中将包含电子邮件模板的配置项。它将具有一个设置页面,以允许用户配置多个模板。我正在寻找使用按钮将设置子组动态添加到我的设置组的帮助,该组将包含配置模板所需的字段。单击按钮将重新加载页面,以将新的子组添加到设置组,并且foreach循环将循环并为每个组提供html和输入。

我在下面有一些示例代码

我正在尝试找到一种方法,使添加模板按钮添加一个子组,该子组将包含settings-group内模板所需的元素。这是非常粗糙的代码供参考,我对PHP还是很陌生。任何帮助都会很棒。 仅供参考,当注释掉foreach时,设置组已经注册并且页面呈现(尚未实现)。

public function render ( $settings )
    {
        $templates = $settings[ 'templates' ];
        ?>

        <div class="wrap">
            <h1>Setup Page</h1>
            <p class="description" >v<?PHP echo $this -> version; ?></p>
            <form action="options.PHP" method="post">
                <?PHP \settings_fields( 'settings-group' ); ?>
                <?PHP \do_settings_sections( 'settings-group' ); ?>
                <table class="form-table">
                    <button class="button button-secondary">
                        Add Template
                    </button>
                <?PHP foreach($templates as $key=>$value): ?>
                <h3></h3>
                    <tr>
                        <th scope="row">
                            <label for="template_id">Template Id</label>
                        </th>
                        <td>
                            <input type="text" name="template_id" id="template_id" size="12" value="<?PHP echo esc_attr( $templateId ); ?>">
                            <p class="description" >Input the Id of your template</p>
                        </td>
                    </tr>
                    <tr>
                        <th scope="row">
                            <label for="notification_type">Type of notification you'd like to send</label>
                        </th>
                        <td>
                            <select name="notification_type" id="notification_type" >
                                <option value="email" <?PHP if( isset( $notificationType ) && $notificationType && $notificationType == 'email' ){ echo $selected; } ?> >email</option>
                            </select>                            
                            <p class="description" >Input the type of notification you'd like to send</p>
                        </td>
                    </tr>
                <?PHP endforeach; ?>
                </table>
                <?PHP \submit_button(); ?>
            </form>
        </div>
        <?PHP
        
    }

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)