Filter uncanny-automator

automator_settings_addons_tabs

Filters the array of addon tabs displayed on the Automator settings page, allowing for modification before rendering.

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

Description

Filters the array of available tabs for the Automator add-ons settings page. Developers can use this hook to programmatically add, remove, or modify the order of add-on tabs displayed in the WordPress admin settings, allowing for custom integration or management of add-on features within the Automator interface.


Usage

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

Return Value

The filtered value.


Examples

// Example of adding a custom addon tab to the Automator settings.
// This function will be hooked into the 'automator_settings_addons_tabs' filter.
add_filter( 'automator_settings_addons_tabs', 'my_custom_automator_addon_tab', 10, 1 );

/**
 * Adds a custom addon tab to the Automator settings page.
 *
 * @param array $tabs An array of existing addon tabs.
 * @return array The modified array of addon tabs including the custom one.
 */
function my_custom_automator_addon_tab( $tabs ) {
    // Define the details for our custom addon tab.
    $custom_tab = array(
        'id'    => 'my-awesome-addon',
        'title' => __( 'My Awesome Addon', 'text-domain' ),
        'content_callback' => 'render_my_awesome_addon_settings', // A callback function to render the tab's content.
        'icon'  => 'star-filled', // Example icon, replace with a valid Automator icon or CSS class.
    );

    // Add our custom tab to the existing array of tabs.
    $tabs[] = $custom_tab;

    // Return the updated array of tabs.
    return $tabs;
}

/**
 * Callback function to render the settings content for "My Awesome Addon".
 * This function would contain the HTML and logic to display the settings for your addon.
 */
function render_my_awesome_addon_settings() {
    ?>
    <div class="automator-settings-section">
        <h3><?php esc_html_e( 'Configure My Awesome Addon', 'text-domain' ); ?></h3>
        <p><?php esc_html_e( 'This is where you can manage the settings for your awesome addon.', 'text-domain' ); ?></p>

        <table class="form-table">
            <tr>
                <th scope="row"><label for="my_addon_api_key"><?php esc_html_e( 'API Key', 'text-domain' ); ?></label></th>
                <td>
                    <input name="my_addon_api_key" type="text" id="my_addon_api_key" value="" class="regular-text">
                    <p class="description"><?php esc_html_e( 'Enter your API key for the awesome service.', 'text-domain' ); ?></p>
                </td>
            </tr>
            <tr>
                <th scope="row"><label for="my_addon_enable_feature"><?php esc_html_e( 'Enable Feature', 'text-domain' ); ?></label></th>
                <td>
                    <input name="my_addon_enable_feature" type="checkbox" id="my_addon_enable_feature" value="1">
                    <label for="my_addon_enable_feature"><?php esc_html_e( 'Turn on this awesome feature.', 'text-domain' ); ?></label>
                </td>
            </tr>
        </table>

        <?php // Add a submit button or rely on the main settings page submit button. ?>
        <?php // submit_button(); ?>
    </div>
    <?php
}

// Note: In a real plugin, you would also need to handle saving the settings
// for 'my_addon_api_key' and 'my_addon_enable_feature' using WordPress
// settings API or by hooking into a 'save_automator_settings' action.
// You would also enqueue any necessary scripts or styles for your tab.

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/tabs/addons.php:19

public function __construct() {

		// Get the tabs
		$this->addons_tabs = apply_filters( 'automator_settings_addons_tabs', array() );

		if ( empty( $this->addons_tabs ) ) {
			return;
		}

		// Add the tab using the filter
		add_filter( 'automator_settings_sections', array( $this, 'register_tab' ), 30, 1 );
	}

Scroll to Top