Skip to:
Content

BuddyPress.org

Changeset 10790


Ignore:
Timestamp:
05/19/2016 05:58:25 PM (4 years ago)
Author:
r-a-y
Message:

Notifications: Pass the notification ID to the notification format callback.

When formatting notifications for a component, there are some cases where
you might want to reference the notification ID.

This is especially important if you want to grab some notification meta
without having to re-query just for the notification ID.

This commit adds the notification ID to our notification format callbacks:

  • For those registered by the BP_Component class ($bp->COMPONENT->notification_callback)
  • For non-BP components via the 'bp_notifications_get_notifications_for_user' filter.

Fixes #7066.

Location:
trunk/src/bp-notifications
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-notifications/bp-notifications-functions.php

    r10788 r10790  
    234234                        $component_action_items[0]->secondary_item_id,
    235235                        $action_item_count,
    236                         'array'
     236                        'array',
     237                        $component_action_items[0]->id
    237238                    );
    238239
     
    254255                // Return an array of content strings.
    255256                } else {
    256                     $content      = call_user_func( $bp->{$component_name}->notification_callback, $component_action_name, $component_action_items[0]->item_id, $component_action_items[0]->secondary_item_id, $action_item_count );
     257                    $content      = call_user_func( $bp->{$component_name}->notification_callback, $component_action_name, $component_action_items[0]->item_id, $component_action_items[0]->secondary_item_id, $action_item_count, $component_action_items[0]->id );
    257258                    $renderable[] = $content;
    258259                }
     
    273274                    $format,
    274275                    $component_action_name, // Duplicated so plugins can check the canonical action name.
    275                     $component_name
     276                    $component_name,
     277                    $component_action_items[0]->id
    276278                );
    277279
     
    287289                     *
    288290                     * @since 1.9.0
    289                      * @since 2.6.0 Added $component_action_name and $component_name as parameters.
     291                     * @since 2.6.0 Added $component_action_name, $component_name, $id as parameters.
    290292                     *
    291293                     * @param string $content               Component action. Deprecated. Do not do checks against this! Use
     
    297299                     * @param string $component_action_name Canonical notification action.
    298300                     * @param string $component_name        Notification component ID.
     301                     * @param int    $id                    Notification ID.
    299302                     *
    300303                     * @return string|array If $format is 'string', return a string of the notification content.
  • trunk/src/bp-notifications/bp-notifications-template.php

    r10785 r10790  
    472472        // Callback function exists.
    473473        if ( isset( $bp->{ $notification->component_name }->notification_callback ) && is_callable( $bp->{ $notification->component_name }->notification_callback ) ) {
    474             $description = call_user_func( $bp->{ $notification->component_name }->notification_callback, $notification->component_action, $notification->item_id, $notification->secondary_item_id, 1 );
     474            $description = call_user_func( $bp->{ $notification->component_name }->notification_callback, $notification->component_action, $notification->item_id, $notification->secondary_item_id, 1, 'string', $notification->id );
    475475
    476476        // @deprecated format_notification_function - 1.5
     
    482482
    483483            /** This filter is documented in bp-notifications/bp-notifications-functions.php */
    484             $description = apply_filters_ref_array( 'bp_notifications_get_notifications_for_user', array( $notification->component_action, $notification->item_id, $notification->secondary_item_id, 1, 'string', $notification->component_action, $notification->component_name ) );
     484            $description = apply_filters_ref_array( 'bp_notifications_get_notifications_for_user', array( $notification->component_action, $notification->item_id, $notification->secondary_item_id, 1, 'string', $notification->component_action, $notification->component_name, $notification->id ) );
    485485        }
    486486
Note: See TracChangeset for help on using the changeset viewer.