Action uncanny-automator

automator_activation_after

Fires after an Automator automation has been successfully activated.

add_action( 'automator_activation_after', $callback, 10, 1 );

Description

Fires after Automator's database tables have been created or upgraded. Developers can use this hook to perform actions that depend on the plugin's database structure being in place, such as registering custom post types or setting up initial plugin options. This hook fires during plugin activation or update.


Usage

add_action( 'automator_activation_after', 'your_function_name', 10, 1 );

Examples

// Example: Log a message when the Automator plugin is activated and the database has been upgraded.
add_action( 'automator_activation_after', 'my_automator_activation_log', 10, 0 );

function my_automator_activation_log() {
    // Check if the Automator database version matches the current plugin version.
    // This assumes AUTOMATOR_DATABASE_VERSION is a defined constant.
    $current_db_version = get_option( 'automator_db_version' );

    if ( $current_db_version && (string) AUTOMATOR_DATABASE_VERSION === (string) $current_db_version ) {
        // Database is already up-to-date, no need to log this activation event.
        return;
    }

    // Log that the database has been upgraded or created.
    // In a real scenario, you might do more complex logging or send notifications.
    error_log( 'Automator plugin activated and database schema updated to version: ' . AUTOMATOR_DATABASE_VERSION );

    // Optionally, update the stored database version after successful table creation.
    // This is often handled by the plugin itself after this hook fires,
    // but this demonstrates where you might do it if needed.
    // update_option( 'automator_db_version', AUTOMATOR_DATABASE_VERSION );
}

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/class-automator-db.php:342

public static function activation() {

		do_action( 'automator_activation_before' );

		automator_update_option( 'automator_over_time', array( 'installed_date' => time() ) );

		$db_version = automator_get_option( 'uap_database_version', null );

		self::async_wp_options_migration();

		if ( null !== $db_version && (string) AUTOMATOR_DATABASE_VERSION === (string) $db_version ) {
			// bail. No db upgrade needed!
			return;
		}

		self::create_tables();

		do_action( 'automator_activation_after' );
	}


Scroll to Top