Skip to content
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
3 changes: 0 additions & 3 deletions wp-content/plugins/vf-events/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,9 @@ The global options are:
| vf_event_past_title | [TEXT] |
| vf_events_per_page | [NUMBER] |
| vf_events_enable_chatbot | [BOOLEAN] |
| vf_events_chatbot_routes_payload | [JSON TEXTAREA] |

† If the date format is `custom` the custom text string is used.

The chatbot routes payload is stored directly in the Events settings page, refreshed automatically once a day, refreshed whenever an event is saved, and can also be refreshed manually with the button on that screen.

See the ACF JSON file for default values.

## Templates
Expand Down
36 changes: 36 additions & 0 deletions wp-content/plugins/vf-events/assets/qa.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"predefinedQA": {
"How can I register?": {
"answer": "Answer 1 here"
},
"Who is the contact person for this event?": {
"answer": "Answer 2 here"
},
"Where is the event taking place?": {
"answer": "Answer 3 here",
"sources": [
{
"domain": "ebi.ac.uk",
"title": "EMBL-EBI Training",
"url": "https://www.ebi.ac.uk/training/",
"description": "Delivering world-class training in data-driven life sciences."
}
]
}
},
"fallbackResponses": [
{
"answer": "I'm sorry, I'm having trouble connecting to my knowledge base right now. Could you try again in a moment?",
"prompts": [
{
"action_text": "Contact support team",
"action_url": "tel:+44 1223 494 444"
},
{
"action_text": "Submit a support request",
"action_url": "https://www.ebi.ac.uk/about/contact/support/"
}
]
}
]
}
37 changes: 0 additions & 37 deletions wp-content/plugins/vf-events/assets/vf-events-chatbot.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,6 @@
return selector ? selector.getAttribute("data-routes-path") : "";
}

function getRoutesPayloadElement() {
var selector = getSelectorElement();

return selector
? selector.querySelector("[data-vf-js-events-chatbot-routes-payload]")
: null;
}

