我正在尝试创建自己的第一个插件,但我是新手,所以请指导我正确的方向。
此插件用于根据用户的角色设置过期后的日期。现在我陷入了保存数据的阶段。
因为我不想为输入创建新的数据库表。我使用设置api来完成这项工作,并将数据保存在wp\\U选项表中。
在我的插件设置页面中,我希望用户能够添加/编辑/删除规则。每个规则由用户定义,并有多个输入。
要添加规则,用户需要选择角色、post\\u类型、过期的\\u操作和天数限制。我想把这些输入存储在一个数组中,我该怎么做?
例如:
array(1) {
role => "" // get from the form input
post_type => "" // get from the form input
expired_action => "" // get from the form input
day_limti => "" // get from the form input
}
array(2) {
role => ""
post_type => ""
expired_action => ""
day_limti => ""
}
array(3) {
role => ""
post_type => ""
expired_action => ""
day_limti => ""
}
......etc
如何使用输入名称my html表单,以便在用户每次提交规则时将其保存在数组中?这是我在插件选项页面中的html表单,用于添加规则:
<form action="options.php" id="apext_form" method="post" name="author_limit">
<?php settings_fields(\'apext_Options\'); ?>
<table class="form-table">
<tbody>
<tr valign="top">
<td>
<label for="apext_user_role"><?php _e(\'User Role\', \'apext\') ?></label>
<select name="role" id="apext_role_id">
<option></option>
<?php global $wp_roles; if ( !isset( $wp_roles ) ) $wp_roles = new WP_Roles();
foreach ( $wp_roles->role_names as $role => $name ) { ?>
<option value="<?php echo $name; ?>"><?php echo $name; ?></option>
<?php }
?>
</select><br>
</td>
<td>
<label for="apext_post_type"><?php _e(\'Post Type\', \'apext\') ?></label>
<select name="apext_pt" id="apext_pt_id">
<?php $post_types=get_post_types(\'\',\'names\');
foreach ($post_types as $post_type ) {
?>
<option value="<?php echo $post_type;?>"><?php echo $post_type;?></option>
<?php }
?>
</select><br/>
</td>
<td><label for="Expired Action"><?php _e(\'Expired Action\'); ?></label>
<select name="remove_to" id="re_to"><option value =\'\'></option>
<option value="pending">pending</option>
<option value="draft">draft</option>
<option value="trash">trash</option>
<option value="delete">delete</option>
</td>
<td>
<label for="apext_post_limit"><?php _e(\'Days Limit\', \'apext\') ?></label>
<input type="text" id="apext_lim" name="apext_lim" id="lim" size="4" value="<?php echo get_option(\'apext_lim\');?>"/><br>
</td>
<td><input class="button-primary" type="submit" name="Submit" value="<?php _e("Submit Rule", \'apext\') ?>" /></td>
</tr>
</tbody>
</table>
</form>
我知道表单不工作,因为它没有来自register\\u设置的引用名称。它只是帮助你理解我在做什么。同样,我的问题是:如何将这些输入值保存在数组中?