Action
uncanny-automator-pro
automator_groups_join_group
Fires when a user successfully joins a BuddyPress group through the Automator plugin.
add_action( 'automator_groups_join_group', $callback, 10, 2 );
Description
Fires when a user joins a BuddyPress group via Uncanny Automator. Developers can use this hook to trigger custom actions or log group joins. It passes the user ID and group ID, ensuring targeted automation based on group membership changes.
Usage
add_action( 'automator_groups_join_group', 'your_function_name', 10, 2 );
Parameters
-
$user_id(mixed) - This parameter contains the ID of the user who has joined the group.
-
$group_id(mixed) - The ID of the user who is joining the group.
Examples
<?php
/**
* Example action hook callback for automator_groups_join_group.
*
* This function logs when a user joins a group and potentially triggers
* other automator actions based on this event.
*
* @param int $user_id The ID of the user who joined the group.
* @param int $group_id The ID of the group the user joined.
*/
function my_automator_log_user_join_group( $user_id, $group_id ) {
// Ensure the user and group IDs are valid integers.
$user_id = absint( $user_id );
$group_id = absint( $group_id );
if ( ! $user_id || ! $group_id ) {
// Log an error or do nothing if IDs are invalid.
error_log( 'Invalid user_id or group_id passed to my_automator_log_user_join_group.' );
return;
}
// Get the user object.
$user = get_user_by( 'id', $user_id );
// Get the group object (assuming BuddyPress or similar).
// You might need to adjust this based on the actual group implementation.
if ( function_exists( 'groups_get_group' ) ) {
$group = groups_get_group( array( 'group_id' => $group_id ) );
} else {
$group = null; // Or fetch group data differently if not using BuddyPress.
}
// Construct a message to log.
$message = sprintf(
'User "%s" (ID: %d) joined group "%s" (ID: %d).',
$user ? $user->display_name : 'Unknown User',
$user_id,
$group ? $group->name : 'Unknown Group',
$group_id
);
// Log the event. This could be to a custom log file, a database table,
// or even trigger another Uncanny Automator recipe if configured.
error_log( 'Uncanny Automator Group Join: ' . $message );
// Example of potentially triggering another Automator action:
// You would typically have a way to get a recipe ID here if you wanted
// to trigger a specific recipe. For this example, we'll just show the concept.
/*
$recipe_id_to_trigger = 123; // Replace with an actual recipe ID if known.
if ( function_exists( 'uncanny_automator_pro' ) ) {
// This is a hypothetical function, actual Automator API might differ.
// You'd likely need to find the correct function to trigger a recipe programmatically.
// For instance, you might use uncanny_automator_pro()->get_triggers()->trigger_recipe( $recipe_id_to_trigger, array( 'user_id' => $user_id, 'group_id' => $group_id ) );
// Consult Uncanny Automator documentation for the exact method.
error_log( 'Attempting to trigger Automator recipe ' . $recipe_id_to_trigger . ' for user ' . $user_id . ' joining group ' . $group_id );
}
*/
}
// Hook into the 'automator_groups_join_group' action.
// The '3' indicates that our callback function accepts 3 arguments
// (even though we only use $user_id and $group_id in this specific example,
// it's good practice to match the hook's parameter count if possible,
// though the source context shows only 2 parameters are passed. Let's stick to 2).
// If the source context truly only passes 2, then the correct args count is 2.
// Based on the source: do_action( 'automator_groups_join_group', $user_id, $group_id );
// The accepted_args should be 2.
add_action( 'automator_groups_join_group', 'my_automator_log_user_join_group', 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
uncanny-automator-pro/src/integrations/buddypress/add-bp-integration.php:139
public function resolve_group_join_group_args_once( $group_id = 0, $user_id = 0 ) {
// Track the users who have joined the group.
global $resolve_automator_groups_join_group;
// Initialize the array if it doesn't exist.
if ( ! is_array( $resolve_automator_groups_join_group ) ) {
$resolve_automator_groups_join_group = array();
}
// Initialize the group array if it doesn't exist.
if ( ! isset( $resolve_automator_groups_join_group[ $group_id ] ) ) {
$resolve_automator_groups_join_group[ $group_id ] = array();
}
// If the action hasn't been run for the group and user yet, run it.
if ( ! in_array( $user_id, $resolve_automator_groups_join_group[ $group_id ] ) ) {
do_action( 'automator_groups_join_group', $user_id, $group_id );
$resolve_automator_groups_join_group[ $group_id ][] = $user_id;
}
}