Notification when reply in topic receives reply?
-
I am using BuddyPress with BBPress, and, if I create a topic, I get a notification that someone commented in the topic, but, as a participant of a topic, I don’t get a notification if someone replies to my comment in a topic. There are a couple bugs I’m working out on my site (allianceofhealth.com), and I’m not sure if this is one of them. Is this a feature that I might have to program into BBPress or BuddyPress (whichever one’s responsible for the notifs).
-
To get replies on a topic, you need to be subscribed to the topic, so you should have ticked the box at the bottom to get the replies.
Pascal.I think if you have threaded replies enabled in bbPress, if you reply to another reply, you get a BuddyPress notification (if you have the notifications active), I think there is a bug in bbPress’ code for that feature though.
I have threaded replies enabled, the box ticked, and the forum subscribed, but I am not getting any BuddyPress notifications when someone responds to the topic. @Robkk, It probably is a bug. I wish more people would work on BBPress, but I know you can only go so far with volunteer work (and they did go pretty far! Especially with BuddyPress. BuddyPress is awesome.).
Yeah I can confirm it is a bug, I created this trac ticket on the issue awhile back.
I read through the ticket. It looks like the BuddyPress notifications for BBPress forums really are kind of messed up, but it’s fine. I love the functionality it does have. Not even fb has forums.
I’ve encountered the same issue. I’ve been beating my head against this thinking it was an issue in the theme I’m developing. Finally stripped everything down to just the bbPress & BuddyPress plugins and used the TwentySixteen theme to test.
If someone replies to a post inside a threaded topic and that post was made by the person who created the original topic, then they will get TWO notifications. One will say it’s from the name of the person who replied (good so far) and the second will say it’s from the name of the person getting the notification (and/or OP author). Also, no notifications are sent if the reply isn’t to the author of the original post/topic.
I’m very happy to see there’s a ticket for this. Any hope that it will get fixed any time soon? Selfish reason for asking – this stands to put a kibosh on my project as the two main requirements for the community forum I’m developing the theme for require threaded replies and notifications.
I haven’t experienced the first problem you mentioned (getting two notifications), probably because I haven’t used BBPress and BuddyPress that much, yet, but I really wish the second part would work: allowing participants (who haven’t created the topic) to get notifications when someone leaves a reply.
My guess is that the second part just hasn’t been implemented, yet. All the components to create that feature are probably there. Someone just has to create it.
Maybe they thought it wasn’t necessary since users can choose to receive email notifications?Funny, I could have sworn reply notifications worked when we were first testing and trying to find a forum platform that met our needs. Must have hallucinated that!
Email notifications are fine for some things, but on a very active discussion board they would be overwhelming.
I’ve been trying to hack the code in the includes/extend/buddypress/notifications.php file. But I’m pretty green with both php and wordpress/bbpress development. It does look like all the parts are there to extend it. But I’m a bit perplexed about some things in the code.
Yeah, you’d assume it would be an obvious feature to include, but maybe there’s something stopping them from implementing it. I think BBPress has its own notifications feature that ties into BuddyPress’ notifications.
It looks like there’s only one function to notify the author of the thread and none to notify anyone else. I’m sure you already found the function, but just in case, its in bbpress > includes > extend > buddypress > notifications.php
I would also really like to see this feature implemented.
Well, I hacked the function bbp_buddypress_add_notification() in bbpress > includes > extend > buddypress > notifications.php which calls bp_notifications_add_notification( $args );
I also found bbp_get_topic_subscribers($topic_id) which I used to get the ids of users who have subscribed to a topic (not sure if there’s another better way of getting all the ids of users who are part of a topic).
I plugged those ids into the $args for the previous function with a foreach loop, and I was surprised to get anything back.
Each user gets a notification (as far as I can tell) when anyone replies to the topic, but they also get extra notifications (from themselves and other users) from one reply. I’ll keep playing around with it.Would you be willing to share what you’ve got so far? It would be helpful. Thanks.
Sure. I copied the function bbp_buddypress_add_notification() in bbpress > includes > extend > buddypress > notifications.php, pasted it right below itself, made the modifications, and changed the name of the function to bbp_buddypress_add_notification_for_participants.
function bbp_buddypress_add_notification_for_participants( $reply_id = 0, $topic_id = 0, $forum_id = 0, $anonymous_data = false, $author_id = 0, $is_edit = false, $reply_to = 0 ) { $current_topic_id = bbp_get_topic_id(); $ids_of_subs = bbp_get_topic_subscribers($current_topic_id); foreach ($ids_of_subs as $sub_id) { $topic_author_id = $sub_id; // Bail if somehow this is hooked to an edit action if ( !empty( $is_edit ) ) { return; } // global $bp; // Get autohr 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 ); } // 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, ); bp_notifications_add_notification( $args ); // 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 ); } } } add_action( 'bbp_new_reply', 'bbp_buddypress_add_notification_for_participants', 10, 7 );
Thanks much! Very helpful.
I’m being a little dense with this due to my inexperience. It seems two variable in this function need to be flipped and I’m not figuring out which they are. The notification is showing for the person who makes the reply rather than the person being replied to and it says it’s from the person that the reply is to. So close…
Keep up the good fight! I’m the guy who led @robkk to start the ticket six months ago….
“If someone replies to a post inside a threaded topic and that post was made by the person who created the original topic, then they will get TWO notifications. One will say it’s from the name of the person who replied (good so far) and the second will say it’s from the name of the person getting the notification (and/or OP author).”
My problem is even more basic: when I post threaded topics, and get a bunch of replies, if I then jump in and reply inside, say, 3 times to 3 different people, notifications tells me I have “3 new replies.”
Which I do, in a way–but my short-term memory’s not THAT bad 🙂
I came up with a solution, based on the start @davidstriga made. I’ve been meaning to post it for anyone else having the same issue. I don’t have the same goal he did to notify everyone in a forum, just the person being replied to, so I removed the foreach loop. I also wanted the notification to go to the actual replied-to post in the thread and not just the initial topic at the top of the page. The forum I’m working on has titles on all the replies – but if you aren’t using titles on replies the notification just shows the topic title, but the link still goes to the relevant post/reply.
If anyone is interested, here’s my solution. It’s working great on our site and takes care of the duplicate issues, as well as the GMT timestamp problem.
Put this in your theme’s functions.php
/* notifications */ 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 ) { $current_topic_id = bbp_get_topic_id(); $ids_of_subs = bbp_get_topic_subscribers($current_topic_id); // 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 ); } // pass the $reply_id to the function that formats the notification $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 );
This doesn’t help me, sadly….
Kineta, would you have any insight into my different but related problem?
Here’s what I want to stop happening: when I’ve created a threaded topic, and go in among the various discussants to reply to their replies to me topic, I get notifications of my replies to their replies–I get notifications of my OWN activity.
@veelow – That was exactly the problem I was having. It seems to be generated from the bbPress function: bbp_buddypress_add_notification (notification with your name instead of the person who responded). The code I posted addresses that problem. Did you try it?
Yes, I did. (Sorry for this long delay.)
They don’t solve the case where I am notified of my own activity, when I reply to a replier to my initial topic.
They still fire: a new nunber 1 appears in the bubble.
But your code does erase the text–I get a blank space where the content would appear, and if I click through the text is also invisible–in my list of notifications they appear as blank entries…
After 2 years, this issue has not been fixed. Admin, Please fix this bug
@nguyendungntd21 I agree it’s really driving me and all my users crazy. When I reply to somebody in a topic that I created, I get the notification and they don’t.
Same here. I have got to find a way to notify users when someone replies/quotes their comments.
- You must be logged in to reply to this topic.