Skip to:
Content

BuddyPress.org

Changeset 7578


Ignore:
Timestamp:
11/16/2013 01:08:49 AM (11 years ago)
Author:
johnjamesjacoby
Message:

Allow non-core components to hook into notifications via a filter. This allows components that are not registered as part of the main BuddyPress singleton to hook a callback into a filter instead. See #5148.

Location:
trunk/bp-notifications
Files:
2 edited

Legend:

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

    r7543 r7578  
    148148        }
    149149
    150         // Skip inactive components
    151         if ( ! bp_is_active( $component_name ) ) {
    152             continue;
    153         }
    154 
    155150        // Loop through each actionable item and try to map it to a component
    156151        foreach ( (array) $action_arrays as $component_action_name => $component_action_items ) {
     
    168163
    169164                // Function should return an object
    170                 if ( 'object' == $format ) {
     165                if ( 'object' === $format ) {
    171166
    172167                    // Retrieve the content of the notification using the callback
     
    205200            } elseif ( isset( $bp->{$component_name}->format_notification_function ) && function_exists( $bp->{$component_name}->format_notification_function ) ) {
    206201                $renderable[] = call_user_func( $bp->{$component_name}->format_notification_function, $component_action_name, $component_action_items[0]->item_id, $component_action_items[0]->secondary_item_id, $action_item_count );
     202
     203            // Allow non BuddyPress components to hook in
     204            } else {
     205
     206                // The array to reference with apply_filters_ref_array()
     207                $ref_array = array(
     208                    $component_action_name,
     209                    $component_action_items[0]->item_id,
     210                    $component_action_items[0]->secondary_item_id,
     211                    $action_item_count,
     212                    $format
     213                );
     214
     215                // Function should return an object
     216                if ( 'object' === $format ) {
     217
     218                    // Retrieve the content of the notification using the callback
     219                    $content = apply_filters_ref_array( 'bp_notifications_get_notifications_for_user', $ref_array );
     220
     221                    // Create the object to be returned
     222                    $notification_object = new stdClass;
     223
     224                    // Minimal backpat with non-compatible notification
     225                    // callback functions
     226                    if ( is_string( $content ) ) {
     227                        $notification_object->content = $content;
     228                        $notification_object->href    = bp_loggedin_user_domain();
     229                    } else {
     230                        $notification_object->content = $content['text'];
     231                        $notification_object->href    = $content['link'];
     232                    }
     233
     234                    $notification_object->id = $component_action_items[0]->id;
     235                    $renderable[]            = $notification_object;
     236
     237                // Return an array of content strings
     238                } else {
     239                    $renderable[] = apply_filters_ref_array( 'bp_notifications_get_notifications_for_user', $ref_array );
     240                }
    207241            }
    208242        }
  • trunk/bp-notifications/bp-notifications-template.php

    r7559 r7578  
    691691        $notification = $bp->notifications->query_loop->notification;
    692692
    693         // Skip inactive components
    694         if ( ! bp_is_active( $notification->component_name ) ) {
    695             return;
    696         }
    697 
    698693        // Callback function exists
    699694        if ( isset( $bp->{ $notification->component_name }->notification_callback ) && is_callable( $bp->{ $notification->component_name }->notification_callback ) ) {
     
    703698        } elseif ( isset( $bp->{ $notification->component_name }->format_notification_function ) && function_exists( $bp->{ $notification->component_name }->format_notification_function ) ) {
    704699            $description = call_user_func( $bp->{ $notification->component_name }->format_notification_function, $notification->component_action, $notification->item_id, $notification->secondary_item_id, 1 );
     700
     701        // Allow non BuddyPress components to hook in
     702        } else {
     703            $description = apply_filters_ref_array( 'bp_notifications_get_notifications_for_user', array( $notification->component_action, $notification->item_id, $notification->secondary_item_id, 1 ) );
    705704        }
    706705
Note: See TracChangeset for help on using the changeset viewer.