Filter uncanny-automator

automator_settings_general_tabs

Filters the general settings tabs, allowing modification of available tabs before they are displayed in the UI.

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

Description

Filters the array of general settings tabs. Developers can add, remove, or modify tabs presented in the Automator general settings menu, controlling the structure and content of this section. This hook fires when the general settings page is loaded.


Usage

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

Return Value

The filtered value.


Examples

/**
 * Add a custom tab to the general settings page.
 *
 * This function demonstrates how to add a new tab to the 'General' settings
 * section of the WordPress Automator plugin. It takes the existing array
 * of tabs and appends a new one with its label and callback function.
 *
 * @param array $tabs An array of existing general tabs.
 * @return array The modified array of general tabs, including the new custom tab.
 */
add_filter( 'automator_settings_general_tabs', function( $tabs ) {

    // Define the new tab's properties.
    $new_tab = array(
        'label' => __( 'Custom Settings', 'your-text-domain' ), // Translatable label for the tab.
        'callback' => 'your_plugin_custom_settings_tab_callback', // The function that will render the tab's content.
        'id' => 'custom_settings' // A unique ID for the tab.
    );

    // Append the new tab to the existing array of tabs.
    $tabs[] = $new_tab;

    // Return the updated array of tabs.
    return $tabs;
}, 10, 1 ); // Priority 10, 1 accepted argument.

// Example callback function to render the content of the custom tab.
// This function would typically be defined in your plugin's files.
function your_plugin_custom_settings_tab_callback() {
    ?>
    <div class="automator-tab-content">
        <h2><?php esc_html_e( 'Custom Plugin Settings', 'your-text-domain' ); ?></h2>
        <p><?php esc_html_e( 'This is the content for your custom settings tab. You can add forms, options, and other elements here.', 'your-text-domain' ); ?></p>
        
        <?php
        // Example of displaying an option from your plugin's settings.
        $custom_option_value = get_option( 'your_plugin_custom_setting', '' );
        ?>
        <label for="your_plugin_custom_setting"><?php esc_html_e( 'Enter a custom value:', 'your-text-domain' ); ?></label>
        <input type="text" id="your_plugin_custom_setting" name="your_plugin_custom_setting" value="<?php echo esc_attr( $custom_option_value ); ?>">
        
        <?php submit_button(); // WordPress standard submit button. ?>
    </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/tabs/general.php:99

public function get_general_tabs() {
		return apply_filters( 'automator_settings_general_tabs', array() );
	}

Scroll to Top