WordPress函数文档add_settings_section()
添加一个设置选项单元 描述 Settings Sections are the groups of setti…
添加一个设置选项单元
描述
Settings Sections are the groups of settings you see on WordPress settings pages with a shared heading. In your plugin you can add new sections to existing settings pages rather than creating a whole new page. This makes your plugin simpler to maintain and creates less new pages for users to learn. You just tell them to change your setting on the relevant existing page.
用法
<?php add_settings_section( $id, $title, $callback, $page ); ?>
参数
$id
(string) (必填) String for use in the ‘id’ attribute of tags.
默认值: None
$title
(string) (必填) Title of the section.
默认值: None
$callback
(string) (必填) Function that fills the section with the desired content. The function should echo its output.
默认值: None
$page
(string) (必填) The menu page on which to display this section. Should match $menu_slug from Function Reference/add theme page
默认值: None
返回值
(void)
This function does not return a value.
注意
The callback function receives a single optional argument, which is an array with three elements.
Example:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
/* ———————————-
* wordpress函数 kim收集
* ———————————- */
add_settings_section(
‘eg_setting_section’,
‘Example settings section in reading’,
‘eg_setting_section_callback_function’,
‘reading’
);
function eg_setting_section_callback_function( $arg ) {
// echo section intro text here
echo ‘<p>id: ‘ . $arg[‘id’] . ‘</p>’; // id: eg_setting_section
echo ‘<p>title: ‘ . $arg[‘title’] . ‘</p>’; // title: Example settings section in reading
echo ‘<p>callback: ‘ . $arg[‘callback’] . ‘</p>’; // callback: eg_setting_section_callback_function
}
|
历史
添加于 版本: 2.7.0
源文件
add_settings_section() 函数的代码位于 wp-admin/includes/template.php
.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
/* ———————————-
* wordpress函数 kim收集
* ———————————- */
/**
* 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);
}
|
相关
Settings API:
register_setting(),
unregister_setting(),
add_settings_field(),
add_settings_section(),
add_settings_error(),
get_settings_errors(),
settings_errors()
- 原文:http://codex.wordpress.org/Function_Reference/add_settings_section
本文收集自互联网,转载请注明来源。
如有侵权,请联系 wper_net@163.com 删除。
评论功能已经关闭!