do_settings_fields

函数
do_settings_fields ( $page, $section )
参数
  • (string) $page Slug title of the admin page whose settings fields you want to show.
    Required:
  • (string) $section Slug title of the settings section whose fields you want to show.
    Required:
定义位置
相关方法
settings_fieldsadd_settings_fielddo_settings_sectionsadd_settings_errorsettings_errors
引入
2.7.0
弃用
-

do_settings_fields: 这是一个WordPress的函数,用于输出一组设置字段的HTML: 这个函数通常用于在WordPress管理中创建自定义设置页面。

打印出特定设置部分的设置字段。

设置API的一部分。在设置页面中使用它来输出一个特定的部分。通常应该由do_settings_sections()调用,而不是直接调用。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
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>';
}
}
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>'; } }
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>';
	}
}

常见问题

FAQs
查看更多 >