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 =
/** @var \wpdb $wpdb */
global $wpdb;
// 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
$lang = ICL_LANGUAGE_CODE;
$user = new User\Account($uid);
$lang = $user->getPreferredLanguage();
/** @var \StdClass $notification */
$notification = get_notification_by_trigger($trigger);
......@@ -265,13 +265,11 @@ function send_triggered_notification($uid = 0, $trigger = 'NO_TRIGGER', $args =
} elseif ($uid == 0 && isset($args['email'])) {
$toEmail = $args['email'];
} else {
$user = new User\Account($uid);
$email_address_preference = get_user_meta($user->ID, 'email_address_preference', true);
if (empty($email_address_preference)) {
$emailAddressPreference = get_user_meta($user->ID, 'email_address_preference', true);
if (empty($emailAddressPreference)) {
$toEmail = $user->user_email;
} else {
$pp = strtolower($email_address_preference).'_';
$pp = strtolower($emailAddressPreference).'_';
$toEmail = get_user_meta($user->ID, $pp.'email', true);
if (empty($toEmail)) {
......