Skip to:
Content
Pages
Categories
Search
Top
Bottom

Bug in bp_notifications_get_notifications_for_user hook or misunderstood


  • Marc
    Participant

    @natrio

    Hi everyone,

    I’am currently try to add custom notification from a non BuddyPress component. I’m using this hooks:
    bp_notifications_get_registered_components
    bp_notifications_get_notifications_for_user
    and this function:
    bp_notifications_add_notification

    Everything works well except the hook bp_notifications_get_notifications_for_user. My problem is in my installation there is the bbPress plugin. It is also using this hooks. So this hooks is call twice, and the $action argument is empty or contain the rendered notification content. So I’m not allowed to do the right things on the second call.

    I must add this to this file in bbPress plugin :
    /wp-content/plugins/bbpress/includes/extend/buddypress/notifications.php on line 78 (at the end of the function return $action):

    
    /**
     * Format the BuddyBar/Toolbar notifications
     *
     * @since bbPress (r5155)
     *
     * @package bbPress
     *
     * @param string $action The kind of notification being rendered
     * @param int $item_id The primary item id
     * @param int $secondary_item_id The secondary item id
     * @param int $total_items The total number of messaging-related notifications waiting for the user
     * @param string $format 'string' for BuddyBar-compatible notifications; 'array' for WP Toolbar
     */
    function bbp_format_buddypress_notifications( $action, $item_id, $secondary_item_id, $total_items, $format = 'string' ) {
    
    	// New reply notifications
    	if ( 'bbp_new_reply' === $action ) {
    		$topic_id    = bbp_get_reply_topic_id( $item_id );
    		$topic_title = bbp_get_topic_title( $topic_id );
    		$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 );
    		$title_attr  = __( 'Topic Replies', 'bbpress' );
    
    		if ( (int) $total_items > 1 ) {
    			$text   = sprintf( __( 'You have %d new replies', 'bbpress' ), (int) $total_items );
    			$filter = 'bbp_multiple_new_subscription_notification';
    		} else {
    			if ( !empty( $secondary_item_id ) ) {
    				$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 ) );
    			} else {
    				$text = sprintf( __( 'You have %d new reply to %s',             'bbpress' ), (int) $total_items, $topic_title );
    			}
    			$filter = 'bbp_single_new_subscription_notification';
    		}
    
    		// WordPress Toolbar
    		if ( 'string' === $format ) {
    			$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 );
    
    		// Deprecated BuddyBar
    		} else {
    			$return = apply_filters( $filter, array(
    				'text' => $text,
    				'link' => $topic_link
    			), $topic_link, (int) $total_items, $text, $topic_title );
    		}
    
    		do_action( 'bbp_format_buddypress_notifications', $action, $item_id, $secondary_item_id, $total_items );
    
    		return $return;
    	}
    	return $action;
    }
    add_filter( 'bp_notifications_get_notifications_for_user', 'bbp_format_buddypress_notifications', 10, 5 );

    And i have to do the same thing for my custom notification rendering.

    So my question is quite simple: Is this a bug? A bug from bbPress? A bug from BuddyPress? Or I am not using the hook properly?

    Please advice me, and I create a ticket if it is necessary.

    Thanks in advance.

Viewing 1 replies (of 1 total)

  • shanebp
    Moderator

    @shanebp

    Custom notifications in non-components is tough.

    Have you try hooking bp_notifications_get_notifications_for_user with a higher priority than what bbPress uses? Something like 8 instead of 10?

    You may want to submit a ticket to bbPress about the orphaned return in their function.

Viewing 1 replies (of 1 total)
  • The topic ‘Bug in bp_notifications_get_notifications_for_user hook or misunderstood’ is closed to new replies.
Skip to toolbar