Arrays WordPress插件设置类中的动态数组选项
对于我的一个插件,我需要在插件选项中添加一个multiselect,但是multiselect中的选项是动态的(从给定站点的用户角色自动生成) 我通常会补充:Arrays WordPress插件设置类中的动态数组选项,arrays,wordpress,api,plugins,multi-select,Arrays,Wordpress,Api,Plugins,Multi Select,对于我的一个插件,我需要在插件选项中添加一个multiselect,但是multiselect中的选项是动态的(从给定站点的用户角色自动生成) 我通常会补充: 'choices' => array( 'op1' => 'Option 1', 'op2' => 'Option 2', ), 但是我需要动态地生成它们,就像我在选择框中所做的那样。我的现场案例如下所示: case 'manageraccess': global
'choices' => array(
'op1' => 'Option 1',
'op2' => 'Option 2',
),
但是我需要动态地生成它们,就像我在选择框中所做的那样。我的现场案例如下所示:
case 'manageraccess':
global $wp_roles;
$all_roles = $wp_roles->roles;
$editable_roles = apply_filters('editable_roles', $all_roles);
echo '<select multiple="multiple" class="select chozed-select' . $field_class . '" name="myplugin_options[' . $id . '][]" data-placeholder=" ">';
foreach($editable_roles as $role=>$theroles){
echo '<option value="' . esc_attr($role) . '" '.selected($options[$id], $role, false) . '>'.$wp_roles->role_names[$role].'</option>';
}
echo '</select>' . $helplink;
if ($desc != '')
echo '<br /><div class="ssfa-description">' . $desc . '</div>';
if ($submit != null)
echo '<br /><br /><br />'.$submit;
break;
案例“manageraccess”:
全球$wp_角色;
$all_roles=$wp_roles->roles;
$editable_roles=应用_过滤器($editable_roles',$all_roles);
回声';
foreach($role=>$theroles的可编辑角色){
回显'.$wp_角色->角色名称[$role].';
}
回显“”$帮助链接;
如果($desc!='')
回显“
”$描述‘’;
如果($submit!=null)
回显“
”。$submit;
打破
我想出来了
public function get_settings(){
global $wp_roles;
$this->settings['managertest'] = array(
'section' => 'manager',
'title' => __('Manager Mode Access'),
'desc' => __(''),
'type' => 'multi_select',
'std' => '',
'dflt' => '',
'choices' => $wp_roles->role_names,
'helplink'=> 'yes',
'submit' => 'yes'
);
public function get_settings(){
global $wp_roles;
$this->settings['managertest'] = array(
'section' => 'manager',
'title' => __('Manager Mode Access'),
'desc' => __(''),
'type' => 'multi_select',
'std' => '',
'dflt' => '',
'choices' => $wp_roles->role_names,
'helplink'=> 'yes',
'submit' => 'yes'
);