add_settings_section()

add_settings_section()函数是Wordpress函数,将新分区添加到设置页。

add_settings_section( string $id, string $title, callable $callback, string $page )

将新分区添加到设置页。
Add a new section to a settings page.

说明(Description)

设置API的一部分。使用此选项可为管理页定义新的设置节。使用do_settings_sections()在管理页回调函数中显示设置节。使用Add_settings_field()将设置字段添加到分区中。

$callback参数应该是一个函数的名称,该函数在实际字段之前回显要显示在设置部分顶部的任何内容。如果你想的话,它什么也不能输出。


参数(Parameters)

参数类型必填说明
$id(string)必需用于标识节的段塞名称。用于标记的“id”属性中。
$title(string)必需节的格式化标题。显示为该节的标题。
$callback(callable)必需在节的顶部(在标题和字段之间)回显任何内容的函数。
$page(string)必需显示节的设置页的slug名称。内置页面包括“常规”、“阅读”、“写作”、“讨论”、“媒体”等。使用add_options_page()创建自己的页面;

返回(Return)

无返回值


源码(Source)


/**
 * Add a new section to a settings page.
 *
 * Part of the Settings API. Use this to define new settings sections for an admin page.
 * Show settings sections in your admin page callback function with do_settings_sections().
 * Add settings fields to your section with add_settings_field()
 *
 * The $callback argument should be the name of a function that echoes out any
 * content you want to show at the top of the settings section before the actual
 * fields. It can output nothing if you want.
 *
 * @since 2.7.0
 *
 * @global $wp_settings_sections Storage array of all settings sections added to admin pages
 *
 * @param string $id       Slug-name to identify the section. Used in the 'id' attribute of tags.
 * @param string $title    Formatted title of the section. Shown as the heading for the section.
 * @param string $callback Function that echos out any content at the top of the section (between heading and fields).
 * @param 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();
 */
function add_settings_section($id, $title, $callback, $page) {
	global $wp_settings_sections;
	if ( 'misc' == $page ) {
		_deprecated_argument( __FUNCTION__, '3.0', sprintf( __( 'The "%s" options group has been removed. Use another settings group.' ), 'misc' ) );
		$page = 'general';
	}
	if ( 'privacy' == $page ) {
		_deprecated_argument( __FUNCTION__, '3.5', sprintf( __( 'The "%s" options group has been removed. Use another settings group.' ), 'privacy' ) );
		$page = 'reading';
	}
	$wp_settings_sections[$page][$id] = array('id' => $id, 'title' => $title, 'callback' => $callback);
}
更新版本源码位置使用被使用
2.7.0wp-admin/includes/template.php:150902

笔记(Notes)

示例用法
php类的add_settings_部分示例

个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索