Skip to:
Content
Pages
Categories
Search
Top
Bottom

“New Reply”-Notification – Link to the Reply, not Topic


  • Malle
    Participant

    @malle

    Hi folks,

    bbPress is amazing with Buddypress, but one thing is anoying me:

    When i have new Replys or a Notification of a new Reply. The generated Link directs me to the front Page or the First Post of the Topic.

    But the Notification is called “You have a new Reply from XY to Topic ABC”.
    So i want to see the new Reply, not the first Entry of this Topic (bc. i created this Topic).

    I arranged it like that:

    Changed the following Code:
    “bbpress/includes/extend/buddypress/notifications.php” / Line 49

    
    $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 );
    

    to

    
    $topic_link  = wp_nonce_url( add_query_arg( array( 'action' => 'bbp_mark_read', 'topic_id' => $item_id ), bbp_get_reply_url( $item_id ) ), 'bbp_mark_topic_' . $item_id );
    

    and
    “bbpress/includes/extend/buddypress/notifications.php” / Line 113-120

    
    	// 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,
    	);
    

    to

    
    	// Get some reply information
    	$args = array(
    		'user_id'          => $topic_author_id,
    		'item_id'          => $reply_id,
    		'component_name'   => bbp_get_component_name(),
    		'component_action' => 'bbp_new_reply',
    		'date_notified'    => get_post( $reply_id )->post_date,
    	);
    

    So it´s Kind of a Core Hack.
    Could it be impimented as an Option or via other Filter? I don´t know how to do it “right”.

    Pls Help and Greetings

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

  • Kineta
    Participant

    @kineta

    This is just what I need for the project I’m working on. I have the same question about how to do this without hacking the core files. Any guidance for a wordpress/bbpress beginner?


    ajoyce2016
    Participant

    @ajoyce2016

    I’ll third it. I’m fine with hacking it, but need a more permanent solution. Perhaps a bp-custom solution using the right filters/actions (which are quite poorly documented, gotta say)


    contemplate
    Participant

    @contemplate

    Hi All. Needed this exact behavior as well. It really should be the default behavior. But if you don’t want to hack the core here is the code to place in your functions.php or custom plugin:

    
    /**
     * Format the BuddyBar/Toolbar notifications
     * Fixed: https://bbpress.org/forums/topic/new-reply-notification-link-to-the-reply/
     */
    function bbp_format_buddypress_notifications_custom( $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' => $item_id ), bbp_get_reply_url( $item_id ) ), 'bbp_mark_topic_' . $item_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;
    	}
    }
    remove_filter( 'bp_notifications_get_notifications_for_user', 'bbp_format_buddypress_notifications', 10 );
    add_filter( 'bp_notifications_get_notifications_for_user', 'bbp_format_buddypress_notifications_custom', 10, 5 );
    
    /**
     * Hooked into the new reply function, this notification action is responsible
     * for notifying topic and hierarchical reply authors of topic replies.
     * Fixed: https://bbpress.org/forums/topic/new-reply-notification-link-to-the-reply/
     */
    function bbp_buddypress_add_notification_custom( $reply_id = 0, $topic_id = 0, $forum_id = 0, $anonymous_data = false, $author_id = 0, $is_edit = false, $reply_to = 0 ) {
    
    	// Bail if somehow this is hooked to an edit action
    	if ( !empty( $is_edit ) ) {
    		return;
    	}
    
    	// Get autohr information
    	$topic_author_id   = bbp_get_topic_author_id( $topic_id );
    	$secondary_item_id = $author_id;
    
    	// Hierarchical replies
    	if ( !empty( $reply_to ) ) {
    		$reply_to_item_id = bbp_get_topic_author_id( $reply_to );
    	}
    
    	// Get some reply information
    	$args = array(
    		'user_id'          => $topic_author_id,
    		'item_id'          => $reply_id,
    		'component_name'   => bbp_get_component_name(),
    		'component_action' => 'bbp_new_reply',
    		'date_notified'    => get_post( $reply_id )->post_date,
    	);
    
     	// 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'] = $reply_to_item_id ;
    
    		bp_notifications_add_notification( $args );
     	}
    }
    remove_action( 'bbp_new_reply', 'bbp_buddypress_add_notification', 10 );
    add_action( 'bbp_new_reply', 'bbp_buddypress_add_notification_custom', 10, 7 );
    

    WPjohnny.com
    Participant

    @treeflips

    Hi contemplate,

    Can you make a skimmed down version of your solution for people who have ONLY bbpress?


    Samuel Elh
    Participant

    @elhardoum

    @treeflips

    Hi contemplate,

    Can you make a skimmed down version of your solution for people who have ONLY bbpress?

    /**
     * Hooked into the new reply function, this notification action is responsible
     * for notifying topic and hierarchical reply authors of topic replies.
     * Fixed: https://bbpress.org/forums/topic/new-reply-notification-link-to-the-reply/
     */
    function bbp_buddypress_add_notification_custom( $reply_id = 0, $topic_id = 0, $forum_id = 0, $anonymous_data = false, $author_id = 0, $is_edit = false, $reply_to = 0 ) {
    
    	// Bail if somehow this is hooked to an edit action
    	if ( !empty( $is_edit ) ) {
    		return;
    	}
    
    	// Get autohr information
    	$topic_author_id   = bbp_get_topic_author_id( $topic_id );
    	$secondary_item_id = $author_id;
    
    	// Hierarchical replies
    	if ( !empty( $reply_to ) ) {
    		$reply_to_item_id = bbp_get_topic_author_id( $reply_to );
    	}
    
    	// Get some reply information
    	$args = array(
    		'user_id'          => $topic_author_id,
    		'item_id'          => $reply_id,
    		'component_name'   => bbp_get_component_name(),
    		'component_action' => 'bbp_new_reply',
    		'date_notified'    => get_post( $reply_id )->post_date,
    	);
    
     	// 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'] = $reply_to_item_id ;
    
    		bp_notifications_add_notification( $args );
     	}
    }
    remove_action( 'bbp_new_reply', 'bbp_buddypress_add_notification', 10 );
    add_action( 'bbp_new_reply', 'bbp_buddypress_add_notification_custom', 10, 7 );
Viewing 5 replies - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.
Skip to toolbar