From 07f4a46172d84e3ddf84779f571c3852ae2a37a8 Mon Sep 17 00:00:00 2001 From: MS-potilas Date: Tue, 13 Jun 2017 09:05:43 +0300 Subject: [PATCH] New option: mark notifications read New option: mark notifications read instead of clearing (deleting) them --- core/class-bp-notification-widget.php | 33 +++++++++++++++++++++------ 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/core/class-bp-notification-widget.php b/core/class-bp-notification-widget.php index 17c4845..1e9cdf4 100644 --- a/core/class-bp-notification-widget.php +++ b/core/class-bp-notification-widget.php @@ -38,14 +38,13 @@ public function widget( $args, $instance ) { } else { $notifications = bp_core_get_notifications_for_user( get_current_user_id(), 'string' ); } - // will be set to false if there are no notifications. if ( empty( $notifications ) ) { - $count = 0; + $countx = 0; } else { - $count = count( $notifications ); + $countx = count( $notifications ); } - + $count = bp_notifications_get_unread_notification_count(); // do not show this widget. if ( $count <= 0 && empty( $instance['show_empty'] ) ) { return; @@ -64,16 +63,26 @@ public function widget( $args, $instance ) { echo "
"; if ( ! empty( $instance['show_count'] ) ) { + echo ''; printf( __( 'You have %d new Notifications', 'buddypress-notifications-widget' ), $count ); + echo ''; } if ( $instance['show_list'] ) { - self::print_list( $notifications, $count ); + self::print_list( $notifications, $countx ); } if ( $count > 0 && $instance['show_clear_notification'] ) { - $clear_text = __( 'clearing...', 'buddypress-notifications-widget' ); - echo '' . __( '[x] Clear All Notifications', 'buddypress-notifications-widget' ) . ''; + if($instance['mark_read']) { + $clear_text = __( 'marking read...', 'buddypress-notifications-widget' ); + $clear_text_widget = __( '[x] Mark All Notifications Read', 'buddypress-notifications-widget' ); + $clear_all = 'read'; + } else { + $clear_text = __( 'clearing...', 'buddypress-notifications-widget' ); + $clear_text_widget = __( '[x] Clear All Notifications', 'buddypress-notifications-widget' ); + $clear_all = 'true'; + } + echo '' . $clear_text_widget . ''; } echo '
'; @@ -97,6 +106,7 @@ public function update( $new_instance, $old_instance ) { $instance['show_list'] = intval( $new_instance['show_list'] ); $instance['show_clear_notification'] = intval( $new_instance['show_clear_notification'] ); $instance['show_empty'] = intval( $new_instance['show_empty'] ); + $instance['mark_read'] = intval( $new_instance['mark_read'] ); return $instance; } @@ -116,6 +126,7 @@ public function form( $instance ) { 'show_list' => 1, 'show_clear_notification' => 1, 'show_empty' => 0, + 'mark_read' => 0, ) ); @@ -125,6 +136,7 @@ public function form( $instance ) { $show_list = absint( $instance['show_list'] ); // show notification list. $show_clear_notification = absint( $instance['show_clear_notification'] ); $show_empty = absint( $instance['show_empty'] ); + $mark_read = absint( $instance['mark_read'] ); ?>

+

+ +