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