Filter settings section that can be rendered on settings pages. This filter can be used to modify sections available for rendering.
Parameters
Using one parameter.
$sections array
Associative array that holds data about sections. Example of data structure for one section listed below.
array(
'title' => 'My Section Title',
'description' => 'My section description',
'settings_fields' => array(
'label' => 'My Field Label',
'type' => 'input',
'option_name' => 'my_option_name',
'option_section' => 'my_option_section',
'option_key' => 'my_option_key',
'id' => 'my_field_id',
'name' => 'my_field_name',
'help' => 'Help text',
'description' => 'Description text',
'link' => 'Link to documentation',
'required' => true | false | null,
'required' => true | false | null,
'options' => array(
'value1' => 'Label 1',
'value2' => 'Label 2',
'value3' => 'Label 3',
),
'debug' => true | false | null,
'before' => 'HTML or string to be print before input',
'after' => 'HTML or string to be print after input',
)
);
Changelog
- 1.2.1 – Introduced
Example
In below example one section is added to plugin settings sections using custom function hooked into wetory_settings_sections filter.
// Function where you can modify plugin $sections
function my_settings_section($sections)
{
$section_name = 'my-section';
$section = array(
'title' => 'My Section Title',
'description' => 'My section description',
'settings_fields' => array()
);
$field = array(
'label' => 'My Field Label',
'type' => 'text',
'option_name' => 'my_option_name',
'option_section' => 'my_option_section',
'option_key' => 'my_option_key',
'id' => 'my_field_id',
'name' => 'my_field_name',
'help' => 'How to use my field',
'description' => 'My field description',
'link' => 'https://www.my-field-docs.com',
);
$section['settings_fields'][] = $field;
$sections[$section_name] = $section;
return $sections;
}
// Hook our function to filter
add_filter('wetory_settings_sections', 'my_settings_section', 10, 1);
// Filter is then used to retrieve all sections
$plugin_sections = apply_filters('wetory_settings_sections', $plugin_sections);
// Check what sections you have available to be rendered
var_dump($plugin_sections);