bpln_get_latest_notification_id

Get the last notification id for the user.

Description

bpln_get_latest_notification_id( (bool) $user_id = false ); 

Parameters (1)

0. $user_id — Optional. (bool) => false
The user id.

Usage

  1. if ( !function_exists( 'bpln_get_latest_notification_id' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress-live-notification/functions.php'; 
  3.  
  4. // The user id. 
  5. $user_id = false; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = bpln_get_latest_notification_id($user_id); 
  9.  

Defined (1)

The function is defined in the following location(s).

/functions.php  
  1. function bpln_get_latest_notification_id( $user_id = false ) { 
  2.  
  3. if ( ! $user_id ) { 
  4. $user_id = get_current_user_id(); 
  5.  
  6. global $wpdb; 
  7.  
  8. $bp = buddypress(); 
  9.  
  10. $table = $bp->notifications->table_name; 
  11.  
  12. $registered_components = bp_notifications_get_registered_components(); 
  13.  
  14.  
  15. $components_list = array(); 
  16.  
  17. foreach ( $registered_components as $component ) { 
  18. $components_list[] = $wpdb->prepare( '%s', $component ); 
  19.  
  20. $components_list = implode( ', ', $components_list ); 
  21.  
  22.  
  23. $query = "SELECT MAX(id) FROM {$table} WHERE user_id = %d AND component_name IN ({$components_list}) AND is_new = %d "; 
  24.  
  25. $query = $wpdb->prepare( $query, $user_id, 1 ); 
  26.  
  27. return (int) $wpdb->get_var( $query );