benecaster_settings_sections
Filters the array of field section declarations, allowing add-ons to inject configuration sections — with fields — into an existing settings page. Use to add settings to a core settings page such as Subscription or General, or to a page your add-on declared via benecaster_settings_pages.
This is a Free filter. Distinct from benecaster_settings_pages, which declares whole pages: use this filter when you only need to add a handful of fields to an existing page. The core page slugs (general, subscription, feeds, emails, templates, account, tools) are stable across Benecaster versions and are part of the public extension API.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$sections |
array |
— | Array of section declaration arrays, each with: id, page (settings page slug to attach to), label, fields (array of field objects; supported types: text, textarea, select, toggle, number, url) |
Returns:
array
Examples
Attach API key field to custom page
add_filter( 'benecaster_settings_sections', function( $sections ) {
// Attach an API key field to the custom "Integrations" settings page.
$sections[] = [
'id' => 'my-integration',
'page' => 'integrations',
'label' => 'My Service',
'fields' => [
[
'key' => '_my_service_api_key',
'label' => 'API Key',
'type' => 'text',
'meta' => true,
],
],
];
return $sections;
} );
Inject section into core Subscription page
add_filter( 'benecaster_settings_sections', function ( array $sections ): array {
$sections[] = [
'id' => 'community-integrations-subscription',
'page' => 'subscription',
'label' => __( 'Community Integrations', 'my-addon' ),
'fields' => [
[
'id' => '_my_addon_discord_server_id',
'type' => 'text',
'label' => __( 'Discord Server ID', 'my-addon' ),
'default' => '',
'meta' => true,
],
[
'id' => '_my_addon_auto_sync',
'type' => 'toggle',
'label' => __( 'Sync subscriber roles automatically', 'my-addon' ),
'default' => true,
'meta' => true,
],
],
];
return $sections;
} );
Notes
Core page slugs are stable: general, subscription, feeds, emails, templates, account, tools. Use benecaster_settings_pages to declare a whole new page; use this filter to inject sections into a page that already exists. Fires at admin page load when the settings screen initializes.
Affects
- Show Settings Pages