bpln_get_new_notifications

Get all new notifications after a given time for the current user.

Description

bpln_get_new_notifications( (type) $user_id, (type) $last_notified ); 

Parameters (2)

0. $user_id (type)
The user id.
1. $last_notified (type)
The last notified.

Usage

  1. if ( !function_exists( 'bpln_get_new_notifications' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress-live-notification/functions.php'; 
  3.  
  4. // The user id. 
  5. $user_id = null; 
  6.  
  7. // The last notified. 
  8. $last_notified = null; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = bpln_get_new_notifications($user_id, $last_notified); 
  12.  

Defined (1)

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

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