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
檢視更多 >