bp_gifts_send_gifts_notification

Notification functions are used to send email notifications to users on specific events.

Description

bp_gifts_send_gifts_notification( $to_user_id, $from_user_id ); 

They will check to see the users notification settings first, if the user has the notifications

turned on, they will be sent a formatted email notification.

You should use your own custom actions to determine when an email notification should be sent.

Parameters (2)

0. $to_user_id
The to user id.
1. $from_user_id
The from user id.

Usage

  1. if ( !function_exists( 'bp_gifts_send_gifts_notification' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress-gifts-latest-2014/includes/bp-gifts-notifications.php'; 
  3.  
  4. // The to user id. 
  5. $to_user_id = null; 
  6.  
  7. // The from user id. 
  8. $from_user_id = null; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = bp_gifts_send_gifts_notification($to_user_id, $from_user_id); 
  12.  

Defined (1)

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

/includes/bp-gifts-notifications.php  
  1. function bp_gifts_send_gifts_notification( $to_user_id, $from_user_id ) { 
  2.  
  3. global $bp; 
  4.  
  5.  
  6.  
  7. /** Let's grab both user's names to use in the email. */ 
  8.  
  9. $sender_name = bp_core_get_user_displayname( $from_user_id, false ); 
  10.  
  11. $reciever_name = bp_core_get_user_displayname( $to_user_id, false ); 
  12.  
  13.  
  14. if ( 'no' == get_usermeta( (int)$to_user_id, 'notification_gifts_received' ) ) 
  15.  
  16. return false; 
  17.  
  18.  
  19.  
  20. /** Get the userdata for the reciever and sender, this will include usernames and emails that we need. */ 
  21.  
  22. $reciever_ud = get_userdata( $to_user_id ); 
  23.  
  24. $sender_ud = get_userdata( $from_user_id ); 
  25.  
  26.  
  27.  
  28. /** Now we need to construct the URL's that we are going to use in the email */ 
  29.  
  30. //$sender_profile_link = site_url( BP_MEMBERS_SLUG . '/' . $sender_ud->user_login . '/' . $bp->profile->slug ); 
  31.  
  32. $sender_profile_link = trailingslashit( bp_get_root_domain() . '/' . bp_get_members_root_slug() . '/' . $sender_ud->user_login . '/' . $bp->profile->slug ); 
  33.  
  34.  
  35. $sender_gifts_link = trailingslashit( bp_get_root_domain() . '/' . bp_get_members_root_slug() . '/'. $sender_ud->user_login . '/'. 'gifts' ); 
  36.  
  37.  
  38. $reciever_gifts_link = trailingslashit( bp_get_root_domain() . '/' . bp_get_members_root_slug() . '/' . $reciever_ud->user_login . '/' . 'gifts' ); 
  39.  
  40.  
  41. $reciever_settings_link= trailingslashit( bp_get_root_domain() . '/' . bp_get_members_root_slug() ); 
  42. $reciever_settings_link .= $reciever_ud->user_login . '/settings/notifications' ; 
  43.  
  44.  
  45. /** Set up and send the message */ 
  46.  
  47. $to = $reciever_ud->user_email; 
  48.  
  49. $subject = '[' . get_blog_option( 1, 'blogname' ) . '] ' . sprintf( __( '%s send gifts to you!', 'bp-gifts' ), stripslashes($sender_name) ); 
  50.  
  51.  
  52.  
  53. $message = sprintf( __(  
  54.  
  55. '%s sent you a new gifts! Why not send one back? 
  56.  
  57.  
  58.  
  59. Check your new gifts: %s 
  60.  
  61.  
  62.  
  63.  
  64.  
  65. To see %s\'s profile: %s 
  66.  
  67.  
  68.  
  69. To send %s a gifts: %s 
  70.  
  71.  
  72.  
  73. --------------------- 
  74.  
  75. ', 'bp-gifts' ), $sender_name, $reciever_gifts_link, $sender_name, $sender_profile_link, $sender_name, $sender_gifts_link ); 
  76.  
  77.  
  78.  
  79. $message .= sprintf( __( 'To disable these notifications please log in and go to: %s', 'bp-gifts' ), $reciever_settings_link ); 
  80.  
  81.  
  82.  
  83. // Send it! 
  84.  
  85. wp_mail( $to, $subject, $message ); 
  86.