Filter uncanny-automator-pro

automator_action_send_notification_to_members

Filters the content of notifications sent to members by the BuddyBoss integration.

add_filter( 'automator_action_send_notification_to_members', $callback, 10, 2 );

Description

Filters the content of a BuddyBoss group notification sent by Uncanny Automator. Modify the `$notification_content` before it's sent to group members, allowing for dynamic message generation based on recipe and user data. `$this` refers to the action object.


Usage

add_filter( 'automator_action_send_notification_to_members', 'your_function_name', 10, 2 );

Parameters

$notification_content (mixed)
This parameter contains the dynamically generated content of the notification that will be sent to group members.
$this (mixed)
This parameter contains the content of the notification that will be sent to group members.

Return Value

The filtered value.


Examples

<?php
/**
 * Filters the notification content sent to BuddyBoss group members.
 *
 * This example adds a prefix to the notification content and also
 * conditionally adds a link to a specific page if the notification content
 * is empty.
 *
 * @param mixed $notification_content The original notification content.
 * @param mixed $this The instance of the Uncanny Automator action class.
 * @return mixed The modified notification content.
 */
add_filter( 'automator_action_send_notification_to_members', function( $notification_content, $this_action_instance ) {

    // Check if the notification content is empty and add a default link if so.
    // This assumes $this_action_instance has access to the action's meta data,
    // which is a common pattern in Uncanny Automator.
    if ( empty( $notification_content ) && isset( $this_action_instance->meta['BDBNOTIFICATIONLINK'] ) ) {
        $default_link_text = __( 'Click here for more details', 'your-text-domain' );
        $notification_content .= ' ' . $default_link_text;
    }

    // Add a custom prefix to all notification content.
    $prefix = __( '[Automated Update] ', 'your-text-domain' );
    $notification_content = $prefix . $notification_content;

    return $notification_content;

}, 10, 2 ); // Priority 10, accepts 2 arguments.
?>

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-sendnotificationtoallgroupmembers.php:112

public function send_notification_to_members( $user_id, $action_data, $recipe_id, $args ) {

		$sender_id            = $action_data['meta']['BDBFROMUSER'];
		$group_id             = $action_data['meta']['BDBGROUPS'];
		$notification_content = Automator()->parse->text( $action_data['meta']['BDBNOTIFICATIONCONTENT'], $recipe_id, $user_id, $args );
		$notification_content = apply_filters( 'automator_action_send_notification_to_members', do_shortcode( $notification_content ), $this );
		$notification_link    = Automator()->parse->text( $action_data['meta']['BDBNOTIFICATIONLINK'], $recipe_id, $user_id, $args );
		$notification_link    = do_shortcode( $notification_link );
		$members_ids          = array();

		if ( function_exists( 'groups_get_group_members' ) ) {
			$members = groups_get_group_members(
				array(
					'group_id'       => $group_id,
					'per_page'       => 999999,
					'type'           => 'last_joined',
					'exclude_banned' => true,
				)
			);

			if ( isset( $members['members'] ) ) {

				if ( function_exists( 'bp_notifications_add_notification' ) ) {

					foreach ( $members['members'] as $member ) {
						$notification_id = '';
						$notification_id = bp_notifications_add_notification(
							array(
								'user_id'           => $member->ID,
								'item_id'           => $action_data['ID'],
								'secondary_item_id' => $user_id,
								'component_name'    => 'uncanny-automator',
								'component_action'  => 'uncannyautomator_bdb_notification',
								'date_notified'     => bp_core_current_time(),
								'is_new'            => 1,
								'allow_duplicate'   => true,
							)
						);
						// Adding meta for notification display on front-end
						bp_notifications_update_meta( $notification_id, 'uo_notification_content', $notification_content );
						bp_notifications_update_meta( $notification_id, 'uo_notification_link', $notification_link );
					}

					Automator()->complete_action( $user_id, $action_data, $recipe_id );
				}
			}
		} else {
			Automator()->complete_action( $user_id, $action_data, $recipe_id, __( 'BuddyBoss message module is not active.', 'uncanny-automator-pro' ) );
		}

	}

Scroll to Top