do_settings_sections

函数
do_settings_sections ( $page )
参数
  • (string) $page The slug name of the page whose settings sections you want to output.
    Required:
定义位置
相关方法
add_settings_sectiondo_settings_fieldsdoing_actionsettings_errorsdo_accordion_sections
引入
2.7.0
弃用
-

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

打印出添加到特定设置页面的所有设置部分。

设置API的一部分。在设置页面的回调函数中使用这个函数,可以输出用add_settings_section()和add_settings_field()添加到该$page的所有部分和字段。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
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['before_section'] ) {
if ( '' !== $section['section_class'] ) {
echo wp_kses_post( sprintf( $section['before_section'], esc_attr( $section['section_class'] ) ) );
} else {
echo wp_kses_post( $section['before_section'] );
}
}
if ( $section['title'] ) {
echo "<h2>{$section['title']}</h2>n";
}
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" role="presentation">';
do_settings_fields( $page, $section['id'] );
echo '</table>';
if ( '' !== $section['after_section'] ) {
echo wp_kses_post( $section['after_section'] );
}
}
}
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['before_section'] ) { if ( '' !== $section['section_class'] ) { echo wp_kses_post( sprintf( $section['before_section'], esc_attr( $section['section_class'] ) ) ); } else { echo wp_kses_post( $section['before_section'] ); } } if ( $section['title'] ) { echo "<h2>{$section['title']}</h2>n"; } 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" role="presentation">'; do_settings_fields( $page, $section['id'] ); echo '</table>'; if ( '' !== $section['after_section'] ) { echo wp_kses_post( $section['after_section'] ); } } }
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['before_section'] ) {
			if ( '' !== $section['section_class'] ) {
				echo wp_kses_post( sprintf( $section['before_section'], esc_attr( $section['section_class'] ) ) );
			} else {
				echo wp_kses_post( $section['before_section'] );
			}
		}

		if ( $section['title'] ) {
			echo "<h2>{$section['title']}</h2>n";
		}

		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" role="presentation">';
		do_settings_fields( $page, $section['id'] );
		echo '</table>';

		if ( '' !== $section['after_section'] ) {
			echo wp_kses_post( $section['after_section'] );
		}
	}
}

常见问题

FAQs
查看更多 >