你必须打电话add_settings_section()
首先,传递一个唯一的ID并将其分配给页面(糟糕的名称)discussion
:
add_settings_section( \'ads_id\', \'Extra Settings\', \'ads_description\', \'discussion\' );
然后注册回调以保存字段…
// Register a callback
register_setting(
\'discussion\',
\'ads\',
\'trim\'
);
…然后注册一个或多个字段:
// Register the field for the "avatars" section.
add_settings_field(
\'ads\',
\'Test field\',
\'ads_show_settings\',
\'discussion\',
\'ads_id\',
array ( \'label_for\' => \'ads_id\' )
);
下面是一个非常简单的示例:
add_action( \'admin_init\', \'ads_register_setting\' );
/**
* Tell WP we use a setting - and where.
*/
function ads_register_setting()
{
add_settings_section(
\'ads_id\',
\'Extra Settings\',
\'ads_description\',
\'discussion\'
);
// Register a callback
register_setting(
\'discussion\',
\'ads\',
\'trim\'
);
// Register the field for the "avatars" section.
add_settings_field(
\'ads\',
\'Test field\',
\'ads_show_settings\',
\'discussion\',
\'ads_id\',
array ( \'label_for\' => \'ads_id\' )
);
}
/**
* Print the text before our field.
*/
function ads_description()
{
?><p class="description">This is the description</p><?php
}
/**
* Show our field.
*
* @param array $args
*/
function ads_show_settings( $args )
{
$data = esc_attr( get_option( \'ads\', \'\' ) );
printf(
\'<input type="text" name="ads" value="%1$s" id="%2$s" />\',
$data,
$args[\'label_for\']
);
}
注意第五个参数
add_settings_field()
.
结果