The config section defines the settings for the settings class, controlling its integration, appearance, and behavior within the WordPress admin dashboard.
This configuration is set in the $this->config array.
Available Options
| Parameter | Type | Description | Required | Default |
|---|---|---|---|---|
name |
String | The plugin name. If omitted, the name is built automatically from the plugin slug. | No | Plugin slug |
menu_name |
String | The label shown in the WordPress admin menu. If omitted, it is built automatically from the plugin slug. | No | Plugin slug |
settings_name |
String | Unique settings option name used for get_option. To prevent conflicts, include a company prefix or suffix. |
Yes | – |
page |
String | The parent page under which the settings submenu appears. Use options-general.php for the Settings menu or other pages like woocommerce to display under WooCommerce. |
No | – |
position |
Integer | The position of the submenu item. Lower numbers move the link higher in the list. | No | – |
capability |
String | The user capability required to view and edit settings (e.g., manage_options for administrators). |
No | – |
css |
String | Path to a custom CSS file for styling the admin panel. Relative to the plugin root. Comment out to use default styles. | No | Default styles |
js |
String | Path to a custom JavaScript file for the admin panel. Relative to the plugin root. Comment out to use the default script. | No | Default script |
template |
String | Theme template for the settings page. Use default or provide a custom template slug (e.g., recharge). |
No | Default theme |
support |
String | URL to a support page. Comment out to remove the support link. | No | – |
action_links |
Array | Optional. Adds action links to the plugin listing on the admin Plugins page. Each item can include url, label, style, and external. |
No | – |
meta_links |
Array | Optional. Adds meta links below the plugin description on the admin Plugins page. Each item can include url, label, style, and external. |
No | – |
sidebar |
Array | Optional. Defines a permanent sidebar in the settings panel. Supports heading, body, button_label, and button_url. |
No | – |
Note: Paths for
logo, css, and js should be relative to the plugin root directory. Ensure files are accessible and properly enqueued to avoid errors.Example
Below is an example of how to define the config array for the Reusable Admin Panel settings class.
$this->config = array(
'name' => __('Test Plugin', 'test-plugin'),
'menu_name' => __('Test Plugin', 'test-plugin'),
'settings_name' => Utils::get_settings_name(),
'page' => 'options-general.php',
'position' => 1,
'capability' => 'manage_options',
'css' => '/css/backend/settings.css',
'js' => '/js/backend/settings.js',
'template' => 'recharge',
'support' => 'https://next.polyplugins.com/support/',
'action_links' => array(
array(
'label' => __('Settings', 'test-plugin'),
'style' => 'color: orange; font-weight: 700;',
'external' => false
),
array(
'url' => 'https://next.polyplugins.com',
'label' => __('Go Pro', 'test-plugin'),
'style' => 'color: green; font-weight: 700;',
'external' => true
),
),
'meta_links' => array(
array(
'url' => 'https://github.com/users/PolyPlugins/projects/4',
'label' => __('Roadmap', 'test-plugin'),
'style' => 'color: purple; font-weight: 700;',
'external' => true
),
array(
'label' => __('Support', 'test-plugin'),
'style' => 'font-weight: 700;',
'external' => true
),
),
'sidebar' => array(
'heading' => __('Something Not Working?', 'test-plugin'),
'body' => __('Feel free to reach out!', 'test-plugin'),
'button_label' => __('Email Us', 'test-plugin'),
'button_url' => 'https://next.polyplugins.com/contact/'
),
);
This configuration sets the admin panel as a submenu under the WordPress Settings menu, positions it at the top of the submenu, restricts access to users with manage_options capability, and includes custom logo, CSS, JavaScript, and support link.
Usage Notes
- The
pageparameter determines the parent menu. Common values includeoptions-general.php(Settings),edit.php(Posts), or plugin-specific pages likewoocommerce. - Lower
positionvalues prioritize the submenu item higher in the list. If omitted, WordPress assigns a default position. - Use standard WordPress capabilities for
capability(e.g.,manage_options,edit_posts) to control access. - Custom
cssandjsfiles must be placed in the correct plugin directory and referenced with a leading slash (e.g.,/css/style.css). - The
supportURL should point to a valid external or internal support page. Always usehttps://for security. action_linksandmeta_linksallow you to add quick-access links in the Plugins admin screen.sidebaris useful for persistent contact or promotional content within the settings page.