function getSelectorEmptyLabel() {
var selector = getSelectorElement();

Expand Down Expand Up @@ -189,40 +181,11 @@

function loadEventRoutes() {
var routesPath = getRoutesPath();
var routesPayloadElement = getRoutesPayloadElement();

if (eventRoutesPromise) {
return eventRoutesPromise;
}

if (routesPayloadElement) {
eventRoutesPromise = Promise.resolve()
.then(function () {
var payloadText = routesPayloadElement.textContent || "";
var parsedPayload = payloadText ? JSON.parse(payloadText) : { routes: [] };
var routes = sortRoutesAlphabetically(
normalizeRoutesPayload(parsedPayload)
);

eventRoutesById = {};
routes.forEach(function (route) {
if (route && route.id) {
eventRoutesById[route.id] = route;
}
});

return routes;
})
.catch(function (error) {
console.error("Unable to parse inline event routes payload:", error);
eventRoutesById = {};
eventRoutesPromise = null;
return [];
});

return eventRoutesPromise;
}

if (!routesPath) {
return Promise.resolve([]);
}
Expand Down
92 changes: 0 additions & 92 deletions wp-content/plugins/vf-events/includes/acf.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,6 @@ function __construct($file) {
'acf/settings/load_json',
array($this, 'acf_settings_load_json')
);
add_filter(
'acf/prepare_field/name=vf_events_chatbot_routes_payload_actions',
array($this, 'acf_prepare_field_vf_events_chatbot_routes_payload_actions')
);
add_action(
'admin_post_vf_events_refresh_chatbot_routes',
array($this, 'handle_manual_chatbot_routes_refresh')
);
add_action(
VF_Events::chatbot_routes_refresh_hook(),
array($this, 'refresh_chatbot_routes_payload')
Expand Down Expand Up @@ -209,35 +201,6 @@ public function acf_init() {
'ui_on_text' => __('Enabled', 'vfwp'),
'ui_off_text' => __('Disabled', 'vfwp'),
),
array(
'key' => 'field_vf_events_chatbot_routes_payload',
'label' => __('Chatbot routes payload', 'vfwp'),
'name' => 'vf_events_chatbot_routes_payload',
'type' => 'textarea',
'instructions' => __(
'Stored JSON payload used by the event chatbot selector. It is refreshed automatically once a day and whenever an event is saved.',
'vfwp'
),
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array(
'width' => '',
'class' => '',
'id' => '',
),
'default_value' => '',
'rows' => 18,
'new_lines' => '',
),
array(
'key' => 'field_vf_events_chatbot_routes_payload_actions',
'label' => __('Refresh chatbot routes payload', 'vfwp'),
'name' => 'vf_events_chatbot_routes_payload_actions',
'type' => 'message',
'message' => '',
'new_lines' => 'wpautop',
'esc_html' => 0,
),
),
'location' => array(
array(
Expand Down Expand Up @@ -422,40 +385,6 @@ public function rest_api_init() {
));
}

/**
* Prepare the actions field for chatbot routes payload refresh.
*/
public function acf_prepare_field_vf_events_chatbot_routes_payload_actions($field) {
$refresh_url = wp_nonce_url(
admin_url('admin-post.php?action=vf_events_refresh_chatbot_routes'),
'vf_events_refresh_chatbot_routes'
);
$updated_at = VF_Events::get_chatbot_routes_updated_at();
$status_message = $updated_at
? sprintf(
__('Last refreshed: %s', 'vfwp'),
wp_date(get_option('date_format') . ' ' . get_option('time_format'), $updated_at)
)
: __('The chatbot routes payload has not been generated yet.', 'vfwp');

if (isset($_GET['vf_events_chatbot_routes_refreshed'])) {
if ($_GET['vf_events_chatbot_routes_refreshed'] === '1') {
$status_message = __('The chatbot routes payload was refreshed successfully.', 'vfwp') . ' ' . $status_message;
} elseif ($_GET['vf_events_chatbot_routes_refreshed'] === '0') {
$status_message = __('The chatbot routes payload could not be refreshed.', 'vfwp') . ' ' . $status_message;
}
}

$field['message'] = sprintf(
'<p>%1$s</p><p><a class="button button-secondary" href="%2$s">%3$s</a></p>',
esc_html($status_message),
esc_url($refresh_url),
esc_html__('Refresh now', 'vfwp')
);

return $field;
}

/**
* Return the stored chatbot routes payload via REST.
*/
Expand Down Expand Up @@ -483,27 +412,6 @@ public function refresh_chatbot_routes_payload_on_save($post_id) {
$this->refresh_chatbot_routes_payload();
}

/**
* Handle manual chatbot routes refresh from the Events settings page.
*/
public function handle_manual_chatbot_routes_refresh() {
if (!current_user_can('manage_options')) {
wp_die(__('You are not allowed to refresh chatbot routes.', 'vfwp'));
}

check_admin_referer('vf_events_refresh_chatbot_routes');

$refreshed = $this->refresh_chatbot_routes_payload();
$redirect_url = add_query_arg(
'vf_events_chatbot_routes_refreshed',
$refreshed ? '1' : '0',
VF_Events::get_settings_url()
);

wp_safe_redirect($redirect_url);
exit;
}

/**
* Filter: `acf/settings/load_json`
*/
Expand Down
14 changes: 5 additions & 9 deletions wp-content/plugins/vf-events/templates/partials/chatbot.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@
$chatbot_event_id = get_post_field('post_name', $chatbot_event_post_id);
$chatbot_plugin_base_url = plugin_dir_url(dirname(dirname(dirname(__FILE__))) . '/vf-events.php');
$chatbot_asset_base = untrailingslashit(get_theme_file_uri('assets/assets/vf-chatbot/assets'));
$chatbot_asset_base_custom = untrailingslashit(get_template_directory_uri() . '/assets/assets/chatbot');
$chatbot_routes_payload = class_exists('VF_Events')
? VF_Events::get_chatbot_routes_payload()
: array('routes' => array());
$chatbot_qa_data_url = $chatbot_plugin_base_url . 'assets/qa.json';
$chatbot_routes_url = class_exists('VF_Events')
? VF_Events::get_chatbot_routes_url()
: rest_url('vf-events/v1/chatbot-routes');
Expand Down Expand Up @@ -103,7 +100,6 @@
<div role="region" aria-label="Chatbot header" class="vf-chatbot-modal__header">
<div role="region" aria-label="Chatbot title" class="vf-chatbot-modal__header-left">
<div class="vf-chatbot-selector" data-vf-js-events-chatbot-selector data-routes-path="<?php echo esc_url($chatbot_routes_url); ?>" data-empty-label="Select other event" data-selected-route-id="<?php echo esc_attr($chatbot_event_id); ?>">
<script type="application/json" data-vf-js-events-chatbot-routes-payload><?php echo wp_json_encode($chatbot_routes_payload, JSON_UNESCAPED_SLASHES); ?></script>
<button class="vf-chatbot-selector__title" data-vf-js-selector-toggle type="button">
<img src="<?php echo esc_url($chatbot_asset_base . '/vf-chatbot--icon-24x24-dark-green.svg'); ?>" alt="AI Event Assistant">
<div class="vf-chatbot-selector__title-content vf-u-margin__left--200">
Expand Down Expand Up @@ -148,7 +144,7 @@
id="eventInfo"
class="vf-events-chatbot-event-hero"
<?php if (!empty($chatbot_hero_image)) { ?>
style="background: url('<?php echo esc_url($chatbot_hero_image); ?>') no-repeat 73% 46%; background-size: auto; margin: 1.5rem 1.5rem 2rem 1.5rem; border-radius: 2px;"
style="background: url('<?php echo esc_url($chatbot_hero_image); ?>') no-repeat 73% 46%; background-size: auto; margin: 0.5rem 0.5rem 2rem; border-radius: 2px;"
<?php } ?>
>
<div class="vf-events-chatbot-event-card">
Expand Down Expand Up @@ -191,7 +187,7 @@ class="vf-chatbot-welcome"
data-enable-qa-data-loading="true"
data-enable-predefined-qa="true"
data-enable-fallback-responses="true"
data-qa-data-url="<?php echo esc_url($chatbot_asset_base_custom . '/qa.json'); ?>"
data-qa-data-url="<?php echo esc_url($chatbot_qa_data_url); ?>"
>


Expand Down Expand Up @@ -373,7 +369,7 @@ class="vf-chatbot-welcome"
<script>
(function () {
var assetBase = "<?php echo esc_js($chatbot_asset_base); ?>";
var assetBaseCustom = "<?php echo esc_js($chatbot_asset_base_custom); ?>";
var qaDataUrl = "<?php echo esc_js($chatbot_qa_data_url); ?>";

window.vfEventChatbotConfig = {
type: "modal",
Expand All @@ -395,7 +391,7 @@ class="vf-chatbot-welcome"
api: {
chat_endpoint: "https://8jtt848211.execute-api.eu-west-2.amazonaws.com/message",
feedback_endpoint: false,
qa_data_url: assetBaseCustom + "/qa.json",
qa_data_url: qaDataUrl,
headers: {
"Content-Type": "application/json"
},
Expand Down
24 changes: 0 additions & 24 deletions wp-content/plugins/vf-events/vf-events.php
Original file line number Diff line number Diff line change
Expand Up @@ -266,13 +266,6 @@ static public function chatbot_routes_option_name() {
return 'options_vf_events_chatbot_routes_payload';
}

/**
* Option name for chatbot routes refresh timestamp.
*/
static public function chatbot_routes_updated_at_option_name() {
return 'options_vf_events_chatbot_routes_updated_at';
}

/**
* Cron hook for refreshing chatbot routes.
*/
Expand All @@ -294,22 +287,6 @@ static public function get_chatbot_routes_url() {
return rest_url(self::chatbot_routes_rest_path());
}

/**
* Admin URL for the Events settings page.
*/
static public function get_settings_url() {
return admin_url(
'edit.php?post_type=' . self::type() . '&page=vf-events-settings'
);
}

/**
* Last refresh timestamp for stored routes payload.
*/
static public function get_chatbot_routes_updated_at() {
return (int) get_option(self::chatbot_routes_updated_at_option_name(), 0);
}

/**
* Schedule the daily chatbot routes refresh if it is not already scheduled.
*/
Expand Down Expand Up @@ -397,7 +374,6 @@ static public function refresh_chatbot_routes_payload($posts_per_page = 100) {
}

update_option(self::chatbot_routes_option_name(), $json, false);
update_option(self::chatbot_routes_updated_at_option_name(), time(), false);

return $payload;
}
Expand Down
41 changes: 28 additions & 13 deletions wp-content/themes/vf-wp-groups/functions/groups-customize.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,22 +52,35 @@ public function __construct() {
array($this, 'wp_head')
);
*/
// Setup defaults
$this->themes = VF_Theme::apply_filters(
'vf/admin/customize/themes',
array()
);
$this->theme_layouts = VF_Theme::apply_filters(
'vf/admin/customize/theme_layouts',
array()
);
}

/**
* Build customize choices lazily so translations run after init.
*/
private function setup_defaults() {
if ($this->themes === null) {
$this->themes = VF_Theme::apply_filters(
'vf/admin/customize/themes',
array()
);
}

if ($this->theme_layouts === null) {
$this->theme_layouts = VF_Theme::apply_filters(
'vf/admin/customize/theme_layouts',
array()
);
}

/**
* @deprecated https://github.com/visual-framework/vf-wp/issues/141
*
$this->theme_colors = VF_Theme::apply_filters(
'vf/admin/customize/theme_colors',
array()
);
if ($this->theme_colors === null) {
$this->theme_colors = VF_Theme::apply_filters(
'vf/admin/customize/theme_colors',
array()
);
}
*/
}

Expand Down Expand Up @@ -119,6 +132,8 @@ public function customize_theme_colors($colors) {
* Action: `vf/admin/customize`
*/
public function admin_customize($wp_customize) {
$this->setup_defaults();

// Global theme
$wp_customize->add_setting('vf_theme', array(
'default' => array_keys($this->themes)[0],
Expand Down
Loading
Loading