Skip to:
Content

bbPress.org


Ignore:
Timestamp:
01/27/2017 05:40:54 AM (6 years ago)
Author:
johnjamesjacoby
Message:

BuddyPress: Update bbp_format_buddypress_notifications() with new parameters.

  • Prefer $component_action_name over less reliable $content
  • Parameters match BuddyPress 2.6.0 and higher signature
  • Mild function clean-up

Fixes #3036.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/includes/extend/buddypress/notifications.php

    r6180 r6262  
    1313// Hooks
    1414add_filter( 'bp_notifications_get_registered_components', 'bbp_filter_notifications_get_registered_components', 10 );
    15 add_filter( 'bp_notifications_get_notifications_for_user', 'bbp_format_buddypress_notifications', 10, 5 );
     15add_filter( 'bp_notifications_get_notifications_for_user', 'bbp_format_buddypress_notifications', 10, 8 );
    1616add_action( 'bbp_new_reply', 'bbp_buddypress_add_notification', 10, 7 );
    1717add_action( 'bbp_get_request', 'bbp_buddypress_mark_notifications', 1 );
     
    5050 * @package bbPress
    5151 *
    52  * @param string $action The kind of notification being rendered
    53  * @param int $item_id The primary item id
    54  * @param int $secondary_item_id The secondary item id
    55  * @param int $total_items The total number of messaging-related notifications waiting for the user
    56  * @param string $format 'string' for BuddyBar-compatible notifications; 'array' for WP Toolbar
    57  */
    58 function bbp_format_buddypress_notifications( $action, $item_id, $secondary_item_id, $total_items, $format = 'string' ) {
     52 * @param string $content               Component action. Deprecated. Do not do checks against this! Use
     53 *                                      the 6th parameter instead - $component_action_name.
     54 * @param int    $item_id               Notification item ID.
     55 * @param int    $secondary_item_id     Notification secondary item ID.
     56 * @param int    $action_item_count     Number of notifications with the same action.
     57 * @param string $format                Format of return. Either 'string' or 'object'.
     58 * @param string $component_action_name Canonical notification action.
     59 * @param string $component_name        Notification component ID.
     60 * @param int    $id                    Notification ID.
     61 */
     62function bbp_format_buddypress_notifications( $content, $item_id, $secondary_item_id, $action_item_count, $format, $component_action_name, $component_name, $id ) {
    5963
    6064    // Bail if not the notification action we are looking for
    61     if ( 'bbp_new_reply' !== $action ) {
    62         return $action;
     65    if ( 'bbp_new_reply' !== $component_action_name ) {
     66        return $component_action_name;
    6367    }
    6468
     
    6670    $topic_id    = bbp_get_reply_topic_id( $item_id );
    6771    $topic_title = bbp_get_topic_title( $topic_id );
    68     $topic_link  = wp_nonce_url( add_query_arg( array( 'action' => 'bbp_mark_read', 'topic_id' => $topic_id ), bbp_get_reply_url( $item_id ) ), 'bbp_mark_topic_' . $topic_id );
    69     $title_attr  = __( 'Topic Replies', 'bbpress' );
    70 
    71     if ( (int) $total_items > 1 ) {
    72         $text   = sprintf( __( 'You have %d new replies', 'bbpress' ), (int) $total_items );
     72    $topic_link  = wp_nonce_url(
     73        add_query_arg(
     74            array(
     75                'action'   => 'bbp_mark_read',
     76                'topic_id' => $topic_id
     77            ),
     78            bbp_get_reply_url( $item_id )
     79        ),
     80        'bbp_mark_topic_' . $topic_id
     81    );
     82
     83    // Cast to int
     84    $action_item_count = (int) $action_item_count;
     85
     86    // Multiple
     87    if ( $action_item_count > 1 ) {
    7388        $filter = 'bbp_multiple_new_subscription_notification';
     89        $text   = sprintf( __( 'You have %d new replies', 'bbpress' ), $action_item_count );
     90
     91    // Single
    7492    } else {
    75         if ( ! empty( $secondary_item_id ) ) {
    76             $text = sprintf( __( 'You have %d new reply to %2$s from %3$s', 'bbpress' ), (int) $total_items, $topic_title, bp_core_get_user_displayname( $secondary_item_id ) );
    77         } else {
    78             $text = sprintf( __( 'You have %d new reply to %s',             'bbpress' ), (int) $total_items, $topic_title );
    79         }
    8093        $filter = 'bbp_single_new_subscription_notification';
     94        $text   = ! empty( $secondary_item_id )
     95            ? sprintf( __( 'You have %d new reply to %2$s from %3$s', 'bbpress' ), $action_item_count, $topic_title, bp_core_get_user_displayname( $secondary_item_id ) )
     96            : sprintf( __( 'You have %d new reply to %s',             'bbpress' ), $action_item_count, $topic_title );
    8197    }
    8298
    8399    // WordPress Toolbar
    84100    if ( 'string' === $format ) {
    85         $return = apply_filters( $filter, '<a href="' . esc_url( $topic_link ) . '" title="' . esc_attr( $title_attr ) . '">' . esc_html( $text ) . '</a>', (int) $total_items, $text, $topic_link );
     101        $return = apply_filters( $filter, '<a href="' . esc_url( $topic_link ) . '" title="' . esc_attr__( 'Topic Replies', 'bbpress' ) . '">' . esc_html( $text ) . '</a>', $action_item_count, $text, $topic_link );
    86102
    87103    // Deprecated BuddyBar
     
    90106            'text' => $text,
    91107            'link' => $topic_link
    92         ), $topic_link, (int) $total_items, $text, $topic_title );
    93     }
    94 
    95     do_action( 'bbp_format_buddypress_notifications', $action, $item_id, $secondary_item_id, $total_items );
     108        ), $topic_link, $action_item_count, $text, $topic_title );
     109    }
     110
     111    do_action( 'bbp_format_buddypress_notifications', $component_action_name, $item_id, $secondary_item_id, $action_item_count, $format, $component_action_name, $component_name, $id );
    96112
    97113    return $return;
Note: See TracChangeset for help on using the changeset viewer.