bp_notifications_add_notification

bp_notifications_add_notification

Codex Home → Developer Resources → Function Examples → bp_notifications_add_notification
bp_notifications_add_notification

bp_notifications_add_notification() is used to insert new notifications into the database table $wpdb->bp_notifications.
Notifications were refactored to be a separate component for BP 1.9
Usage
$notification_id = bp_notifications_add_notification( $args );
@return int|bool ID of the newly created notification on success, false on failure.
Default 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, );
Parameters

$args
An array that describes the notification item that you』re creating. Possible values:

'user_id'
(optional) ID of the user to associate the notification with.
'item_id'
(optional) ID of the item to associate the notification with.
'secondary_item_id'
(optional) ID of the secondary item to associate the notification with.
'component_name'
(optional) Name of the component to associate the notification with.
'component_action'
(optional) Name of the action to associate the notification with.
'date_notified'
(optional) Timestamp for the notification.
'is_new'
(optional) Whether the notification is new. This will be set to 0 once the notification is viewed by the recipient.

Example
This is taken from buddypress/bp-activity/bp-activity-notifications.php and shows how the parameters can be used.
function bp_activity_at_mention_add_notification( $activity, $subject, $message, $content, $receiver_user_id ) {
if ( bp_is_active( 'notifications' ) ) {
bp_notifications_add_notification( array(
'user_id' => $receiver_user_id,
'item_id' => $activity->id,
'secondary_item_id' => $activity->user_id,
'component_name' => buddypress()->activity->id,
'component_action' => 'new_at_mention',
'date_notified' => bp_core_current_time(),
'is_new' => 1,
) );
}
}
add_action( 'bp_activity_sent_mention_email', 'bp_activity_at_mention_add_notification', 10, 5 );

Source File
bp_notifications_add_notification() is located in bp-notifications/bp-notifications-functions.php

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注