Skip to:
Content
Pages
Categories
Search
Top
Bottom

get notification_id in bp_notifications_get_notifications_for_user to delete it


  • pauapau
    Participant

    @pauapau

    hey guys,
    when the user have read/clicked on a notification then the notifitcation should automatically delete. i want to do that with a ajax call.

    so my idea is to add a filter on the function bp_notifications_get_notifications_for_user() to manipulate the output.
    but i need for the ajax call a notification_id. so that he knows which notofiation he has to delete.

    add_filter( 'bp_notifications_get_notifications_for_user', 'bp_follow_notify_format_notifications', 9, 5  );
    function bp_follow_notify_format_notifications( $action, $item_id, $secondary_item_id, $total_items, $format = 'string' ) {
    		
    	if ( 'follow_new_post' === $action ) {
    		
    		if ( (int) $total_items > 1 ) {
    			$title = sprintf( __( '%d new posts have been published', 'bp-follow-notify' ), (int) $total_items );
    			$link  = bp_get_notifications_permalink();
    		} else {
    			$title = sprintf( __( '%s is kiteboarding.', 'bp-follow-notify' ), bp_core_get_user_displayname( $secondary_item_id ) );
    			$link = get_permalink( $item_id );			
    		}
    		
    		// WordPress Toolbar
    		if ( 'string' === $format ) {
    			$return = apply_filters('bp_follow_notify_notification', '<div onClick="clickedOnNotification('.$notificationID.')" title="' . esc_attr( $title ) . '">' . esc_html( $title ) . '"</div>', $title, site_url().$link );
    		
    		// Deprecated BuddyBar
    		} else {
    			$return = apply_filters( 'bp_follow_notify_notification', array(
    				'text' => $title,
    				'link' => $link
    			), $link, (int) $total_items, $title, $title );
    		}
    		
    		return $return;
    	}
    	return $action;
    }
    

    here is the important line.
    $return = apply_filters('bp_follow_notify_notification', '<div onClick=”clickedOnNotification(‘.$notificationID.’)”title="' . esc_attr( $title ) . '">' . esc_html( $title ) . '"</div>', $title, site_url().$link );

    cheers Pau

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

  • pauapau
    Participant

    @pauapau

    sorry posted in the wrong subforum.
    can you please change it.


    craig334
    Participant

    @craig334

    function custom_filter_notifications_get_registered_components( $component_names = array() ) {

    // Force $component_names to be an array
    if ( ! is_array( $component_names ) ) {
    $component_names = array();
    }

    // Add ‘custom’ component to registered components array
    array_push( $component_names, ‘custom’ );

    // Return component’s with ‘custom’ appended
    return $component_names;
    }
    add_filter( ‘bp_notifications_get_registered_components’, ‘custom_filter_notifications_get_registered_components’ );


    pauapau
    Participant

    @pauapau

    Hey,
    Thank you for your help.
    But why should I have to register a component?

    I just need the notification-Id.

    Thank you.

    Cheers pau

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