add_settings_field

函式
add_settings_field ( $id, $title, $callback, $page, $section = 'default', $args = array() )
引數
  • (string) $id Slug-name to identify the field. Used in the 'id' attribute of tags.
    Required:
  • (string) $title Formatted title of the field. Shown as the label for the field during output.
    Required:
  • (callable) $callback Function that fills the field with the desired form inputs. The function should echo its output.
    Required:
  • (string) $page The slug-name of the settings page on which to show the section (general, reading, writing, ...).
    Required:
  • (string) $section Optional. The slug-name of the section of the settings page in which to show the box. Default 'default'.
    Required:
    Default: 'default'
  • (array) $args { Optional. Extra arguments that get passed to the callback function. @type string $label_for When supplied, the setting title will be wrapped in a `<label>` element, its `for` attribute populated with this value. @type string $class CSS Class to be added to the `<tr>` element when the field is output. }
    Required:
    Default: array()
定義位置
相關方法
do_settings_fieldssettings_fieldsadd_settings_erroradd_settings_sectiondo_settings_sections
引入
2.7.0
棄用
-

add_settings_field: 這個函式用來向WordPress設定頁面新增一個新的欄位。你可以用這個函式在WordPress設定頁上新增自定義欄位和選項: 這個函式通常與add_settings_section一起使用,以分組相關的設定欄位。

在設定頁面的某個部分新增一個新的欄位。

設定API的一部分。使用它來定義一個設定欄位,它將作為設定頁面內設定部分的一部分顯示。這些欄位將使用do_settings_fields()在do_settings_sections()中顯示。

$callback引數應該是一個函式的名稱,用於撥出這個設定欄位的HTML輸入標籤。使用get_option()來檢索要顯示的現有值。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function add_settings_field( $id, $title, $callback, $page, $section = 'default', $args = array() ) {
global $wp_settings_fields;
if ( 'misc' === $page ) {
_deprecated_argument(
__FUNCTION__,
'3.0.0',
sprintf(
/* translators: %s: misc */
__( 'The "%s" options group has been removed. Use another settings group.' ),
'misc'
)
);
$page = 'general';
}
if ( 'privacy' === $page ) {
_deprecated_argument(
__FUNCTION__,
'3.5.0',
sprintf(
/* translators: %s: privacy */
__( 'The "%s" options group has been removed. Use another settings group.' ),
'privacy'
)
);
$page = 'reading';
}
$wp_settings_fields[ $page ][ $section ][ $id ] = array(
'id' => $id,
'title' => $title,
'callback' => $callback,
'args' => $args,
);
}
function add_settings_field( $id, $title, $callback, $page, $section = 'default', $args = array() ) { global $wp_settings_fields; if ( 'misc' === $page ) { _deprecated_argument( __FUNCTION__, '3.0.0', sprintf( /* translators: %s: misc */ __( 'The "%s" options group has been removed. Use another settings group.' ), 'misc' ) ); $page = 'general'; } if ( 'privacy' === $page ) { _deprecated_argument( __FUNCTION__, '3.5.0', sprintf( /* translators: %s: privacy */ __( 'The "%s" options group has been removed. Use another settings group.' ), 'privacy' ) ); $page = 'reading'; } $wp_settings_fields[ $page ][ $section ][ $id ] = array( 'id' => $id, 'title' => $title, 'callback' => $callback, 'args' => $args, ); }
function add_settings_field( $id, $title, $callback, $page, $section = 'default', $args = array() ) {
	global $wp_settings_fields;

	if ( 'misc' === $page ) {
		_deprecated_argument(
			__FUNCTION__,
			'3.0.0',
			sprintf(
				/* translators: %s: misc */
				__( 'The "%s" options group has been removed. Use another settings group.' ),
				'misc'
			)
		);
		$page = 'general';
	}

	if ( 'privacy' === $page ) {
		_deprecated_argument(
			__FUNCTION__,
			'3.5.0',
			sprintf(
				/* translators: %s: privacy */
				__( 'The "%s" options group has been removed. Use another settings group.' ),
				'privacy'
			)
		);
		$page = 'reading';
	}

	$wp_settings_fields[ $page ][ $section ][ $id ] = array(
		'id'       => $id,
		'title'    => $title,
		'callback' => $callback,
		'args'     => $args,
	);
}

常見問題

FAQs
檢視更多 >