Filter uncanny-automator

automator_settings_sections

Filters the settings sections array, allowing modification of available automator settings sections.

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

Description

Allows developers to programmatically add or modify top-level sections (tabs) in the Automator plugin's settings page. You can filter the array of sections to include custom integrations or addons as new tabs, enhancing plugin extensibility.


Usage

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

Return Value

The filtered value.


Examples

add_filter( 'automator_settings_sections', 'my_custom_automator_settings_section', 20, 1 );

/**
 * Adds a custom section to the Automator settings page.
 *
 * This function demonstrates how to hook into the 'automator_settings_sections'
 * filter to add a new top-level tab or section to the plugin's settings area.
 *
 * @param array $sections An array of existing settings sections.
 * @return array The modified array of settings sections with the new section added.
 */
function my_custom_automator_settings_section( $sections ) {
    // Define the new section details.
    $new_section = array(
        'id'    => 'my_custom_section', // Unique ID for the section.
        'title' => __( 'My Custom Settings', 'text-domain' ), // Translatable title for the tab.
        'callback' => 'my_custom_settings_page_content', // The function that will render the content for this section.
        'description' => __( 'This is a custom section for advanced configurations.', 'text-domain' ), // Optional description.
    );

    // Add the new section to the array.
    $sections[] = $new_section;

    // You could also insert it at a specific position if needed:
    // array_splice( $sections, 1, 0, array( $new_section ) );

    return $sections;
}

/**
 * Callback function to render the content for the custom settings section.
 *
 * This function will be executed when the user navigates to the "My Custom Settings" tab.
 * Replace this with your actual settings page HTML and form elements.
 */
function my_custom_settings_page_content() {
    ?>
    <div class="wrap">
        <h2><?php _e( 'My Custom Settings Content', 'text-domain' ); ?></h2>
        <p><?php _e( 'This is where you can add your custom settings fields. For example, you might add fields for API keys, integration toggles, or advanced options.', 'text-domain' ); ?></p>

        <form method="post" action="options.php">
            <?php
            // Example of adding a settings field.
            // You would typically use WordPress Settings API for robust handling.
            ?>
            <table class="form-table">
                <tr>
                    <th scope="row"><label for="my_custom_api_key"><?php _e( 'Custom API Key', 'text-domain' ); ?></label></th>
                    <td>
                        <input type="text" id="my_custom_api_key" name="my_custom_api_key" value="" class="regular-text">
                        <p class="description"><?php _e( 'Enter your unique API key here.', 'text-domain' ); ?></p>
                    </td>
                </tr>
                <?php
                // If using WordPress Settings API, you would also include:
                // settings_fields( 'your_option_group' );
                // do_settings_sections( 'your_settings_page_slug' );
                ?>
            </table>
            <p class="submit">
                <input type="submit" name="submit" id="submit" class="button button-primary" value="<?php _e( 'Save Changes', 'text-domain' ); ?>">
            </p>
        </form>
    </div>
    <?php
}

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/admin-settings/admin-settings.php:102

public function get_top_level_tabs() {
		return apply_filters( 'automator_settings_sections', array() );
	}

Internal Usage

Found in src/core/admin/admin-settings/tabs/premium-integrations.php:19:

add_filter( 'automator_settings_sections', array( $this, 'create_tab' ) );

Found in src/core/admin/admin-settings/tabs/addons.php:26:

add_filter( 'automator_settings_sections', array( $this, 'register_tab' ), 30, 1 );
Scroll to Top