bp_notifications_add_notification( array $args = array() )

Add a notification for a specific user, from a specific component.


Description Description


Parameters Parameters

$args

(Optional) Array of arguments describing the notification. All are optional.

  • 'user_id'
    (int) ID of the user to associate the notification with.
  • 'item_id'
    (int) ID of the item to associate the notification with.
  • 'secondary_item_id'
    (int) ID of the secondary item to associate the notification with.
  • 'component_name'
    (string) Name of the component to associate the notification with.
  • 'component_action'
    (string) Name of the action to associate the notification with.
  • 'date_notified'
    (string) Timestamp for the notification.

Default value: array()


Top ↑

Return Return

(int|bool) ID of the newly created notification on success, false on failure.


Top ↑

Source Source

File: bp-notifications/bp-notifications-functions.php

function bp_notifications_add_notification( $args = array() ) {

	$r = bp_parse_args( $args, array(
		'user_id'           => 0,
		'item_id'           => 0,
		'secondary_item_id' => 0,
		'component_name'    => '',
		'component_action'  => '',
		'date_notified'     => bp_core_current_time(),
		'is_new'            => 1,
		'allow_duplicate'   => false,
	), 'notifications_add_notification' );

	// Check for existing duplicate notifications.
	if ( ! $r['allow_duplicate'] ) {
		// Date_notified, allow_duplicate don't count toward
		// duplicate status.
		$existing = BP_Notifications_Notification::get( array(
			'user_id'           => $r['user_id'],
			'item_id'           => $r['item_id'],
			'secondary_item_id' => $r['secondary_item_id'],
			'component_name'    => $r['component_name'],
			'component_action'  => $r['component_action'],
			'is_new'            => $r['is_new'],
		) );

		if ( ! empty( $existing ) ) {
			return false;
		}
	}

	// Setup the new notification.
	$notification                    = new BP_Notifications_Notification;
	$notification->user_id           = $r['user_id'];
	$notification->item_id           = $r['item_id'];
	$notification->secondary_item_id = $r['secondary_item_id'];
	$notification->component_name    = $r['component_name'];
	$notification->component_action  = $r['component_action'];
	$notification->date_notified     = $r['date_notified'];
	$notification->is_new            = $r['is_new'];

	// Save the new notification.
	return $notification->save();
}

Top ↑

Changelog Changelog

Changelog
Version Description
1.9.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.