Make notifications translatable
Showing
4 changed files
with
44 additions
and
34 deletions
This diff is collapsed.
Click to expand it.
| ... | @@ -79,7 +79,9 @@ function print_user_notices($showOnlyUnread = false) | ... | @@ -79,7 +79,9 @@ function print_user_notices($showOnlyUnread = false) |
| 79 | } | 79 | } |
| 80 | 80 | ||
| 81 | $system = get_post_meta($notice['notification_id'], 'system', true); | 81 | $system = get_post_meta($notice['notification_id'], 'system', true); |
| 82 | $content = $system['message']; | 82 | $content = isset($system[ICL_LANGUAGE_CODE.'_message']) |
| 83 | ? $system[ICL_LANGUAGE_CODE.'_message'] | ||
| 84 | : $system['en_message']; | ||
| 83 | 85 | ||
| 84 | if (isset($notice['args']) && count($notice['args']) > 0) { | 86 | if (isset($notice['args']) && count($notice['args']) > 0) { |
| 85 | foreach ($notice['args'] as $key => $val) { | 87 | foreach ($notice['args'] as $key => $val) { |
| ... | @@ -214,6 +216,9 @@ function send_triggered_notification($uid = 0, $trigger = 'NO_TRIGGER', $args = | ... | @@ -214,6 +216,9 @@ function send_triggered_notification($uid = 0, $trigger = 'NO_TRIGGER', $args = |
| 214 | /** @var \wpdb $wpdb */ | 216 | /** @var \wpdb $wpdb */ |
| 215 | global $wpdb; | 217 | global $wpdb; |
| 216 | 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 | ||
| 220 | $lang = ICL_LANGUAGE_CODE; | ||
| 221 | |||
| 217 | /** @var \StdClass $notification */ | 222 | /** @var \StdClass $notification */ |
| 218 | $notification = get_notification_by_trigger($trigger); | 223 | $notification = get_notification_by_trigger($trigger); |
| 219 | 224 | ||
| ... | @@ -228,10 +233,8 @@ function send_triggered_notification($uid = 0, $trigger = 'NO_TRIGGER', $args = | ... | @@ -228,10 +233,8 @@ function send_triggered_notification($uid = 0, $trigger = 'NO_TRIGGER', $args = |
| 228 | $notification->status = isset($details['status']) ? $details['status'] : 'active'; | 233 | $notification->status = isset($details['status']) ? $details['status'] : 'active'; |
| 229 | $notification->type = $details['type']; | 234 | $notification->type = $details['type']; |
| 230 | $notification->sendto = @$details['sendto']; | 235 | $notification->sendto = @$details['sendto']; |
| 231 | $notification->is_email = (($email['text'] != '' || $email['html'] != '') && $email['subject'] != '') | 236 | $notification->is_email = (($email[$lang.'_text'] != '' || $email[$lang.'_html'] != '') && $email[$lang.'_subject'] != ''); |
| 232 | ? true | 237 | $notification->is_system = (isset($system[$lang.'_message']) && $system[$lang.'_message'] != ''); |
| 233 | : false; | ||
| 234 | $notification->is_system = (isset($system['message']) && $system['message'] != '') ? true : false; | ||
| 235 | 238 | ||
| 236 | // if is_system ========================================== | 239 | // if is_system ========================================== |
| 237 | if ($notification->is_system && $uid != 0) { | 240 | if ($notification->is_system && $uid != 0) { |
| ... | @@ -257,52 +260,59 @@ function send_triggered_notification($uid = 0, $trigger = 'NO_TRIGGER', $args = | ... | @@ -257,52 +260,59 @@ function send_triggered_notification($uid = 0, $trigger = 'NO_TRIGGER', $args = |
| 257 | 260 | ||
| 258 | // if is_email =========================================== | 261 | // if is_email =========================================== |
| 259 | if ($notification->is_email) { | 262 | if ($notification->is_email) { |
| 260 | |||
| 261 | if ($uid == 0 && !isset($args['email'])) { | 263 | if ($uid == 0 && !isset($args['email'])) { |
| 262 | return; | 264 | return; |
| 263 | } elseif ($uid == 0 && isset($args['email'])) { | 265 | } elseif ($uid == 0 && isset($args['email'])) { |
| 264 | $to_email = $args['email']; | 266 | $toEmail = $args['email']; |
| 265 | } else { | 267 | } else { |
| 266 | 268 | ||
| 267 | $user = new User\Account($uid); | 269 | $user = new User\Account($uid); |
| 268 | $email_address_preference = get_user_meta($user->ID, 'email_address_preference', true); | 270 | $email_address_preference = get_user_meta($user->ID, 'email_address_preference', true); |
| 269 | if (empty($email_address_preference)) { | 271 | if (empty($email_address_preference)) { |
| 270 | $to_email = $user->user_email; | 272 | $toEmail = $user->user_email; |
| 271 | } else { | 273 | } else { |
| 274 | $pp = strtolower($email_address_preference).'_'; | ||
| 275 | $toEmail = get_user_meta($user->ID, $pp.'email', true); | ||
| 272 | 276 | ||
| 273 | $pp = strtolower($email_address_preference)."_"; | 277 | if (empty($toEmail)) { |
| 274 | $to_email = get_user_meta($user->ID, $pp.'email', true); | 278 | $toEmail = $user->user_email; |
| 275 | |||
| 276 | if (empty($to_email)) { | ||
| 277 | $to_email = $user->user_email; | ||
| 278 | } | 279 | } |
| 279 | } | 280 | } |
| 280 | } | 281 | } |
| 281 | 282 | ||
| 282 | $contents = $email; | 283 | $contents = $email; |
| 283 | 284 | ||
| 284 | $from_email = get_bloginfo('admin_email'); | 285 | $fromEmail = get_bloginfo('admin_email'); |
| 285 | $subject = strip_tags($contents['subject']); | 286 | $subject = strip_tags( |
| 286 | $html = @$contents['html']; | 287 | isset($contents[$lang.'_subject']) && !empty($contents[$lang.'_subject']) |
| 287 | $alttext = strip_tags($contents['text']); | 288 | ? $contents[$lang.'_subject'] |
| 289 | : $contents['en_subject'] | ||
| 290 | ); | ||
| 291 | $html = isset($contents[$lang.'_html']) && !empty($contents[$lang.'_html']) | ||
| 292 | ? $contents[$lang.'_html'] | ||
| 293 | : @$contents['en_html']; | ||
| 294 | $altText = strip_tags( | ||
| 295 | isset($contents[$lang.'_text']) && !empty($contents[$lang.'_text']) | ||
| 296 | ? $contents[$lang.'_text'] | ||
| 297 | : $contents['en_text'] | ||
| 298 | ); | ||
| 288 | 299 | ||
| 289 | foreach ($args as $key => $val) { | 300 | foreach ($args as $key => $val) { |
| 290 | if ((filter_var($val, FILTER_VALIDATE_URL) !== false) && !empty($html)) { | 301 | if ((filter_var($val, FILTER_VALIDATE_URL) !== false) && !empty($html)) { |
| 291 | $html = str_replace("{".$key."}", "<a href='".$val."'>".$val."</a>", $html); | 302 | $html = str_replace('{'.$key.'}', '<a href="'.$val.'">'.$val.'</a>', $html); |
| 292 | } else { | 303 | } else { |
| 293 | $html = str_replace("{".$key."}", $val, $html); | 304 | $html = str_replace('{'.$key.'}', $val, $html); |
| 294 | $alttext = str_replace("{".$key."}", $val, $alttext); | 305 | $altText = str_replace('{'.$key.'}', $val, $altText); |
| 295 | $subject = str_replace("{".$key."}", $val, $subject); | 306 | $subject = str_replace('{'.$key.'}', $val, $subject); |
| 296 | } | 307 | } |
| 297 | } | 308 | } |
| 298 | 309 | ||
| 299 | $attachments = []; | 310 | $attachments = isset($contents[$lang.'_attachments']) |
| 300 | if (isset($contents['attachments'])) { | 311 | ? $contents[$lang.'_attachments'] |
| 301 | $attachments = $contents['attachments']; | 312 | : $contents['en_attachments']; |
| 302 | } | 313 | $att1 = isset($attachments[0]) ? $attachments[0] : ''; |
| 303 | $att1 = isset($attachments[0]) ? $attachments[0] : ''; | 314 | $att2 = isset($attachments[1]) ? $attachments[1] : ''; |
| 304 | $att2 = isset($attachments[1]) ? $attachments[1] : ''; | 315 | $att3 = isset($attachments[2]) ? $attachments[2] : ''; |
| 305 | $att3 = isset($attachments[2]) ? $attachments[2] : ''; | ||
| 306 | 316 | ||
| 307 | $attachments = array_map( | 317 | $attachments = array_map( |
| 308 | function ($attachmentPath) { | 318 | function ($attachmentPath) { |
| ... | @@ -313,7 +323,7 @@ function send_triggered_notification($uid = 0, $trigger = 'NO_TRIGGER', $args = | ... | @@ -313,7 +323,7 @@ function send_triggered_notification($uid = 0, $trigger = 'NO_TRIGGER', $args = |
| 313 | 323 | ||
| 314 | $sentSuccessfully = false; | 324 | $sentSuccessfully = false; |
| 315 | if (CBV\system_can_send_emails()) { | 325 | if (CBV\system_can_send_emails()) { |
| 316 | $response = \wpMandrill::mail($to_email, $subject, !empty($html) ? $html : $alttext, [], $attachments); | 326 | $response = \wpMandrill::mail($toEmail, $subject, !empty($html) ? $html : $altText, [], $attachments); |
| 317 | if ( | 327 | if ( |
| 318 | is_array($response) | 328 | is_array($response) |
| 319 | && isset($response[0]['status']) | 329 | && isset($response[0]['status']) |
| ... | @@ -328,10 +338,10 @@ function send_triggered_notification($uid = 0, $trigger = 'NO_TRIGGER', $args = | ... | @@ -328,10 +338,10 @@ function send_triggered_notification($uid = 0, $trigger = 'NO_TRIGGER', $args = |
| 328 | 'wp_mail_daemon', | 338 | 'wp_mail_daemon', |
| 329 | [ | 339 | [ |
| 330 | 'notification_id' => $nid, | 340 | 'notification_id' => $nid, |
| 331 | 'from_email' => $from_email, | 341 | 'from_email' => $fromEmail, |
| 332 | 'to_email' => $to_email, | 342 | 'to_email' => $toEmail, |
| 333 | 'subject' => $subject, | 343 | 'subject' => $subject, |
| 334 | 'text' => $alttext, | 344 | 'text' => $altText, |
| 335 | 'html' => $html, | 345 | 'html' => $html, |
| 336 | 'attachment1' => $att1, | 346 | 'attachment1' => $att1, |
| 337 | 'attachment2' => $att2, | 347 | 'attachment2' => $att2, | ... | ... |
| ... | @@ -9,7 +9,7 @@ use Tz\WordPress\Tools\Notifications\Settings; | ... | @@ -9,7 +9,7 @@ use Tz\WordPress\Tools\Notifications\Settings; |
| 9 | <div class="wrap"> | 9 | <div class="wrap"> |
| 10 | <h2>Notifications - Create New</h2> | 10 | <h2>Notifications - Create New</h2> |
| 11 | 11 | ||
| 12 | <?php if (isset($flash) && $flash != ""): ?> | 12 | <?php if (isset($flash) && $flash != ''): ?> |
| 13 | <div class="post-success"> | 13 | <div class="post-success"> |
| 14 | <?php echo $flash; ?> | 14 | <?php echo $flash; ?> |
| 15 | </div> | 15 | </div> |
| ... | @@ -231,4 +231,4 @@ use Tz\WordPress\Tools\Notifications\Settings; | ... | @@ -231,4 +231,4 @@ use Tz\WordPress\Tools\Notifications\Settings; |
| 231 | jQuery('.scheduled_sendto').show(); | 231 | jQuery('.scheduled_sendto').show(); |
| 232 | } | 232 | } |
| 233 | } | 233 | } |
| 234 | </script> | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| 234 | </script> | ... | ... |
This diff is collapsed.
Click to expand it.
-
Please register or sign in to post a comment