Filter
uncanny-automator
uncanny_automator_enabled_global_utm
Filters whether global UTM parameters are enabled for Uncanny Automator.
add_filter( 'uncanny_automator_enabled_global_utm', $callback, 10, 1 );
Description
This filter hook, `uncanny_automator_enabled_global_utm`, controls whether global UTM parameters are added to Automator Pro links. Developers can use it to disable this functionality by returning `false`. It fires when Automator Pro links are being processed, allowing for fine-grained control over tracking.
Usage
add_filter( 'uncanny_automator_enabled_global_utm', 'your_function_name', 10, 1 );
Return Value
The filtered value.
Examples
/**
* Example: Disable global UTM parameters for Automator links based on a user role.
*
* This filter allows administrators to disable the automatic addition of
* global UTM parameters to Uncanny Automator links for specific user roles.
*
* @param bool $enabled Whether global UTM parameters are enabled. Defaults to true.
* @return bool The modified value for whether global UTM parameters are enabled.
*/
function my_custom_disable_global_utm_for_roles( $enabled ) {
// If the feature is already disabled, no need to do anything further.
if ( ! $enabled ) {
return $enabled;
}
// Define the roles for which global UTMs should be disabled.
$roles_to_disable_for = array( 'editor', 'author' );
// Get the currently logged-in user.
$user = wp_get_current_user();
// Check if the user is logged in and has one of the specified roles.
if ( $user && ! empty( $user->roles ) ) {
foreach ( $user->roles as $role ) {
if ( in_array( $role, $roles_to_disable_for ) ) {
// If the user has a role that should disable UTMs, return false.
return false;
}
}
}
// If the user is not logged in or doesn't have a role that requires disabling,
// return the original enabled status.
return $enabled;
}
add_filter( 'uncanny_automator_enabled_global_utm', 'my_custom_disable_global_utm_for_roles', 10, 1 );
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/class-automator-load.php:875
public function global_utm_r_links() {
$uncanny_automator_enabled_global_utm = apply_filters( 'uncanny_automator_enabled_global_utm', true );
$uncannyautomator_source = automator_get_option( 'uncannyautomator_source' );
if ( false === $uncannyautomator_source || empty( $uncannyautomator_source ) ) {
return;
}
if ( ! $uncanny_automator_enabled_global_utm ) {
return;
}
?>
<script>
jQuery(document).ready(function ($) {
"use strict";
var automator_pro_links = 'a[href^="https://automatorplugin.com"]';
var _update_url_parameter = function (uri, key, value) {
// remove the hash part before operating on the uri
var i = uri.indexOf('#');
var hash = i === -1 ? '' : uri.substr(i);
uri = i === -1 ? uri : uri.substr(0, i);
var re = new RegExp("([?&])" + key + "=.*?(&|$)", "i");
var separator = uri.indexOf('?') !== -1 ? "&" : "?";
if (uri.match(re)) {
uri = uri.replace(re, '$1' + key + "=" + value + '$2');
} else {
uri = uri + separator + key + "=" + value;
}
return uri + hash; // finally append the hash as well
}
var source = "<?php echo esc_js( $uncannyautomator_source ); ?>";
// Add utmr to all automator upgrade links.
$.each($(automator_pro_links), function () {
var link_with_utmr = _update_url_parameter($(this).attr('href'), 'utm_r', '<?php echo esc_js( $uncannyautomator_source ); ?>');
$(this).attr('href', link_with_utmr);
});
// Add utmr to all automator upgrade links which are not accessible on document ready.
$(document).on('mouseover', automator_pro_links, function (e) {
var link_with_utmr = _update_url_parameter($(this).attr('href'), 'utm_r', '<?php echo esc_js( $uncannyautomator_source ); ?>');
$(this).attr('href', link_with_utmr);
});
});
</script>
<?php
}