Option to remove/clear notifications
-
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
-
Hi again,
It’s not the perfect solution because require plugin modifications but if someone is interested I was able to disable showing old notifications to new users..
Fisrt I’m checking the current user registration date (local time):
$registered = date('Y-m-d H:i:s', strtotime($udata->user_registered)); $local_registered = get_date_from_gmt( $registered, 'Y-m-d H:i:s' );
then I’m adjusted the query which selects all notifications from database by adding this additional condition:
AND posts.post_date > '{$local_registered}'
it works, but I still can see count “1” on the bell, is it possible to hide it?
Hi @wpdever,
I was able to fix other issues, but still have a problem with notifications order..
I thinks there’s a problem with the correct order. Here’s the case:
1. I create new post (draft) with ex. title “First Post”
2. I create another post (draft) with ex. title “Second Post”
3. Now I change “Second Post” content and publish it
4. Finally I change “First Post” content and publish it.So the latest published post is “First post” and it should be visible as the first notification, right? Unfortunately the first notification is from “Second Post”, so I assume that the draft creation date is taken here..
Are you able to reproduce the issue?
Thanks,
PiotrHi,
Thanks for sharing the solution to hide old notifications. You can use the ‘wnbell_notification_conditions’ filter hook to make changes in your functions.php file instead of modifying the code:
add_filter('wnbell_notification_conditions','add_notification_conditions',10); function add_notification_conditions(){ $registered = date('Y-m-d H:i:s', strtotime($udata->user_registered)); $local_registered = get_date_from_gmt( $registered, 'Y-m-d H:i:s' ); $query =" AND posts.post_date > '$registered' "; return $query; }
I was not able to reproduce the notification order issue. Notifications use the ‘post_date’ in the posts table which should be the publish date. Also, when I follow the steps, “First post” is the first notification in the list.
Is it possible you could have some code that changes the post_date value for some reason?Hi @wpdever
Thanks for the condition filter.
Regarding the order issue – I’ll show you screenshots and I’ve added fresh plugin files without any modifications and also removed all filters from theme’s functions.php file..
I’ve created two blog post drafts:
https://assets.tuning4web.com/1_284963EF.pngand when I check notification bell, there are also two drafts:
https://assets.tuning4web.com/2_28496441.png (dates are the same).Now, after few minutes I’ve edited and publish 2nd post and after another few minutes publish 1st post.. so it looks like here:
https://assets.tuning4web.com/3_2849653A.pngbut when I check Notification Bell, the order is wrong:
https://assets.tuning4web.com/4_28496591.png (dates are the same as on first two screenshots and it’s not correct)On the front – the order is also not correct, the first (top) notification is from 2nd post..
https://assets.tuning4web.com/5_2849662B.pngThe problem is here I think (please compare two following screenshots):
https://assets.tuning4web.com/2_28496441.png
https://assets.tuning4web.com/4_28496591.png
Draft last modified date is the same as published date but in real these dates are different..Hi,
I was testing the notifications instead of the posts.
You can add this in your functions.php file, if it works I’ll add it in the next update (so you can remove it then):
add_action('transition_post_status', 'wnbelltest_first_publish_time_register', 10, 3); function wnbelltest_first_publish_time_register($new, $old, $post) { if ($new == 'publish' && $old != 'publish' && $post->post_type == 'wnbell_notifications') { $firstPublishTime = get_post_meta($post->ID, 'first_publish_time', true); if (empty($firstPublishTime)) { // First time the post is publish, register the time add_post_meta($post->ID, 'first_publish_time', time(), true); $time = strtotime("now"); $my_post = array( 'ID' => $post->ID, 'post_date' => date('Y-m-d H:i:s', $time), 'post_date_gmt' => gmdate('Y-m-d H:i:s', $time), ); wp_update_post($my_post); } } }
Hi @wpdever
It’s me again ??
Your code fixed the order but I’m afraid that there’s another problem now..
When there are no “unseen” notifications I can see “1” on the icon bell all the time..
It happens only when the order is disturbed (so I publish lesson draft, second draft etc, and publish the second draft first, like I described above with the screenshots).
In this case I can see:
console.log(data.unseen_notification);
1
in the console.. when I click the bell icon I can see “0” and it’s correct but when I click the bell icon again I can see “1”, even if there are no unseen notifications..I hope you are able to reproduce the issue..
Thanks,
PiotrHi @wpdever,
Any news regarding my previous question? Are you able to reproduce the issue?
Thanks,
PiotrHi,
Can you add this to your functions.php file?
add_action('wnbell_notifications_processed', 'add_last_date'); function add_last_date() { $current_user_id = get_current_user_id(); $time = strtotime("now"); update_user_meta($current_user_id, 'wnbell_last_seen_date', gmdate('Y-m-d H:i:s', $time)); } add_filter('wnbell_notification_count_conditions', 'add_notification_conditions', 10); function add_notification_conditions() { $user_last_seen = get_user_meta($user_id, 'wnbell_last_seen_date', true); $query = " AND posts.post_date_gmt > '$local_last' "; return $query; }
Also, I’ll be including this in the next update but I’m not sure when it’ll be so in the meantime, you can go to includes/menu_bell.php file, find the $count_query variable and change it with this:
$count_query = "SELECT count(*) from (select posts.ID from {$wpdb->prefix}posts AS posts LEFT JOIN {$wpdb->prefix}wnbell_recipients_role AS prole ON (posts.ID=prole.notification_id) LEFT JOIN {$wpdb->prefix}wnbell_recipients AS pname ON (posts.ID=pname.notification_id) WHERE posts.post_type = 'wnbell_notifications' AND posts.post_status = 'publish' AND posts.ID>%d AND (prole.user_role IN(" . wnbell_escape_array($roles) . ") OR prole.user_role IS NULL) AND (pname.usernames IS NULL)"; $count_query .= apply_filters("wnbell_notification_count_conditions", ''); $count_query .= " GROUP BY posts.ID ORDER BY posts.post_date DESC LIMIT 100) as subquery;";
Hi @wpdever
Thanks, I’ve added the code into theme’s functions.php file and modified the query from includes/menu_bell.php file but unfortunately it still doesn’t work..
It’s better now, because when I click the bell icon I can see “0”, when I click the bell icon again I still can see “0” so it’s fine.. but i see “1” again when I refresh the page..
Piotr Kunicki `Piotr Kunicki, how are you?
I apologize if any sentence is strange, I’m translating from Portuguese with google translator.
I sent you a message via facebook, I need help with customizing this plugin on my page, are you available for this job?
wpdever, if Piotr is not available, do you have any indication?
I’m waiting!`
Hi @wpdever,
Unfortunately I’ve noticed one more issue.. regarding the comments notifications removing – i’m using your function:
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); }
and it works fine with comments answered (cfc type), but unfortunately it doesn’t work with ‘cfa’ type (post authors comments).
I’ve tried to change this condition into:
if(($notification['type']==='cfc' || $notification['type']==='cfa') && $notification['comment_id']==$notification_id){
but unfortunately it doesn’t work..
- The topic ‘Option to remove/clear notifications’ is closed to new replies.