WordPress后台系统的开发遵循着一定的规范。这里整理一下设置的部分的代码开发。后台设置部分:
function my_admin_init(){
register_setting('my_setting_group','my-setting');
add_settings_section('part1','尺寸颜色设置部分','my_callback','general');
add_settings_field('field1','尺寸','field_1_callback','general','part1');
add_settings_field('field2','颜色','field_2_callback','general','part1');
}
add_action('admin_init','my_admin_init');
function my_callback(){
settings_fields('my_setting_group');
}
function field_1_callback(){
$setting = get_option('my-setting');
$size = esc_attr($setting['my-size']);
echo "<input name='my-setting[my-size]' type='text' value='$size' />";
}
function field_2_callback(){
$setting = get_option('my-setting');
$color = esc_attr($setting['my-color']);
echo "<input name='my-setting[my-color]' type='text' value='$color' />";
}