Skip to:
Content
Pages
Categories
Search
Top
Bottom

Notifications stopped working properly with the upgrade


  • Kineta
    Participant

    @kineta

    I have bbPress & BuddyPress installed on my site (the newest versions of both: 2.5.9 & 2.5.2 respectively. On WordPress 4.5.2

    Notifications had been working nicely – users where notified when someone replied to either a topic they posted or a reply in a thread. Now only the person who started the topic gets a notification to their topic or their replies in the thread, and with replies they get two notifications – one that says the correct name of who it’s from and another saying it’s from their name.

    I disabled all other plugins and turned off my theme and activated the Twentysixteen theme to test.

    A separate but related issue – it would be *very* nice if the notification link went to the actual reply instead of the topic at the top of the page. This had seemed kind of promising: https://bbpress.org/forums/topic/new-reply-notification-link-to-the-reply/

Viewing 7 replies - 1 through 7 (of 7 total)

  • Kineta
    Participant

    @kineta

    Anyone else have this issue? It’s a real roadblock for our project and I’ve been trying to debug it. I’m 99% certain this happened during one of the last two bbPress upgrades.


    VeeLow
    Participant

    @veelow

    I have all kinds of issues with notifications in a threaded forum context. I post a topic; six people reply; I reply to three of them. At the end of that process, I am promptly told have “3 new replies.” (Unnamed).

    There are other bugs as well.

    FWIW, I’ve had these issues for close to a year, during which I worked with different themes using the BP/bbp combo; it’s definitely not the newest update.


    alzaran
    Participant

    @ajoyce2016

    I followed through that link as well, and though I don’t like modifying core, I did go through with it to get the ideal notification behavior. Any progress on a solid fix on that? Would it be possible to add that sort of thing as an option in bbpress-core? Just ridiculous that the default behavior doesn’t do it.


    Kineta
    Participant

    @kineta

    @ajoyce2016 – I created a fix for the site I’m working on that doesn’t require hacking the core. I’ll post it when I get home from work.


    Kineta
    Participant

    @kineta

    Here you go. I have this in my theme’s functions.php file. I posted this code a while ago, but there was a small mistake which is fixed here.

    function jpr_buddypress_add_notification( $reply_id = 0, $topic_id = 0, $forum_id = 0, $anonymous_data = false, $author_id = 0, $is_edit = false, $reply_to = 0 ) {
    	
    		
    		// this is who the notification goes to. whose post is replied to
    		$topic_author_id = bbp_get_topic_author_id( $reply_to );
    
    		// Bail if somehow this is hooked to an edit action
    		if ( !empty( $is_edit ) ) {
    			return;
    		}
    
    		// Get author information
    		// $topic_author_id   = bp_loggedin_user_id();
    		$secondary_item_id = $author_id;
    
    		// Hierarchical replies
    		if ( !empty( $reply_to ) ) {			
    			$reply_to_item_id = bbp_get_topic_author_id( $reply_to );
    			// if not replying to OP:
    			$topic_id = $reply_to;
    		}		
    
    		
    		// Get some reply information
    		$args = array(
    			'user_id'          => $topic_author_id,
    			'item_id'          => $topic_id,
    			'component_name'   => bbp_get_component_name(),
    			'component_action' => 'bbp_new_reply',
    			'date_notified'    => get_post( $reply_id )->post_date_gmt,
    		);
    	 	
    		// Notify the topic author if not the current reply author
    	 	if ( $author_id !== $topic_author_id ) {
    			$args['secondary_item_id'] = $secondary_item_id ;
    
    			bp_notifications_add_notification( $args );
    	 	}
    	 	// Notify the immediate reply author if not the current reply author
    	 	if ( !empty( $reply_to ) && ( $author_id !== $reply_to_item_id ) ) {
    			$args['secondary_item_id'] = $secondary_item_id;
    			
    			bp_notifications_add_notification( $args );
    	 }
    }
    // remove the bbpress notification function so we don't get dupicate notifications
    remove_action( 'bbp_new_reply', 'bbp_buddypress_add_notification', 10, 7 );
    add_action( 'bbp_new_reply', 'jpr_buddypress_add_notification', 10, 7 );
    
    // remove the bbpress format notification function before using our custom function
    remove_filter( 'bp_notifications_get_notifications_for_user', 'bbp_format_buddypress_notifications', 10, 5 );
    
    function jpr_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_id( $item_id );
    		$topic_title = bbp_get_reply_title( $item_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( 'jpr_format_buddypress_notifications', $action, $item_id, $secondary_item_id, $total_items );
    
    		return $return;
    	}
    }
    add_filter( 'bp_notifications_get_notifications_for_user', 'jpr_format_buddypress_notifications', 10, 5 );
    
    

    alzaran
    Participant

    @ajoyce2016

    Fantastic! I attempted to do the same thing but neglected to remove_action, so this is exactly what I needed. Thanks for your help, it’s baffling to me that BBPress doesn’t make this an option out of the box.


    Kineta
    Participant

    @kineta

    @ajoyce2016 you’re welcome. glad I could be helpful 😉

Viewing 7 replies - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.
Skip to toolbar