Php 将设置组动态添加到插件设置页面
我正在构建一个新插件,它将包含电子邮件模板的配置项。它将有一个设置页面,允许用户配置多个模板。我正在寻找帮助,以便使用按钮将设置子组动态添加到我的设置组中,该设置子组将包含配置模板所需的字段。单击按钮将重新加载页面,向设置组添加新的子组,foreach循环将循环并为每个组提供html和输入 下面是一些示例代码 我正在试图找到一种方法,使添加模板按钮添加一个子组,其中将包含设置组中模板所需的元素。这是非常粗糙的代码供参考,我对PHP非常陌生。任何援助都将是巨大的。 仅供参考,设置组已注册,并且当foreach被注释掉(尚未实现)时,页面呈现已完成Php 将设置组动态添加到插件设置页面,php,wordpress,custom-wordpress-pages,Php,Wordpress,Custom Wordpress Pages,我正在构建一个新插件,它将包含电子邮件模板的配置项。它将有一个设置页面,允许用户配置多个模板。我正在寻找帮助,以便使用按钮将设置子组动态添加到我的设置组中,该设置子组将包含配置模板所需的字段。单击按钮将重新加载页面,向设置组添加新的子组,foreach循环将循环并为每个组提供html和输入 下面是一些示例代码 我正在试图找到一种方法,使添加模板按钮添加一个子组,其中将包含设置组中模板所需的元素。这是非常粗糙的代码供参考,我对PHP非常陌生。任何援助都将是巨大的。 仅供参考,设置组已注册,并且当f
公共函数渲染($settings)
{
$templates=$settings['templates'];
?>
设置页
v
添加模板
模板Id
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
}