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

Issue 1498 - Adding entity fields #1526

Merged
merged 20 commits into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion assets/css/admin.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion assets/css/admin.min.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion assets/css/public.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion assets/css/public.min.css

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion assets/src/admin-import-settings.scss
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ h2 {
margin: 0;
}

h3 {
h3,.h3 {
margin-top: 10px !important;
font-weight: bold;
}

p,
Expand Down
14 changes: 14 additions & 0 deletions assets/src/public.scss
Original file line number Diff line number Diff line change
Expand Up @@ -910,6 +910,20 @@ $height: 550px; //height of map and min-height of list
}
}
}

.meeting {
&-entity-title {
font-size: 0.8rem;
}
&-entity-name {
text-align: center;
font-weight: bold;
}
&-entity-location {
text-align: center;
}
}

}

body.tsml_fullscreen {
Expand Down
77 changes: 74 additions & 3 deletions includes/admin_settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ function tsml_settings_page()
sort($tsml_feedback_addresses);
update_option('tsml_feedback_addresses', $tsml_feedback_addresses);
tsml_alert(__('Feedback address added.', '12-step-meeting-list'));
tsml_cache_rebuild(); //these values affects what's in the cache
}
}

Expand All @@ -107,6 +108,7 @@ function tsml_settings_page()
update_option('tsml_feedback_addresses', $tsml_feedback_addresses);
}
tsml_alert(__('Feedback address removed.', '12-step-meeting-list'));
tsml_cache_rebuild(); //these values affects what's in the cache
} else {
//theoretically should never get here, because user is choosing from a list
tsml_alert(sprintf(esc_html__('<p><code>%s</code> was not found in the list of addresses. Please try again.</p>', '12-step-meeting-list'), $email), 'error');
Expand Down Expand Up @@ -202,6 +204,22 @@ function tsml_settings_page()
tsml_alert(__('Invalid timezone selected.', '12-step-meeting-list'), 'error');
}
}

//save entity fields
if (isset($_POST['tsml_entity']) && isset($_POST['tsml_nonce']) && wp_verify_nonce($_POST['tsml_nonce'], $tsml_nonce)) {
$current_tsml_entity = tsml_get_option_array('tsml_entity');
$tsml_entity = [];
global $tsml_entity_fields;
foreach ( $tsml_entity_fields as $field ) {
$tsml_entity[$field] = isset($current_tsml_entity[$field]) ? $current_tsml_entity[$field] : '';
if (isset($_POST["tsml_$field"])) {
$tsml_entity[$field] = substr(trim(strval($_POST["tsml_$field"])), 0, 100);
}
}
update_option('tsml_entity', $tsml_entity);
tsml_cache_rebuild(); //these values affects what's in the cache
tsml_alert(__('Entity details saved.', '12-step-meeting-list'));
}
gkovats marked this conversation as resolved.
Show resolved Hide resolved
?>

<!-- Admin page content should all be inside .wrap -->
Expand Down Expand Up @@ -332,7 +350,62 @@ function tsml_settings_page()
</form>
</div>

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check the order of these on the settings screen. I ended up putting this in spot 2, left column, and moved the Feeds settings to top of the middle column. But I don't stare at this screen much, so it's a guess.

<div class="postbox stack">
<div class="postbox stack">
<!-- Entity Form -->
<?php
$tsml_entity = tsml_get_entity();
if (!isset($tsml_entity['entity_phone'])) {
$tsml_entity['entity_phone'] = '';
}
if (!isset($tsml_entity['entity_location'])) {
$tsml_entity['entity_location'] = '';
}
?>
<div class="stack compact">
<h2>
<?php _e('Service Entity Information', '12-step-meeting-list') ?>
</h2>
<p>
<?php _e('Enter information for your service entity here to help identity the meeting source when sharing feeds with others.', '12-step-meeting-list') ?>
</p>

