Filter uncanny-automator

automator_settings_header

Filters the header content for the Automator settings page, allowing modifications to the active tab and overall header presentation.

add_filter( 'automator_settings_header', $callback, 10, 2 );

Description

This filter allows developers to modify the content displayed in the header section of the Automator plugin's settings pages. Use it to inject custom HTML, modify existing elements, or dynamically change the header based on the active tab or specific settings. The existing content is echoed before any filtered output.


Usage

add_filter( 'automator_settings_header', 'your_function_name', 10, 2 );

Parameters

$active (mixed)
This parameter is used to pass a custom header string that will be outputted before any other content.
$tab (mixed)
This parameter indicates whether the current tab is the active tab.

Return Value

The filtered value.


Examples

<?php
/**
 * Adds a custom title to the settings header for a specific tab.
 *
 * This function hooks into the 'automator_settings_header' filter to dynamically
 * generate content that will be displayed at the top of a settings tab's header.
 *
 * @param string $header_content The existing header content.
 * @param bool   $active         Whether the current tab is active.
 * @param object $tab            The current tab object, containing information like its slug, title, etc.
 * @return string The modified header content.
 */
add_filter(
	'automator_settings_header',
	function ( $header_content, $active, $tab ) {
		// Check if the current tab is active and if its slug is 'automator_general_settings'
		if ( $active && isset( $tab->slug ) && 'automator_general_settings' === $tab->slug ) {
			// If it's the general settings tab, prepend a custom title.
			// We can assume the tab object has a 'title' property from the context.
			// For realism, let's format it as an H2 heading.
			$custom_title = sprintf(
				'<h2>%s</h2><p>Manage your core Automator settings here.</p>',
				esc_html__( 'Automator Core Settings', 'your-text-domain' )
			);

			// Append the custom title to the existing header content.
			$header_content = $custom_title . $header_content;
		}

		// Return the (potentially modified) header content.
		return $header_content;
	},
	10, // Priority: Default priority
	3  // Accepted args: The number of arguments the filter callback accepts
);

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/includes/automator-settings.php:202

if ( isset( $tab->settings_field ) ) {
							settings_fields( $tab->settings_field );
						}
						if ( isset( $tab->wp_nonce_field ) ) {
							wp_nonce_field( $tab->wp_nonce_field, $tab->wp_nonce_field );
						}

						$header_content = apply_filters( 'automator_settings_header', '', $active, $tab );
						ob_start();
						echo $header_content; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
						$header_content = ob_get_clean(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped

						?>

						<?php if ( ! empty( $header_content ) ) { ?>


Scroll to Top