BuddyDev

Search

[Resolved] notifications component_name

  • Participant
    Level: Enlightened
    Posts: 36
    rav on #24581

    Hello,
    I need help. If I ask in the wrong place, I am sorry for that
    I was looking for help on the internet and on the support page. Unfortunately, nobody helped me. I hope it will be different here.
    I mean BuddyPress Notification Widget.
    I would like the plugin to show only selected notifications with the specified ‘component_name’.
    The ‘component_name’ value is specified when creating the notification and I want to refer to it to check if the notification has the value I need and then show the notification in the widget.
    How to do it? please help

  • Keymaster
    (BuddyDev Team)
    Posts: 24706
    Brajesh Singh on #24600

    Hi Rav,
    Welcome to BuddyDev forums.

    At the moment, BuddyPress does not provide an API to find component specific notifications for user.

    The notification widget is unable to do it. It is still possible to modify the code and use it fopr your purpose

    You will need to change this line

    https://github.com/buddydev/buddypress-notifications-widget/blob/master/core/class-bp-notification-widget.php#L41

    With the code to fetch notifications based on component for the user.

    Regards
    Brajesh

  • Participant
    Level: Enlightened
    Posts: 36
    rav on #24607

    Hi Brajesh Singh,
    Thank you for your answer. Unfortunately, I don’t know how to solve the problem and how to change this code.
    I know that bp_notifications_get_notifications_for_user () allows you to receive notifications for the user, but how to make a notification only from a group?
    Maybe trying to refer to “component_name” and comparing whether the condition is met is a bad way, but I have no other idea. Is there any way?

  • Keymaster
    (BuddyDev Team)
    Posts: 24706
    Brajesh Singh on #24632

    Hi Rav,
    The problem in this case is you need to rewrite whole the notification fetching/parsing.

    It is not a difficult task as you be only modifying the code from the function ‘bp_notifications_get_notifications_for_user’, It is not much use.

    I can share the modified code but I won’t be rewriting the plugin to use that code. Please let me know if you will be able to work from that?

    Thank you
    Brajesh

  • Participant
    Level: Enlightened
    Posts: 36
    rav on #24675

    hi Brajesh Singh
    If you share the modified code I will be very grateful to you. I hope I can handle the implementation.

  • Keymaster
    (BuddyDev Team)
    Posts: 24706
    Brajesh Singh on #24681

    Thank you.

    I will share today.

    Regards
    Brajesh

  • Participant
    Level: Enlightened
    Posts: 36
    rav on #24692

    Thank you
    I will be waiting for your code.

  • Participant
    Level: Enlightened
    Posts: 36
    rav on #24752

    Hi Brajesh Singh,
    Were you able to create this code?

  • Keymaster
    (BuddyDev Team)
    Posts: 24706
    Brajesh Singh on #24769

    Hi,
    Here is the code in 2 parts.

    Part 1:-

    https://gist.github.com/sbrajesh/002257e663d7c5660e0c4be27c781c5d

    This is a copy of ‘bp_notifications_get_notifications_for_user’ with 1 line change

    From

    
    $notifications = bp_get_grouped_notifications_for_user( $user_id );
    

    to

    
    $notifications = bd_custom_get_grouped_notifications_for_user( $user_id, $component_name );
    
    

    Part 2:-
    https://gist.github.com/sbrajesh/d71d88317c649333b9e456bf3ba8cf4f

    As explained in
    https://buddydev.com/support/forums/topic/notifications-component_name/#post-24600

    You will need to replace that function with ‘bd_notifications_get_notifications_for_user’ and appropriate args.

    Regards
    Brajesh

  • Participant
    Level: Enlightened
    Posts: 36
    rav on #24812

    Thank you very much for the code and for the work you have done in writing it. I will try to implement it now. Thanks again.

The topic ‘ [Resolved] notifications component_name’ is closed to new replies.

This topic is: resolved