<form method="post" class="stack compact" action="<?php echo $_SERVER['REQUEST_URI'] ?>">
<?php wp_nonce_field($tsml_nonce, 'tsml_nonce', false) ?>
<label class="h3" for="tsml_entity">
<?php _e('Entity Name', '12-step-meeting-list') ?>
</label>
<input type="text" id="tsml_entity" name="tsml_entity" value="<?php echo esc_attr($tsml_entity['entity']); ?>"
placeholder="<?php esc_attr_e('Entity Name', '12-step-meeting-list'); ?>" maxlength="100">
<label class="h3" for="tsml_entity_email">
<?php _e('Administrative Contact Email', '12-step-meeting-list') ?>
</label>
<input type="text" id="tsml_entity_email" name="tsml_entity_email" value="<?php echo esc_attr($tsml_entity['entity_email']); ?>"
placeholder="[email protected]" maxlength="100">
<label class="h3" for="tsml_entity_phone">
<?php _e('Public Phone Number', '12-step-meeting-list') ?>
</label>
<input type="text" id="tsml_entity_phone" name="tsml_entity_phone" value="<?php echo esc_attr($tsml_entity['entity_phone']); ?>"
placeholder="+18005551212" maxlength="100">
<label class="h3" for="tsml_entity_location">
<?php _e('Service Area', '12-step-meeting-list') ?>
</label>
<input type="text" id="tsml_entity_location" name="tsml_entity_location" value="<?php echo esc_attr($tsml_entity['entity_location']); ?>"
placeholder="<?php esc_attr_e('City, State, Country', '12-step-meeting-list')?>" maxlength="100">
<label class="h3" for="tsml_entity_url">
<?php _e('Website Address', '12-step-meeting-list') ?>
</label>
<input type="text" id="tsml_entity_url" name="tsml_entity_url" value="<?php echo esc_attr($tsml_entity['entity_url']); ?>"
placeholder="https://" maxlength="100">
<p>
<input type="submit" class="button" value="<?php esc_attr_e('Save', '12-step-meeting-list'); ?>">
</p>
</form>
</div>
</div>
</div>

<div class="stack">
<div class="postbox stack">
<!-- Feed Management -->
<h2>
<?php _e('Feed Management', '12-step-meeting-list') ?>
Expand Down Expand Up @@ -412,9 +485,7 @@ function tsml_settings_page()
</div>
<?php } ?>
</div>
</div>

<div class="stack">
<div class="postbox stack">
<!-- Switch UI -->
<div class="stack compact">
Expand Down
17 changes: 12 additions & 5 deletions includes/ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -301,15 +301,21 @@ function tsml_ajax_feedback()
$message .= '<p>' . $key . ': ' . $value . '</p>';
}

//if meeting was imported and has feedback_emails set, email them instead
$to_email_addresses = $tsml_feedback_addresses;
if (!empty($meeting->data_source) && !empty($meeting->feedback_emails)) {
$to_email_addresses = $meeting->feedback_emails;
}

//email vars
if (!isset($_POST['tsml_nonce']) || !wp_verify_nonce($_POST['tsml_nonce'], $tsml_nonce)) {
_e('Error: nonce value not set correctly. Email was not sent.', '12-step-meeting-list');
} elseif (empty($tsml_feedback_addresses) || empty($name) || !is_email($email) || empty($message)) {
} elseif (empty($to_email_addresses) || empty($name) || !is_email($email) || empty($message)) {
_e('Error: required form value missing. Email was not sent.', '12-step-meeting-list');
} else {
//send HTML email
$subject = __('Meeting Feedback Form', '12-step-meeting-list') . ': ' . $meeting->post_title;
if (tsml_email($tsml_feedback_addresses, $subject, $message, $name . ' <' . $email . '>')) {
if (tsml_email($to_email_addresses, $subject, $message, $name . ' <' . $email . '>')) {
_e('Thank you for your feedback.', '12-step-meeting-list');
} else {
global $phpmailer;
Expand Down Expand Up @@ -378,7 +384,7 @@ function tsml_ajax_geocodes()
//ajax function to import the meetings in the import buffer
//used by admin_import.php
add_action('wp_ajax_tsml_import', function () {
global $tsml_data_sources, $tsml_custom_meeting_fields, $tsml_source_fields_map, $tsml_contact_fields;
global $tsml_data_sources, $tsml_custom_meeting_fields, $tsml_source_fields_map, $tsml_contact_fields, $tsml_entity_fields, $tsml_array_fields;

tsml_require_meetings_permission();

Expand Down Expand Up @@ -565,13 +571,14 @@ function tsml_ajax_geocodes()
//add custom meeting fields if available
$custom_meeting_fields = array_merge(
['types', 'data_source', 'conference_url', 'conference_url_notes', 'conference_phone', 'conference_phone_notes'],
array_keys($tsml_source_fields_map)
array_keys($tsml_source_fields_map),
$tsml_entity_fields
);
if (!empty($tsml_custom_meeting_fields)) {
$custom_meeting_fields = array_merge($custom_meeting_fields, array_keys($tsml_custom_meeting_fields));
}
foreach ($custom_meeting_fields as $key) {
if (empty(isset($meeting[$key]) ? $meeting[$key] : '')) {
if (empty($meeting[$key])) {
if (metadata_exists('post', $meeting_id, $key)) {
delete_post_meta($meeting_id, $key);
}
Expand Down
Loading