Filter uncanny-automator

automator_active_campaign_webhook_endpoint

Filters the ActiveCampaign webhook endpoint URL before it's used.

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

Description

Filters the ActiveCampaign webhook endpoint URL. Developers can use this hook to dynamically change the default endpoint for ActiveCampaign webhooks, ensuring compatibility with older setups or custom configurations. This filter fires when the webhook endpoint is being set.


Usage

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

Parameters

$this (mixed)
This parameter contains the default webhook endpoint for ActiveCampaign, which can be filtered by other plugins or themes.

Return Value

The filtered value.


Examples

<?php
/**
 * Filters the ActiveCampaign webhook endpoint to use a custom one for specific users.
 *
 * @param string $endpoint The default webhook endpoint slug.
 * @param object $helpers  The helper object passed from the plugin.
 * @return string The modified webhook endpoint slug.
 */
add_filter( 'automator_active_campaign_webhook_endpoint', function( $endpoint, $helpers ) {
    // Get the current user object.
    $current_user = wp_get_current_user();

    // Check if the current user has a specific role or meta data.
    // For example, if we want to use a different endpoint for 'admin' users.
    if ( in_array( 'administrator', (array) $current_user->roles ) ) {
        // Return a custom endpoint slug for administrators.
        return 'admin-active-campaign';
    }

    // You could also check for user meta:
    // $custom_endpoint = get_user_meta( $current_user->ID, 'active_campaign_webhook_endpoint', true );
    // if ( ! empty( $custom_endpoint ) ) {
    //     return sanitize_key( $custom_endpoint );
    // }

    // Otherwise, return the original endpoint.
    return $endpoint;
}, 10, 2 );

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/integrations/active-campaign/helpers/active-campaign-webhooks.php:17

public function set_properties() {
		// Override webhook endpoint for legacy compatibility.
		$this->set_webhook_endpoint(
			apply_filters(
				'automator_active_campaign_webhook_endpoint',
				'active-campaign',
				$this->helpers
			)
		);

		// Override webhooks enabled option name for legacy compatibility.
		$this->set_webhooks_enabled_option_name( $this->helpers->get_const( 'ENABLE_WEBHOOK_OPTION' ) );

		// Override webhook key option name for legacy compatibility.
		$this->set_webhook_key_option_name( 'uap_active_campaign_webhook_key' );
	}

Scroll to Top