bbp_subscriptions_handler
Fires when a user subscribes or unsubscribes to a forum, passing relevant IDs.
add_action( 'bbp_subscriptions_handler', $callback, 10, 2 );
Description
Fires after a user is subscribed or unsubscribed from a BuddyPress or BuddyBoss forum. Developers can use this hook to trigger custom actions or logic based on forum subscription events, such as sending notifications or updating user meta.
Usage
add_action( 'bbp_subscriptions_handler', 'your_function_name', 10, 2 );
Parameters
-
$user_id(mixed) - This parameter appears to be a boolean flag indicating whether the operation should be treated as a success or not, though its exact purpose in this context is unclear without more information.
-
$forum_id(mixed) - The user ID of the user who is being subscribed or unsubscribed from a forum.
Examples
/**
* Handles actions related to user subscriptions to bbPress forums.
*
* This function is triggered by the 'bbp_subscriptions_handler' action hook.
* It can be used to perform custom logic when a user subscribes to or
* unsubscribes from a forum, based on the provided action type.
*
* @param bool $is_subscription_action Whether this is a subscription action (true) or unsubscribe action (false).
* @param int $user_id The ID of the user involved.
* @param int $forum_id The ID of the forum involved.
* @param string $action_type The type of subscription action ('bbp_subscribe' or 'bbp_unsubscribe').
*/
add_action( 'bbp_subscriptions_handler', 'my_custom_bbp_subscription_handler', 10, 4 );
function my_custom_bbp_subscription_handler( $is_subscription_action, $user_id, $forum_id, $action_type ) {
// Example: Log subscription/unsubscription events.
if ( 'bbp_subscribe' === $action_type ) {
bbp_log( sprintf( 'User %d subscribed to forum %d.', $user_id, $forum_id ) );
// You could also trigger other actions here, like sending a welcome email.
} elseif ( 'bbp_unsubscribe' === $action_type ) {
bbp_log( sprintf( 'User %d unsubscribed from forum %d.', $user_id, $forum_id ) );
// You could also trigger other actions here, like revoking permissions.
}
// Example: Check if it's a subscription action for a specific forum and perform a different action.
if ( $is_subscription_action && $forum_id === 123 ) { // Replace 123 with a specific forum ID
bbp_log( sprintf( 'User %d has subscribed to the special forum %d. Performing a special action.', $user_id, $forum_id ) );
// Add your special logic here.
}
}
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/buddyboss/actions/bdb-unsubscribe-user-from-forum.php:124
uncanny-automator-pro/src/integrations/buddyboss/actions/bdb-subscribeforum.php:147
uncanny-automator-pro/src/integrations/bbpress/actions/bb-subscribeforum.php:95
uncanny-automator-pro/src/integrations/buddypress/actions/bp-unsubscribe-user-form-forum.php:94
uncanny-automator-pro/src/integrations/buddypress/actions/bp-subscribeforum.php:96
$success = false;
foreach ( $forums as $forum_id ) {
// Add unsuccessful forum IDs to errors.
if ( false === bbp_remove_user_subscription( $user_id, $forum_id ) ) {
$errors['success'][] = $forum_id;
} else {
// Do additional subscriptions actions
do_action( 'bbp_subscriptions_handler', true, $user_id, $forum_id, 'bbp_unsubscribe' );
$success = true;
}
}
// Generate any error messages ( ignored if no errors ).
$error = $this->generate_error_message( $errors );