打印出特定设置部分的设置字段
原型
do_settings_fields( string $page, string $section )
描述
Settings API的一部分。在设置页面中使用此选项可输出特定部分。通常应该由do_settings_sections()而不是直接调用。
参数
$page
(string)
(Required)
Slug管理页面的标题,你要显示的设置字段。
$section
(string)
(Required)
Slug设置部分的标题,你要显示的字段。
源文件
路径:wp-admin/includes/template.php
<?php
...
function do_settings_fields($page, $section) {
global $wp_settings_fields;
if ( ! isset( $wp_settings_fields[$page][$section] ) )
return;
foreach ( (array) $wp_settings_fields[$page][$section] as $field ) {
$class = '';
if ( ! empty( $field['args']['class'] ) ) {
$class = ' class="' . esc_attr( $field['args']['class'] ) . '"';
}
echo "<tr{$class}>";
if ( ! empty( $field['args']['label_for'] ) ) {
echo '<th scope="row"><label for="' . esc_attr( $field['args']['label_for'] ) . '">' . $field['title'] . '</label></th>';
} else {
echo '<th scope="row">' . $field['title'] . '</th>';
}
echo '<td>';
call_user_func($field['callback'], $field['args']);
echo '</td>';
echo '</tr>';
}
}
...
?>
其他
英文文档:https://developer.wordpress.org/reference/functions/do_settings_fields/