Filter uncanny-automator

automator_settings_tabs

Filters the available settings tabs for the Automator plugin before they are displayed.

add_filter( 'automator_settings_tabs', $callback, 10, 1 );

Description

Filters the settings tabs array before they are displayed in the admin area. Developers can use this hook to add, remove, or modify settings tabs programmatically, allowing for custom configuration pages. The `$tabs` parameter is an array of tab objects.


Usage

add_filter( 'automator_settings_tabs', 'your_function_name', 10, 1 );

Parameters

$tabs (mixed)
This filter allows you to modify the array of settings tabs before they are processed and registered.

Return Value

The filtered value.


Examples

/**
 * Adds a new tab to the Automator settings page for a custom integration.
 *
 * This function hooks into the 'automator_settings_tabs' filter to add a new
 * section to the Uncanny Automator settings within the WordPress admin.
 *
 * @param array $tabs The existing array of setting tabs.
 * @return array The modified array of setting tabs, including the new custom tab.
 */
function my_custom_automator_settings_tab( $tabs ) {
    // Define the structure for our new settings tab.
    $custom_tab = array(
        'settings_slug' => 'my_custom_integration', // Unique slug for the tab.
        'settings_name' => __( 'My Custom Integration', 'my-text-domain' ), // User-facing tab title.
        'fields'        => array(
            'my_api_key' => array(
                'name'              => __( 'API Key', 'my-text-domain' ),
                'type'              => 'text',
                'placeholder'       => __( 'Enter your API key here', 'my-text-domain' ),
                'label'             => __( 'API Key', 'my-text-domain' ),
                'description'       => __( 'This key is required to connect to your custom service.', 'my-text-domain' ),
                'default_value'     => '',
                'field_args'        => array(), // Additional arguments for the field, if needed.
            ),
            'enable_feature' => array(
                'name'              => __( 'Enable Feature', 'my-text-domain' ),
                'type'              => 'checkbox',
                'label'             => __( 'Enable this custom feature.', 'my-text-domain' ),
                'description'       => __( 'Check this box to activate the custom integration features.', 'my-text-domain' ),
                'default_value'     => '0', // Default to unchecked (false).
                'field_args'        => array(),
            ),
        ),
    );

    // Add our custom tab to the existing tabs array.
    // The key of the array element should match the 'settings_slug'.
    $tabs['my_custom_integration'] = (object) $custom_tab; // Cast to object as the source context suggests.

    return $tabs;
}

// Hook into the 'automator_settings_tabs' filter with a priority and accepted arguments.
// Priority 10 is standard. We accept 1 argument ($tabs).
add_filter( 'automator_settings_tabs', 'my_custom_automator_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:209

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
					}
				}
			}
		}
	}


Scroll to Top