banner

add_settings_section()函数和add_settings_field()函数

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' />";
}

wordpress

WordPress中的后台增加子菜单到现有系统菜单里

wordpress中有许多的函数我们需要熟稔于心。需要说明的是该方式语法与add_menu_page语法完全相同,不再赘述。但仅可以增加子菜单到对应系统内置的菜单,无法为自定义菜单增加子菜单。

0
Would love your thoughts, please comment.x
()
x
Scroll to Top