[Solved] What are the correct action and filter hooks for comment notifications?
-
I have been customizing the way my notifications are shown and have split them out from the main notifications bubble, so far i have managed to do this via these hooks/filters
bp_friend_get_total_requests_count
bp_notifications_get_unread_notification_count
messages_get_unread_countNow i don’t know the ones that relate specifically to the comment notifications a user receives when someone replies or comments on their status update etc, any ideas?
-
Hey @mcpeanut
bp_friend_get_total_requests_count(), bp_notifications_get_unread_notification_count() and messages_get_unread_count() are actually functions. I do believe each returns a count. Regarding comments, are you looking for a function that gets the comment count?
hey @henrywright good to hear from you again its been a while bud, thx for chiming in on this, ahh cool i referred to them as action and filter hooks based on this post at http://etivite.com/api-hooks/ Miss-understanding.
In short yes i am, I have found this function bp_activity_get_comment_count() but it seems to bring the total count a user has made, where as im looking for a function that shows a count if someone replies to an activity update you posted then once you have viewed the update it would reset.
Ah right! That seems to be quite an old resource, goes back to BuddyPress 1.5, I think.
Yeah, bp_activity_get_comment_count() will return the comment count for a particular activity item.
Sounds like you’re looking for a ‘notification’ count for activity comments? So for example, if I comment on an activity you’ve posted, the count will be 1. If two people comment on an activity you’ve posted, the count will be 2. At some point in time, you log in and view these which results in the count being reset to 0. Is that what you’re looking for? If so, as far as I know, there’s nothing like that available currently. You could always open a request on Trac asking for the functionality to be added?
@henrywright Yes that’s exactly it! That’s why i posted here asking i was scratching my head trying to find this function lol, basically what i am trying to do is split “everything” out from the Notification bubble not just friends requests etc because im disabling the buddypresss/wordpress bar completely from users.
so far ive managed to create a menu system that has ‘pending friend requests, group invites, unread messages, total of friends, group total, and all notifications, i have yet to do the @mentions for when you receive a new @mention, do you by offchance know the function for this?
I can get the total mention count using this function bp_get_total_mention_count_for_user (); but i am after the function that lets me get the count of mentions i haven’t viewed yet.
Example: in the notifications bubble in the wordpress/buddypress bar if you get mentioned 3 times it will say you have 3 new mentions when you click it and read the mentions it will clear, This is the function i need to find the name of now.
Like the comment count, I’m not sure there’s anything for mentions either. The function responsible for outputting the count you currently see for ‘unseen’ mentions is
bp_activity_format_notifications()
. It accepts 5 parameters, one of them being$total_items
. That variable is what’s used when outputting the text “You have X new mentions”.But again, to my knowledge, there isn’t currently anything available ‘stand-alone’ that will do the job for you.
Hope this helps?
ty @henrywright! I will try it, what are the other 4 parameters? This is the last challenge and then my menu notification system is finished.
For example with pending friends request im using this
see function at line 389 bp-activity-notifications.php
about friendship: see bp-friends-functions.php
Tip: for your custom work, use notepad++ which comes with a powerfull search engine aside many other tools.
yes ty @danbp i use notepad++, as you can see i have been sticking my head into learning all this as much as i can at the minute.
I see nothing, but glad you got it 😉
HAHA you know what i meant by that lololol
what are the other 4 parameters?
They won’t help because it’s the count that you really need, and that is passed to the function. Everything else in the function is useless with reference to what you want to do.
To see how it all works, take a look at the BP core code, the notifications component section in particular:
https://github.com/buddypress/BuddyPress/tree/master/src/bp-notifications
You may find a function has already been written but my guess is you’re pioneering the way on this, and therefore would have to write something yourself (or open a functionality request ticket on Trac).
@henrywright using this bp_activity_format_notifications( $user_id = 0 ); i have got the mentions to show in the dropdown but without the username of who mentioned you until you hover over it, there is no count though.
scrap that! no i haven’t , it is just a link that takes me to my profile and shows all my mentions using it like that haha, like i said im learning and having a good play around, i suppose like you said @henrywright there is no point trying to do something there isnt a function for, but playing around helps me learn (slowly), everything else works good though so i might scrap trying to pull the mentions in separately.
More about this:
and an example used by bbpress
https://bbpress.trac.wordpress.org/browser/tags/2.5.3/includes/extend/buddypress/notifications.phpcheers again @danbp keep em coming lol so i can read them all, i will get better at all this.
Hey @danbp
More about this:
https://codex.buddypress.org/developer/function-examples/bp_notifications_add_notification/
@mcpeanut isn’t trying to add a new notification, instead the aim is to get the ‘unseen’ mention count.You could also study this plugin and see how it’s made…
i mentionned the codex page because it shows the arrays to filter on.
'component_action' => 'new_at_mention', 'is_new' => 1,
‘is_new’
(optional) Whether the notification is new. This will be set to 0 once the notification is viewed by the recipient.See bp_notifications_toolbar_menu function (bp-notifications-adminbar.php:20)
@danbp and @henrywright ty for your help on this i have a good lot of reading/studying to do now, will get my head into all the links and info and get back to you, cheers.
Wish you a nice monday, tuesday,…. week 😛
Haha sounds about right! lol
@danbp right, I see what you mean! 🙂
Hey again @mcpeanut,
I’ve had a little bit more time this evening to look at this for you. I found that the notifications component provides a public static method
get_total_count()
which can be used to get the unseen mention count. You can use it like this:$query_vars = array( 'user_id' => get_current_user_id(), 'component_action' => 'new_at_mention', 'is_new' => true ); $count = BP_Notifications_Notification::get_total_count( $query_vars ); echo $count;
Hope that does the trick!
@henrywright YOU MY FRIEND ARE A STAR! 🙂 This is exactly what i was looking for and can confirm its working for me, i have now got the mentions split out with the number of mentions displayed and working correctly, thankyou very much henry!!!! also thankyou very much @danbp for your help. This is resolved! cheers.
Oh one last thing henry it turns out i didnt need to use the echo $count; at the end because it was causing it to echo 4 times on the page, but removing it seemed to fix the problem and the count is still showing.
So the final code i used was
$query_vars = array( 'user_id' => get_current_user_id(), 'component_action' => 'new_at_mention', 'is_new' => true ); $count = BP_Notifications_Notification::get_total_count( $query_vars )
ty once again henry.
- You must be logged in to reply to this topic.