Filter
uncanny-automator
uap_settings_tabs
Filters the settings tabs array, allowing modification of available tabs in the Ultimate Affiliate Pro settings panel.
add_filter( 'uap_settings_tabs', $callback, 10, 1 );
Description
Allows developers to modify or add custom tabs to the plugin's settings page. Developers can return an array of tab definitions, each containing an ID, title, and an optional array of fields. Use this hook to extend plugin functionality by creating new settings sections.
Usage
add_filter( 'uap_settings_tabs', 'your_function_name', 10, 1 );
Parameters
-
$tabs(mixed) - This parameter contains an array of settings tabs that can be filtered to add or modify tabs in the WordPress admin menu.
Return Value
The filtered value.
Examples
/**
* Add a custom settings tab for a hypothetical plugin's integration with another service.
*
* This function hooks into the 'uap_settings_tabs' filter to add a new tab
* to the settings page, allowing users to configure integration settings.
*
* @param array $tabs An array of existing settings tabs.
* @return array The modified array of settings tabs including the new custom tab.
*/
function my_plugin_add_custom_settings_tab( $tabs ) {
// Define the new custom tab.
$custom_tab_name = 'my_custom_integration';
$custom_tab_label = __( 'My Custom Integration', 'my-plugin-textdomain' );
$custom_tab_description = __( 'Configure settings for integrating with our custom service.', 'my-plugin-textdomain' );
// Define fields for the custom tab.
$custom_tab_fields = array(
'api_key' => array(
'id' => 'my_integration_api_key',
'label' => __( 'API Key', 'my-plugin-textdomain' ),
'type' => 'text',
'description' => __( 'Enter your API key for the custom service.', 'my-plugin-textdomain' ),
'placeholder' => 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',
'field_args' => array(
'required' => true,
),
),
'enable_feature' => array(
'id' => 'my_integration_enable_feature',
'label' => __( 'Enable Feature', 'my-plugin-textdomain' ),
'type' => 'checkbox',
'description' => __( 'Check this to enable the custom service integration.', 'my-plugin-textdomain' ),
'default' => 0, // 0 for unchecked, 1 for checked
),
);
// Add the new tab to the existing tabs array.
$tabs[ $custom_tab_name ] = array(
'label' => $custom_tab_label,
'description' => $custom_tab_description,
'fields' => $custom_tab_fields,
);
return $tabs;
}
add_filter( 'uap_settings_tabs', 'my_plugin_add_custom_settings_tab', 10, 1 );
Placement
This code should be placed in the functions.php file of your active theme, a custom plugin, or using a code snippets plugin.
Source Code
src/core/admin/class-admin-menu.php:208
public function plugins_loaded() {
$tabs = array();
$tabs = apply_filters( 'uap_settings_tabs', $tabs );
self::$tabs = apply_filters( 'automator_settings_tabs', $tabs );
if ( self::$tabs ) {
$tabs = json_decode( wp_json_encode( self::$tabs ), false );
foreach ( $tabs as $tab => $tab_settings ) {
if ( $tab_settings->fields ) {
foreach ( $tab_settings->fields as $field_id => $field_settings ) {
$args = isset( $field_settings->field_args ) ? $field_settings->field_args : array();
// Third-party settings_field values must start with 'uncanny_automator_' to be recognized
// by the demand-driven loader when options.php processes the form submission. Otherwise,
// WordPress will reject it with "options page is not in the allowed options list".
// See: Recipe_Manifest::is_automator_options_php_submit().
register_setting( $tab_settings->settings_field, $field_id, $args ); // phpcs:ignore PluginCheck.CodeAnalysis.SettingSanitization.register_settingMissing
}
}
}
}
}