输出所有的设置项目单元
描述
打印出添加到特定设置页面的所有设置部分。
用法
<?php do_settings_sections( $page ); ?>
参数
(string)(必填)要输出其设置部分的页面的辅助信息域名称。
这应该与 add_settings_section() 中使用的页面名称匹配。
注意
这将输出包装在 h3 标签中的部分标题和包装在表中的设置字段。
源文件
do_settings_sections() 函数的代码位于 wp-admin/includes/template.php
.
/**
* Prints out all settings sections added to a particular settings page
*
* Part of the Settings API. Use this in a settings page callback function
* to output all the sections and fields that were added to that $page with
* add_settings_section() and add_settings_field()
*
* @global $wp_settings_sections Storage array of all settings sections added to admin pages
* @global $wp_settings_fields Storage array of settings fields and info about their pages/sections
* @since 2.7.0
*
* @param string $page The slug name of the page whos settings sections you want to output
*/
function do_settings_sections( $page ) {
global $wp_settings_sections, $wp_settings_fields;
if ( ! isset( $wp_settings_sections[$page] ) )
return;
foreach ( (array) $wp_settings_sections[$page] as $section ) {
if ( $section[‘title’] )
echo “<h3>{$section[‘title’]}</h3>
“;
if ( $section[‘callback’] )
call_user_func( $section[‘callback’], $section );
if ( ! isset( $wp_settings_fields ) || !isset( $wp_settings_fields[$page] ) || !isset( $wp_settings_fields[$page][$section[‘id’]] ) )
continue;
echo ‘<table class=”form-table”>’;
do_settings_fields( $page, $section[‘id’] );
echo ‘</table>’;
}
}
相关
Settings API:
register_setting(),
unregister_setting(),
add_settings_field(),
add_settings_section(),
add_settings_error(),
get_settings_errors(),
settings_errors()