Description
A section organizes related fields under a labeled heading in the admin panel. Sections can have an optional icon displayed next to the title, an optional note message for status or guidance, and subsections to further group related settings.
Available Options
| Parameter | Type | Description | Required | Default |
|---|---|---|---|---|
icon |
String | Bootstrap icon slug to display next to the section title (e.g., gear-fill). |
No | – |
note |
Array | Optional note for the section. Includes message (string) and class(success, warning, or error) for styling. |
No | – |
fields |
Array | An array of field definitions for this section (e.g., color, switch). |
Yes | – |
subsections |
Array | Optional array of subsections, each with its own icon, label, and fields. |
No | – |
callback |
Array | Optional array to override section with your own custom callback to break out of the framework. (Requires 3.1.0) | No | – |
Example
Example of a section with an icon, a note, fields, and a subsection:
$this->fields = array(
'general' => array(
'icon' => 'gear-fill',
'note' => array(
'message' => __('General plugin settings go here.', 'your-plugin-slug'),
'class' => 'success',
),
'fields' => array(
array(
'name' => __('Theme Color', 'your-plugin-slug'),
'type' => 'color',
'label' => __('Primary Theme Color', 'your-plugin-slug'),
'description' => __('Choose a color', 'your-plugin-slug'),
'default' => '#ff0000',
'class' => 'theme-color-input',
'help' => __('Select the primary color for the theme.', 'your-plugin-slug'),
'required' => true,
),
),
'subsections' => array(
'advanced' => array(
'icon' => 'tools',
'label' => __('Advanced', 'your-plugin-slug'),
'fields' => array(
array(
'name' => __('Enable Debug', 'your-plugin-slug'),
'type' => 'switch',
'default' => false,
'help' => __('Turn on debug mode for troubleshooting.', 'your-plugin-slug'),
),
),
),
),
),
);
This example creates a General section with a gear-fill icon and a success note. It contains a color field and a subsection Advanced with a tools icon and a switch field for debug mode.
Example Callback (Requires 3.1.0)
Example of using a callback to display your own custom content:
public static function get_fields() {
$this->fields = array(
'dashboard' => array(
'icon' => 'grid-fill',
'callback' => array(__CLASS__, 'render_dashboard_tab'),
),
);
}
public static function render_dashboard_tab($section, $section_data, $settings) {
echo "Custom tab content";
}
Usage Notes
- If
iconis not provided, the section or subsection title is displayed without an icon. - Notes can have one of three classes:
success,warning, orerror. - Each section or subsection key (e.g.,
general,advanced) must be unique. - Fields in sections or subsections use the same structure and validation as standalone fields.
- Subsections are useful for grouping advanced or optional settings without cluttering the main section.
