Skip to:
Content

bbPress.org

Changeset 5232


Ignore:
Timestamp:
12/23/2013 09:29:19 PM (11 years ago)
Author:
johnjamesjacoby
Message:

Introduce helper function for getting the BuddyPress component name, and filter new BuddyPress function to include it in registered components. Fixes #2495. Hat-tip imath. (trunk)

Location:
trunk/includes/extend/buddypress
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/includes/extend/buddypress/functions.php

    r5161 r5232  
    1313
    1414/** BuddyPress Helpers ********************************************************/
     15
     16/**
     17 * Return bbPress's component name/ID ('forums' by default)
     18 *
     19 * This is used primarily for Notifications integration.
     20 *
     21 * @since bbPress (r5232)
     22 * @return string
     23 */
     24function bbp_get_component_name() {
     25
     26    // Use existing ID
     27    if ( !empty( bbpress()->extend->buddypress->id ) ) {
     28        $retval = bbpress()->extend->buddypress->id;
     29
     30    // Use default
     31    } else {
     32        $retval = 'forums';
     33    }
     34
     35    return apply_filters( 'bbp_get_component_name', $retval );
     36}
    1537
    1638/**
  • trunk/includes/extend/buddypress/notifications.php

    r5192 r5232  
    11<?php
     2
     3/**
     4 * Filter registered notifications components, and add 'forums' to the queried
     5 * 'component_name' array.
     6 *
     7 * @since bbPress (r5232)
     8 *
     9 * @see BP_Notifications_Notification::get()
     10 * @param array $component_names
     11 * @return array
     12 */
     13function bbp_filter_notifications_get_registered_components( $component_names = array() ) {
     14
     15    // Force $component_names to be an array
     16    if ( ! is_array( $component_names ) ) {
     17        $component_names = array();
     18    }
     19
     20    // Add 'forums' component to registered components array
     21    array_push( $component_names, bbp_get_component_name() );
     22
     23    // Return component's with 'forums' appended
     24    return $component_names;
     25}
     26add_filter( 'bp_notifications_get_registered_components', 'bbp_filter_notifications_get_registered_components', 10 );
    227
    328/**
     
    85110
    86111    // Get some reply information
    87     $date_notified    = get_post( $reply_id )->post_date;
    88     $item_id          = $topic_id;
    89     $component_name   = 'forums';
    90     $component_action = 'bbp_new_reply';
     112    $args = array(
     113        'user_id'          => $topic_author_id,
     114        'item_id'          => $topic_id,
     115        'component_name'   => bbp_get_component_name(),
     116        'component_action' => 'bbp_new_reply',
     117        'date_notified'    => get_post( $reply_id )->post_date,
     118    );
    91119
    92     // Notify the topic author if not the current reply author
    93     if ( $author_id !== $topic_author_id ) {
    94         bp_core_add_notification( $item_id, $topic_author_id, $component_name, $component_action, $secondary_item_id, $date_notified );
    95     }
     120    // Notify the topic author if not the current reply author
     121    if ( $author_id !== $topic_author_id ) {
     122        $args['secondary_item_id'] = $secondary_item_id ;
    96123
    97     // Notify the immediate reply author if not the current reply author
    98     if ( !empty( $reply_to ) && ( $author_id !== $reply_to_item_id ) ) {
    99         bp_core_add_notification( $item_id, $topic_author_id, $component_name, $component_action, $reply_to_item_id, $date_notified );
    100     }
     124        bp_notifications_add_notification( $args );
     125    }
     126 
     127    // Notify the immediate reply author if not the current reply author
     128    if ( !empty( $reply_to ) && ( $author_id !== $reply_to_item_id ) ) {
     129        $args['secondary_item_id'] = $reply_to_item_id ;
     130
     131        bp_notifications_add_notification( $args );
     132    }
    101133}
    102134add_action( 'bbp_new_reply', 'bbp_buddypress_add_notification', 10, 7 );
     
    138170
    139171        // Attempt to clear notifications for the current user from this topic
    140         $success = bp_core_mark_notifications_by_item_id( $user_id, $topic_id, 'forums', 'bbp_new_reply' );
     172        $success = bp_notifications_mark_notifications_by_item_id( $user_id, $topic_id, bbp_get_component_name(), 'bbp_new_reply' );
    141173
    142174        // Do additional subscriptions actions
Note: See TracChangeset for help on using the changeset viewer.