add_settings_section

函式
add_settings_section ( $id, $title, $callback, $page, $args = array() )
引數
  • (string) $id Slug-name to identify the section. Used in the 'id' attribute of tags.
    Required:
  • (string) $title Formatted title of the section. Shown as the heading for the section.
    Required:
  • (callable) $callback Function that echos out any content at the top of the section (between heading and fields).
    Required:
  • (string) $page The slug-name of the settings page on which to show the section. Built-in pages include 'general', 'reading', 'writing', 'discussion', 'media', etc. Create your own using add_options_page();
    Required:
  • (array) $args { Arguments used to create the settings section. @type string $before_section HTML content to prepend to the section's HTML output. Receives the section's class name as `%s`. Default empty. @type string $after_section HTML content to append to the section's HTML output. Default empty. @type string $section_class The class name to use for the section. Default empty. }
    Required:
    Default: array()
定義位置
相關方法
do_settings_sectionsadd_settings_erroradd_settings_fieldadd_site_optiondo_settings_fields
引入
2.7.0
棄用
-

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

為設定頁面新增一個新的部分。

設定API的一部分。使用它來為一個管理頁面定義新的設定部分。用do_settings_sections()在你的管理頁面回撥函式中顯示設定部分。用add_settings_field()向你的部分新增設定欄位。

$callback引數應該是一個函式的名字,它可以在實際欄位之前撥出你想在設定部分頂部顯示的任何內容。如果你願意,它可以什麼都不輸出。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function add_settings_section( $id, $title, $callback, $page, $args = array() ) {
global $wp_settings_sections;
$defaults = array(
'id' => $id,
'title' => $title,
'callback' => $callback,
'before_section' => '',
'after_section' => '',
'section_class' => '',
);
$section = wp_parse_args( $args, $defaults );
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_sections[ $page ][ $id ] = $section;
}
function add_settings_section( $id, $title, $callback, $page, $args = array() ) { global $wp_settings_sections; $defaults = array( 'id' => $id, 'title' => $title, 'callback' => $callback, 'before_section' => '', 'after_section' => '', 'section_class' => '', ); $section = wp_parse_args( $args, $defaults ); 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_sections[ $page ][ $id ] = $section; }
function add_settings_section( $id, $title, $callback, $page, $args = array() ) {
	global $wp_settings_sections;

	$defaults = array(
		'id'             => $id,
		'title'          => $title,
		'callback'       => $callback,
		'before_section' => '',
		'after_section'  => '',
		'section_class'  => '',
	);

	$section = wp_parse_args( $args, $defaults );

	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_sections[ $page ][ $id ] = $section;
}

常見問題

FAQs
檢視更多 >