Skip to:
Content
Pages
Categories
Search
Top
Bottom

Notification Management

  • Avatar of colabsadmin
    colabsadmin
    Participant

    @colabsadmin

    Has anyone worked out a way to mass manage the notification listing in your profile? Deleting them one at a time is a pain. I know the ‘Bp Clear Notifications’ plug adds a link in the admin bar to clear them all so maybe I’ll look at hacking that. But just wondering if anyone else has seen something around.

Viewing 7 replies - 1 through 7 (of 7 total)
  • Avatar of henrywright
    henrywright
    Moderator

    @henrywright

    I’m using a mark all as read button but it’s customised for my site markup so might not play well elsewhere. What part are you stuck with?

    Avatar of colabsadmin
    colabsadmin
    Participant

    @colabsadmin

    @henry

    I haven’t started so I’m not stuck yet. I think I’m going to code in a check box for each notification like you have done, and also a filter to only display certain notifications.

    Along with this, I’ll try to add a section to the profile settings that will allow a member to pick what they get notified on, similar to the way you can choose email notifications.

    I was just seeing if anyone has tackled this before I set out to do it. I would appreciate seeing your code if you want to post it.

    thanks!

    Avatar of henrywright
    henrywright
    Moderator

    @henrywright

    That sounds like a better approach than mine. I just have a rather crude looking button which marks as read all unread notifications.

    bp_notifications_mark_notifications_by_type is the function I’m using to do the marking. For example:

    if ( bp_is_active( 'notifications' ) ) {
        bp_notifications_mark_notifications_by_type( bp_loggedin_user_id(), buddypress()->messages->id, 'new_message' );
        bp_notifications_mark_notifications_by_type( bp_loggedin_user_id(), buddypress()->activity->id, 'new_at_mention' );
    }
    Avatar of colabsadmin
    colabsadmin
    Participant

    @colabsadmin

    Not sure when I’ll start this (soon), but I’ll report back with details on what I come up with. Thanks for the code.

    Avatar of colabsadmin
    colabsadmin
    Participant

    @colabsadmin

    I’ve been playing around with the filtering aspect. Turns out Buddypress has a filter built in, so all you need to do is add a form (dropdown) to use it. I haven’t fully tested this but seems to work. I need a way to determine all possible notification component names and actions so it will autopopulate the dropdown when new plugins use notifications.

    I copied /plugins/buddypress/bp-template/members/single/notifications.php to my child theme and added the following right below the bp_notifications_sort_order_form call

    <li id="members-filter-select" class="last filter">
    	<?php qd_notifications_filter_form(); ?>
    </li>

    Then in my functions.php file, I added the dropdown code (I basically stole this from the code that generates the sort by date dropdown.

    
    function qd_notifications_filter_form() {
    
    	// Setup local variables
            // Need to figure out a way to autopopulate this array
    	$searchterms   = array( 'new_at_mention', 'bbp_new_reply','new_message','friendship_accepted','friendship_request','group_invite','localgroupnotifier','ac_notifier' );
    	$selected = '';
    
    	// Check for a custom sort_order
    	if ( !empty( $_REQUEST['s'] ) ) {
    		if ( in_array( $_REQUEST['s'], $searchterms ) ) {
    			$selected = $_REQUEST['s'];
    		}
    	} ?>
    
    	<form action="" method="get" id="notifications-filter">
    		<label for="notifications-filter-list"><?php esc_html_e( 'Filter By:', 'buddypress' ); ?></label>
    
    // need to loop through this instead of hardcoding the options.
    		<select id="notifications-filter-list" name="s" onchange="this.form.submit();">
            	<option value="" <?php selected( $selected, '' ); ?>><?php _e( 'All', 'buddypress' ); ?></option>
    			<option value="new_at_mention" <?php selected( $selected, 'new_at_mention' ); ?>><?php _e( 'Mentions', 'buddypress' ); ?></option>
    			<option value="bbp_new_reply"  <?php selected( $selected, 'bbp_new_reply'  ); ?>><?php _e( 'Forums', 'buddypress' ); ?></option>
                <option value="new_message"  <?php selected( $selected, 'new_message'  ); ?>><?php _e( 'Messages', 'buddypress' ); ?></option>
                <option value="ac_notifier"  <?php selected( $selected, 'ac_notifier'  ); ?>><?php _e( 'Activity', 'buddypress' ); ?></option>
                <option value="localgroupnotifier"  <?php selected( $selected, 'localgroupnotifier'  ); ?>><?php _e( 'Groups', 'buddypress' ); ?></option>
                <option value="friendship_accepted"  <?php selected( $selected, 'friendship_accepted'  ); ?>><?php _e( 'Friend Accepts', 'buddypress' ); ?></option>
                <option value="friendship_request"  <?php selected( $selected, 'friendship_request'  ); ?>><?php _e( 'Friend Requests', 'buddypress' ); ?></option>
    		</select>
    
    		<noscript>
    			<input id="submit" type="submit" name="form-submit" class="submit" value="<?php _e( 'Go', 'buddypress' ); ?>" />
    		</noscript>
    	</form>
    
    <?php
    }
    
    Avatar of colabsadmin
    colabsadmin
    Participant

    @colabsadmin

    I found bp_notifications_get_registered_components() which will bring back an array “of component names that are currently active and have registered Notifications callbacks”.

    Updated code

    
    function qd_notifications_filter_form() {
    	// Setup local variables
    	$components   = bp_notifications_get_registered_components();
    	$selected = '';
    	
    
    	// Check for a filter
    	if ( !empty( $_REQUEST['s'] ) ) {
    		if ( in_array( $_REQUEST['s'], $components ) ) {
    			$selected = $_REQUEST['s'];
    		}
    	} ?>
    
    	<form action="" method="get" id="notifications-filter">
    		<label for="notifications-filter-list"><?php esc_html_e( 'Filter By:', 'buddypress' ); ?></label>
    
    		<select id="notifications-filter-list" name="s" onchange="this.form.submit();">
            	<option value="" <?php selected( $selected, '' ); ?>><?php _e( 'All', 'buddypress' ); ?></option>
                <?php
                foreach ($components as $component) {
                ?>
                	<option value="<?php echo $component; ?>" <?php selected( $selected, $component ); ?>><?php _e( $component, 'buddypress' ); ?></option>
                <?php
                }
    			?>
    			
    		</select>
    
    		<noscript>
    			<input id="submit" type="submit" name="form-submit" class="submit" value="<?php _e( 'Go', 'buddypress' ); ?>" />
    		</noscript>
    	</form>
    
    <?php
    }
    

    Still not perfect, but better.

    Avatar of colabsadmin
    colabsadmin
    Participant

    @colabsadmin

Viewing 7 replies - 1 through 7 (of 7 total)

You must be logged in to reply to this topic.