243e6882 by Marty Penner

Ensure the right language is used when sending notifications

1 parent 59f86b07
...@@ -216,8 +216,8 @@ function send_triggered_notification($uid = 0, $trigger = 'NO_TRIGGER', $args = ...@@ -216,8 +216,8 @@ function send_triggered_notification($uid = 0, $trigger = 'NO_TRIGGER', $args =
216 /** @var \wpdb $wpdb */ 216 /** @var \wpdb $wpdb */
217 global $wpdb; 217 global $wpdb;
218 218
219 // LANGTODO: get this from the user's preference. As it stands, if an admin triggers this, the notification will be in whatever language the admin is viewing the page as 219 $user = new User\Account($uid);
220 $lang = ICL_LANGUAGE_CODE; 220 $lang = $user->getPreferredLanguage();
221 221
222 /** @var \StdClass $notification */ 222 /** @var \StdClass $notification */
223 $notification = get_notification_by_trigger($trigger); 223 $notification = get_notification_by_trigger($trigger);
...@@ -265,13 +265,11 @@ function send_triggered_notification($uid = 0, $trigger = 'NO_TRIGGER', $args = ...@@ -265,13 +265,11 @@ function send_triggered_notification($uid = 0, $trigger = 'NO_TRIGGER', $args =
265 } elseif ($uid == 0 && isset($args['email'])) { 265 } elseif ($uid == 0 && isset($args['email'])) {
266 $toEmail = $args['email']; 266 $toEmail = $args['email'];
267 } else { 267 } else {
268 268 $emailAddressPreference = get_user_meta($user->ID, 'email_address_preference', true);
269 $user = new User\Account($uid); 269 if (empty($emailAddressPreference)) {
270 $email_address_preference = get_user_meta($user->ID, 'email_address_preference', true);
271 if (empty($email_address_preference)) {
272 $toEmail = $user->user_email; 270 $toEmail = $user->user_email;
273 } else { 271 } else {
274 $pp = strtolower($email_address_preference).'_'; 272 $pp = strtolower($emailAddressPreference).'_';
275 $toEmail = get_user_meta($user->ID, $pp.'email', true); 273 $toEmail = get_user_meta($user->ID, $pp.'email', true);
276 274
277 if (empty($toEmail)) { 275 if (empty($toEmail)) {
......