Skip to:
Content

bbPress.org


Ignore:
Timestamp:
09/11/2014 03:41:54 PM (10 years ago)
Author:
johnjamesjacoby
Message:

Slightly refactor bbp_format_buddypress_notifications():

  • Return original $action if not bbp_new_reply.
  • Reduce indentation to accommodate new $action check.

This fixes a bug where checking for new reply notifications could cause future notification filter checks to fail.

Props Faison. Fixes #2665.

File:
1 edited

Legend:

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

    r5232 r5512  
    4141function bbp_format_buddypress_notifications( $action, $item_id, $secondary_item_id, $total_items, $format = 'string' ) {
    4242
     43    // Bail if not the notification action we are looking for
     44    if ( 'bbp_new_reply' !== $action ) {
     45        return $action;
     46    }
     47
    4348    // New reply notifications
    44     if ( 'bbp_new_reply' === $action ) {
    45         $topic_id    = bbp_get_reply_topic_id( $item_id );
    46         $topic_title = bbp_get_topic_title( $topic_id );
    47         $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 );
    48         $title_attr  = __( 'Topic Replies', 'bbpress' );
     49    $topic_id    = bbp_get_reply_topic_id( $item_id );
     50    $topic_title = bbp_get_topic_title( $topic_id );
     51    $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 );
     52    $title_attr  = __( 'Topic Replies', 'bbpress' );
    4953
    50         if ( (int) $total_items > 1 ) {
    51             $text   = sprintf( __( 'You have %d new replies', 'bbpress' ), (int) $total_items );
    52             $filter = 'bbp_multiple_new_subscription_notification';
     54    if ( (int) $total_items > 1 ) {
     55        $text   = sprintf( __( 'You have %d new replies', 'bbpress' ), (int) $total_items );
     56        $filter = 'bbp_multiple_new_subscription_notification';
     57    } else {
     58        if ( !empty( $secondary_item_id ) ) {
     59            $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 ) );
    5360        } else {
    54             if ( !empty( $secondary_item_id ) ) {
    55                 $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 ) );
    56             } else {
    57                 $text = sprintf( __( 'You have %d new reply to %s',             'bbpress' ), (int) $total_items, $topic_title );
    58             }
    59             $filter = 'bbp_single_new_subscription_notification';
     61            $text = sprintf( __( 'You have %d new reply to %s',             'bbpress' ), (int) $total_items, $topic_title );
    6062        }
     63        $filter = 'bbp_single_new_subscription_notification';
     64    }
    6165
    62         // WordPress Toolbar
    63         if ( 'string' === $format ) {
    64             $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 );
     66    // WordPress Toolbar
     67    if ( 'string' === $format ) {
     68        $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 );
    6569
    66         // Deprecated BuddyBar
    67         } else {
    68             $return = apply_filters( $filter, array(
    69                 'text' => $text,
    70                 'link' => $topic_link
    71             ), $topic_link, (int) $total_items, $text, $topic_title );
    72         }
     70    // Deprecated BuddyBar
     71    } else {
     72        $return = apply_filters( $filter, array(
     73            'text' => $text,
     74            'link' => $topic_link
     75        ), $topic_link, (int) $total_items, $text, $topic_title );
     76    }
    7377
    74         do_action( 'bbp_format_buddypress_notifications', $action, $item_id, $secondary_item_id, $total_items );
     78    do_action( 'bbp_format_buddypress_notifications', $action, $item_id, $secondary_item_id, $total_items );
    7579
    76         return $return;
    77     }
     80    return $return;
    7881}
    7982add_filter( 'bp_notifications_get_notifications_for_user', 'bbp_format_buddypress_notifications', 10, 5 );
Note: See TracChangeset for help on using the changeset viewer.