Action
uncanny-automator
automator_bwfan_tag_added_to_contact
Fires when a tag is added to a contact within the Autonami integration.
add_action( 'automator_bwfan_tag_added_to_contact', $callback, 10, 2 );
Description
Fires when a tag is added to a contact. This hook allows developers to perform custom actions or integrate with other services whenever a contact receives a new tag. It passes the added tags and the contact object to any hooked functions.
Usage
add_action( 'automator_bwfan_tag_added_to_contact', 'your_function_name', 10, 2 );
Parameters
-
$tags(mixed) - This parameter contains the tag(s) that have been added to the contact.
-
$bwfcrm_contact_object(mixed) - This parameter contains the tag or array of tags that have been added to the contact.
Examples
/**
* Example callback function for the automator_bwfan_tag_added_to_contact action hook.
*
* This function demonstrates how to hook into the 'automator_bwfan_tag_added_to_contact'
* action to perform custom actions when a tag is added to a contact in BW Full CRM.
* It checks if the added tag is a specific tag and, if so, performs a simulated action.
*
* @param string $tag The tag that was added to the contact.
* @param object $bwfcrm_contact_object The BW CRM contact object to which the tag was added.
* @return void
*/
function my_custom_tag_added_action( $tag, $bwfcrm_contact_object ) {
// Define a specific tag we want to react to.
$specific_tag_to_monitor = 'new-customer';
// Check if the added tag matches our specific tag.
if ( $tag === $specific_tag_to_monitor ) {
// Ensure the contact object is valid and has an ID.
if ( $bwfcrm_contact_object && isset( $bwfcrm_contact_object->id ) ) {
// Log a message or perform another action.
// In a real scenario, you might update a user meta, send an email,
// trigger another automation, or interact with another service.
error_log( sprintf(
'Tag "%s" added to contact ID %d. Performing custom action...',
$tag,
$bwfcrm_contact_object->id
) );
// Example: Add a custom meta field to the contact if they get the 'new-customer' tag.
// This is a hypothetical example; actual BW CRM methods might differ.
if ( function_exists( 'bwf_crm_update_contact_meta' ) ) {
bwf_crm_update_contact_meta( $bwfcrm_contact_object->id, 'last_status_update', current_time( 'mysql' ) );
error_log( sprintf(
'Added custom meta "last_status_update" to contact ID %d.',
$bwfcrm_contact_object->id
) );
} else {
error_log( 'bwf_crm_update_contact_meta function not found. Skipping meta update.' );
}
} else {
error_log( 'BW CRM contact object is invalid or missing ID when tag was added.' );
}
}
}
// Hook the custom function to the action.
// The second parameter '3' indicates the number of arguments the callback function accepts.
add_action( 'automator_bwfan_tag_added_to_contact', 'my_custom_tag_added_action', 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/autonami/add-autonami-integration.php:77
src/integrations/autonami/add-autonami-integration.php:82
public function tag_added_to_contact( $tags, $bwfcrm_contact_object ) {
if ( ! is_array( $tags ) ) {
do_action( 'automator_bwfan_tag_added_to_contact', $tags, $bwfcrm_contact_object );
return;
}
foreach ( $tags as $tag ) {
do_action( 'automator_bwfan_tag_added_to_contact', $tag, $bwfcrm_contact_object );
}
}
Internal Usage
Found in src/integrations/autonami/triggers/autonami-contact-tag-added.php:48:
$this->add_action( 'automator_bwfan_tag_added_to_contact' );
Found in src/integrations/autonami/triggers/autonami-user-tag-added.php:47:
$this->add_action( 'automator_bwfan_tag_added_to_contact' );