Support » Plugin: WP Notification Bell » Option to remove/clear notifications

  • Resolved Piotr Kunicki

    (@kuperman87)


    Hello,

    Your plugin is almost perfect for our purposes, but we are publishing a lot of content every week, so we would like to adjust amount of visible notifications (for now I can see only 5 latest?)

    It would be also great to add option for users to remove/clear notifications, maybe is it possible with PRO version, or maybe we can talk about custom modifications?

    Thanks,
    Piotr

Viewing 15 replies - 1 through 15 (of 28 total)
  • Plugin Author wpdever

    (@wpdever)

    Hi,

    You can use this to change the number of notifications inside the box:

    add_filter('wnbell_notifications_display_count','change_notification_count',10);
     function change_notification_count(){
    $count= 7;
    return $count;
     }

    And replace 7 with the count you need.

    For the second question, the closest feature to what you need I have right now is to hide notifications after they were seen by the user. Here’s the code for this :

    add_filter("wnbell_notification_conditions", "add_notification_conditions");
    function add_notification_conditions()
    {
    $condition = "";
        $current_user_id = get_current_user_id();
        $seen_posts = get_user_meta($current_user_id, 'wnbell_seen_notification_post', true);
        if (!$seen_posts) {
            return $condition;
        }
       
        $condition = " AND posts.ID NOT IN(" . wnbell_escape_array($seen_posts) . ") ";
        if(count($seen_posts)>=20){
            $arr = array_slice($seen_posts, -5);
            $last_id = filter_var(max($arr), FILTER_SANITIZE_NUMBER_INT);
    
            $condition .= " AND posts.ID > $last_id ";
        }
    
        return $condition;
    }

    But you can add a delete button using this hook ‘wnbell_item_append’ then you can store the id of that notification in an array in user_meta so you can use it in the previous code instead of the $seen_posts variable.

    Thread Starter Piotr Kunicki

    (@kuperman87)

    Hello,

    Thank you, I have one more question..

    So, i’m using i.e. this code:

    add_filter("wnbell_item_append", "add_wnbell_close_button");
    
    function add_wnbell_close_button() 
    {
    	$out ='<span class="bell_close_btn">X</span>';
    	return $out;
    }

    To add close button next to each notifications, but how can I get notification id?

    Plugin Author wpdever

    (@wpdever)

    Hi,

    You can try this:

    add_filter("wnbell_item_append", "add_wnbell_close_button", 10, 2);
    
    function add_wnbell_close_button($output, $notification_id)
    {
        $out = '<span class="bell_close_btn">X</span>';
        $out .= $notification_id;
        return $out;
    }
    Thread Starter Piotr Kunicki

    (@kuperman87)

    Hi,

    Thank you, it works 🙂
    So now I need to use AJAX and add this notification id to user meta when user clicks on “X” button, right?
    Can I use any plugin function for this?

    Thanks,
    Piotr

    Plugin Author wpdever

    (@wpdever)

    Hi,

    There’s no function to help with that. You can search for onclick="wnbell_ajax_seen in the plugin code, and the wnbell_ajax_seen function to see how I save clicked notifications and get an idea on how to write similar functions.

    Thread Starter Piotr Kunicki

    (@kuperman87)

    Hi,

    Thanks for all, I was able to adjust functions from your plugin and option to remove notification works now..

    I have one more question, we would like to use different color/background for different type of notification, (comments, custom post type published etc.) is it possible to add i.e. different classes into “wnbell_notification_item” div?

    Great support,
    thanks,
    Piotr

    Thread Starter Piotr Kunicki

    (@kuperman87)

    @wpdever unfortunately I’ve noticed one more issue..
    When there’s new comment notification, this filter doesn’t work

    add_filter("wnbell_item_append", "add_wnbell_close_button", 10, 2);
    
    function add_wnbell_close_button($output, $notification_id)
    {
        $out = '<span class="bell_close_btn">X</span>';
        $out .= $notification_id;
        return $out;
    }
    

    So, the close button is visible for other notifications, but not for the one with the comment, is it possible to change it?

    Thanks,
    Piotr

    Plugin Author wpdever

    (@wpdever)

    Hi,

    The filter for user notifications (comments, bbpress, woocommerce…) is called ‘wnbell_user_item_append’. You can do something similar:

    add_filter("wnbell_user_item_append", "add_wnbell_close_button_comments", 10, 3);
    
    function add_wnbell_close_button_comments($output, $notification_id, $trigger_type)
    {
        $out = '<span class="bell_close_btn">X</span>';
        $out .= $notification_id;
        return $out;
    }

    For the css class for the user notification item, I’ll add it in the next update (note that it’ll apply for all user notifications (comments, bbpress…) as it’s the same box).

    Thread Starter Piotr Kunicki

    (@kuperman87)

    For the css class for the user notification item, I’ll add it in the next update (note that it’ll apply for all user notifications (comments, bbpress…) as it’s the same box).

    – Thank you for this modification with user notifications, it’s not possible to add also different class for post notification? We would like to have all new posts/custom post types notification in another color..

    Thread Starter Piotr Kunicki

    (@kuperman87)

    @wpdever last question I think 🙂

    Regarding your first answer with the function and filter:

    add_filter("wnbell_notification_conditions", "add_notification_conditions");
    function add_notification_conditions()...
    

    It’s fine with default notifications, but it doesn’t work with user (comment) notifications, so if I click the notification, refresh the page, this comment notification is still visible, is it possible to change it?

    Thanks,
    Piotr

    Plugin Author wpdever

    (@wpdever)

    Hi,

    I’ve added the css class “wnbell_user_item” in the latest update to style user notifications.

    This hook “wnbell_notification_conditions” only works with the default/post/cpt notifications, instead there’s this code that deletes comment notifications after they were viewed by the user, you can modify it to work with the delete button, and add it to your theme’s functions.php file or a custom plugin:

    add_action(‘wnbell_add_unseen’, ‘delete_seen_callback’,11,1);
    function delete_seen_callback($notification_id){
    $current_user_id = get_current_user_id();
    $user_meta_field = ‘wnbell_unseen_comments’;
    $unseen_array = get_user_meta($current_user_id, $user_meta_field, true);
    if (!$unseen_array) {
    $unseen_array=array();
    }
    foreach($unseen_array as $key=>$notification){
    if($notification[‘type’]===’cfc’ && $notification[‘comment_id’]==$notification_id){
    //unset
    unset($unseen_array[$key]);
    }
    }
    update_user_meta($current_user_id, ‘wnbell_unseen_comments’, $unseen_array);
    
    }
    Thread Starter Piotr Kunicki

    (@kuperman87)

    Hi @wpdever

    Thank you for the update and information about comment notifications..

    I’ve noticed one more issue.
    I’m using this filter:

    add_filter('wnbell_notifications_display_count','change_notification_count',10);
     function change_notification_count(){
    $count= 20;
    return $count;
     }

    to display 20 notifications at once and it works, but if I click i.e. 10 notification’s “remove” button it doesn’t work properly.. it looks like only 7 are added into “seen_posts” array, i’m checking it with this code:

    $seen_posts = get_user_meta($current_user_id, 'wnbell_seen_notification_post', true); 
    var_dump($seen_posts);

    and instead of 10 array element, i can see only 7 – is it possible to change this limit?

    Thanks,
    Piotr

    Thread Starter Piotr Kunicki

    (@kuperman87)

    Hi @wpdever any news regarding me latest question?

    I’ve noticed one more thing, we have a lot of notifications now and when new user create an account, he can see all old notification.. I think it’s not correct and new user shouldn’t see old notifications (published before account creation) am I wrong?

    Thanks for all,
    Piotr

    Plugin Author wpdever

    (@wpdever)

    Hi,

    About the issue of the seen_posts array, the “wnbell_seen_notification_post” should store 20 ids so I’m not sure why it’s only storing 7. But regardless, it might be better to create your own user_meta instead of “wnbell_seen_notification_post” to have better control over it (particularly since this one is updated when the link is clicked while you need to update your value when the clear button is clicked).

    About old notifications, the count on the bell is set to 1 if 1 or many notifications already exist when the user creates an account, but they can see all notifications since some sites might want to show older notifications (older posts, calls to subscribe to a newsletter… ). It would suit most use cases I believe.
    Also, since you mention a large number of notifications, you might want to delete older ones (from a few months ago…) manually to reduce the cost on your servers (and since users might not need to see those).

    Thread Starter Piotr Kunicki

    (@kuperman87)

    Hi @wpdever

    Thanks for the answer..

    Regarding the seen_posts array, so it should store 20 ids and this limit may be increased?

    Regarding old notifications, so it’s not possible to adjust it and disable showing old notifications to new users?

    I think we just have noticed one more issue, it looks like the order of displayed notifications is taken from draft (not from publishing dates). We have some notifications with draft status, after that we’ve published other notifications and when we changed old notifications status from draft to published -it’s not the latest visible in the dropdown..

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