Adds a new section to a settings page.
Description
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.
Parameters
$id
stringrequired- Slug-name to identify the section. Used in the
'id'
attribute of tags. $title
stringrequired- Formatted title of the section. Shown as the heading for the section.
$callback
callablerequired- Function that echos out any content at the top of the section (between heading and fields).
$page
stringrequired- 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() ; $args
arrayoptional- Arguments used to create the settings section.
before_section
stringHTML content to prepend to the section’s HTML output.
Receives the section’s class name as%s
.after_section
stringHTML content to append to the section’s HTML output.section_class
stringThe class name to use for the section.
Default:
array()
Source
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;
}
Description of
$page
parameter may be misleading. It can be interpreted as if needs to be the slug name of the admin page created throughadd_submenu_page()
or one of its wrappers (such asadd_theme_page()
oradd_plugins_page()
). Instead, it only needs to be a slug-formatted name used byadd_settings_field()
anddo_settings_sections()
.Example usage
The callback function receives a single optional argument, which is an array with three elements.
Example add_settings_section with php class
You can leave
callback
andtitle
empty to simplify the process.if you want to use the $args argument, You must use do_settings_sections() .
If you used instead do_settings_fields() , the $args argument will be useless.