Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update change notification email fields to include all tsml_export_columns. #1455

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 11 additions & 15 deletions includes/save.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

//handle all the metadata, location
add_action('save_post', function ($post_id, $post, $update) {
global $tsml_nonce, $wpdb, $tsml_notification_addresses, $tsml_days, $tsml_contact_fields;
global $tsml_nonce, $wpdb, $tsml_notification_addresses, $tsml_days, $tsml_contact_fields, $tsml_export_columns;

//security
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
Expand Down Expand Up @@ -161,7 +161,7 @@
}

//compare types
if (tsml_program_has_types() && (!$update || implode(', ', $old_meeting->types) != tsml_meeting_types($_POST['types']))) {
if (tsml_program_has_types() && (!$update || tsml_meeting_types($old_meeting->types) != tsml_meeting_types($_POST['types']))) {
$changes[] = 'types';
if (empty($_POST['types'])) {
delete_post_meta($post->ID, 'types');
Expand Down Expand Up @@ -298,7 +298,7 @@

// save timezone
if (!$update || strcmp($old_meeting->timezone, $_POST['timezone']) !== 0) {
$changes[] = 'timezone' ;
$changes[] = 'timezone';
if (!tsml_timezone_is_valid($_POST['timezone'])) {
delete_post_meta($location_id, 'timezone');
} else {
Expand Down Expand Up @@ -444,24 +444,20 @@
//don't notify for lat / lon changes
$changes = array_diff($changes, ['latitude', 'longitude']);

if (count($tsml_notification_addresses) && count($changes)) {
if (count($tsml_notification_addresses) && count($changes) && $_POST['post_status'] === 'publish') {
$message = ' <p>';
if ($update) {
$message .= sprintf(__('This is to notify you that %s updated a <a href="%s">meeting</a> on the %s site.', '12-step-meeting-list'), $user->display_name, get_permalink($post->ID), get_bloginfo('name'));
} else {
$message .= sprintf(__('This is to notify you that %s created a <a href="%s">new meeting</a> on the %s site.', '12-step-meeting-list'), $user->display_name, get_permalink($post->ID), get_bloginfo('name'));
}
$message .= '</p><table style="font:14px arial;width:100%;border-collapse:collapse;padding:0;">';
$fields = array_merge(
['name', 'day', 'time', 'end_time', 'types', 'notes', 'location', 'formatted_address', 'region', 'location_notes', 'group', 'district', 'group_notes'],
array_keys($tsml_contact_fields)
);
foreach ($fields as $field) {
foreach ($tsml_export_columns as $field => $field_name) {
$new = $old = '';

if ($field == 'types') {
if ($update) {
$old = implode(', ', $old_meeting->types);
$old = tsml_meeting_types($old_meeting->types);
}
$new = tsml_meeting_types($_POST['types']);
} elseif ($field == 'name') {
Expand Down Expand Up @@ -490,7 +486,7 @@
}
$new = empty($_POST['end_time']) ? '' : tsml_format_time($_POST['end_time'], '');
} elseif ($field == 'region') {
if ($term = get_term($_POST['region'], 'tsml_region')) {
if (!empty($_POST['region']) && $term = get_term($_POST['region'], 'tsml_region')) {
$new = $term->name;
}
if ($update && !empty($old_meeting->region)) {
Expand All @@ -504,14 +500,14 @@
$old = $old_meeting->district;
}
} else {
if ($update) {
if ($update && !empty($old_meeting->{$field})) {
$old = $old_meeting->{$field};
}
$new = $_POST[$field];
if (!empty($_POST[$field])) {
$new = $_POST[$field];
}
}

$field_name = __(ucwords(str_replace('_', ' ', $field)), '12-step-meeting-list');

if (in_array($field, $changes)) {
$message .= '<tr style="border:1px solid #999;background-color:#fff;"><td style="width:150px;padding:5px">' . $field_name . '</td><td style="padding:5px">';
if (!empty($old)) {
Expand Down