Below is a differential between the unpatched vulnerable code and the patched update, for reference.
--- a/events-manager/admin/em-addons.php
+++ b/events-manager/admin/em-addons.php
@@ -52,6 +52,7 @@
'events-manager-io' => 'EM_IOLicense',
'events-manager-connect' => 'EMConnectLicense',
'events-manager-zoom-pro' => 'EMZoomLicense',
+ 'events-manager-conversion-tracking' => 'EMConversion_TrackingServerLicense',
) );
}
@@ -813,9 +814,10 @@
'expired' => __( 'License expired', 'events-manager' ),
'licensed' => __( 'Licensed', 'events-manager' ),
);
+ // the plans that include it, cheapest first as the store lists them ("Pro and Pro Plus")
$included = array();
- foreach ( $addon['included_in'] as $plan ) {
- if ( ! empty( $catalogue['plans'][ $plan ] ) ) {
+ foreach ( array_unique( array_merge( array( 'pro', 'pro-plus' ), $addon['included_in'] ) ) as $plan ) {
+ if ( in_array( $plan, $addon['included_in'], true ) && ! empty( $catalogue['plans'][ $plan ] ) ) {
$included[] = $catalogue['plans'][ $plan ]['short'];
}
}
@@ -851,8 +853,8 @@
<?php
static::from_price( $addon['from'], $addon['from_deal'] ?? 0, $addon['save_up_to'] ?? 0 );
if ( $included ) {
- // translators: %s: plan name
- echo '<span class="em-addon-included">' . esc_html( sprintf( __( 'or included with %s', 'events-manager' ), implode( ', ', $included ) ) ) . '</span>';
+ // translators: %s: plan names, such as Pro Plus, or Pro and Pro Plus
+ echo '<span class="em-addon-included">' . esc_html( sprintf( __( 'or included with %s', 'events-manager' ), wp_sprintf( '%l', $included ) ) ) . '</span>';
}
?>
</p>
--- a/events-manager/admin/em-bookings.php
+++ b/events-manager/admin/em-bookings.php
@@ -128,7 +128,7 @@
<div class="input">
<?php if( is_admin() ): ?><h1 class="wp-heading-inline"><?php else: ?><h2><?php endif; ?>
- <?php echo sprintf(__('Manage %s Bookings', 'events-manager'), "'{$EM_Event->event_name}'"); ?>
+ <?php echo sprintf(__('Manage %s Bookings', 'events-manager'), "'". esc_html($EM_Event->event_name) ."'"); ?>
<?php if( !is_admin() ): ?></h2><?php else: ?></h1><?php endif; // inverted to help IDEs ?>
<a href="<?php echo $EM_Event->get_permalink(); ?>" class="button button-secondary"><?php echo sprintf(__('View %s','events-manager'), __('Event', 'events-manager')) ?></a>
<a href="<?php echo $EM_Event->get_edit_url(); ?>" class="button button-secondary"><?php echo sprintf(__('Edit %s','events-manager'), __('Event', 'events-manager')) ?></a>
@@ -184,7 +184,7 @@
<div class="em-notice em-notice-icon" >
<span class="em-icon em-icon-info"></span>
<?php
- $recurring_link = '<a href="'. esc_url( add_query_arg('event_id', $EM_Event->get_recurring_event()->event_id) ) . '">' . $EM_Event->event_name . '</a>';
+ $recurring_link = '<a href="'. esc_url( add_query_arg('event_id', $EM_Event->get_recurring_event()->event_id) ) . '">' . esc_html( $EM_Event->event_name ) . '</a>';
?>
<span><?php echo sprintf( esc_html__('This is a %s recurrence of %s.', 'events-manager'), strtolower( $label_single ), $recurring_link ); ?></span>
<?php if( !empty($timeslots) ) : ?>
@@ -230,7 +230,7 @@
<?php if( $EM_Event->location_id == 0 ): ?>
<em><?php esc_html_e('No Location', 'events-manager'); ?></em>
<?php else: ?>
- <a class="row-title" href="<?php echo admin_url(); ?>post.php?action=edit&post=<?php echo $EM_Event->get_location()->post_id ?>"><?php echo ($EM_Event->get_location()->location_name); ?></a>
+ <a class="row-title" href="<?php echo admin_url(); ?>post.php?action=edit&post=<?php echo $EM_Event->get_location()->post_id ?>"><?php echo esc_html($EM_Event->get_location()->location_name); ?></a>
<?php endif; ?>
</p>
<?php if( em_get_option('dbem_booking_charts_event') && class_exists('EMAdminDashboard') ): ?>
@@ -300,7 +300,7 @@
<div class="input">
<?php if( is_admin() ): ?><h1 class="wp-heading-inline"><?php else: ?><h2><?php endif; ?>
- <?php echo sprintf(__('Ticket for %s', 'events-manager'), "'{$EM_Event->name}'"); ?><?php echo sprintf(__('Manage %s Bookings', 'events-manager'), "'{$EM_Event->event_name}'"); ?>
+ <?php echo sprintf(__('Ticket for %s', 'events-manager'), "'". esc_html($EM_Event->name) ."'"); ?><?php echo sprintf(__('Manage %s Bookings', 'events-manager'), "'". esc_html($EM_Event->event_name) ."'"); ?>
<?php if( !is_admin() ): ?></h2><?php else: ?></h1><?php endif; // inverted to help IDEs ?>
<a href="<?php echo $EM_Event->get_edit_url(); ?>" class="button button-secondary"><?php esc_html_e('View/Edit Event','events-manager') ?></a>
<a href="<?php echo $EM_Event->get_bookings_url(); ?>" class="button button-secondary"><?php esc_html_e('View Event Bookings','events-manager') ?></a>
@@ -371,7 +371,7 @@
<tr class="em-booking-admin-event-name">
<th><?php esc_html_e('Name','events-manager'); ?></th>
<td>
- <a class="row-title" href="<?php echo $EM_Event->get_bookings_url(); ?>"><?php echo ($EM_Event->event_name); ?></a>
+ <a class="row-title" href="<?php echo $EM_Event->get_bookings_url(); ?>"><?php echo esc_html($EM_Event->event_name); ?></a>
</td>
</tr>
<tr class="em-booking-admin-event-date">
--- a/events-manager/admin/em-ms-options.php
+++ b/events-manager/admin/em-ms-options.php
@@ -91,7 +91,7 @@
$general_tab_link = '';
}
?>
- <a href="<?php echo $general_tab_link ?>#general" id="em-menu-general" class="nav-tab nav-tab-active"><?php esc_html_e('General','events-manager'); ?></a>
+ <a href="<?php echo $general_tab_link ?>#general" id="em-menu-general" class="nav-tab <?php if( !$tabs_enabled || empty($_GET['em_tab']) || $_GET['em_tab'] === 'general' ) echo 'nav-tab-active'; ?>"><?php esc_html_e('General','events-manager'); ?></a>
<?php
$custom_tabs = apply_filters('em_ms_options_page_tabs', array());
foreach( $custom_tabs as $tab_key => $tab_name ){
--- a/events-manager/admin/em-options.php
+++ b/events-manager/admin/em-options.php
@@ -4,8 +4,18 @@
use EMArchetypes_Admin;
use EMException;
+// PHP drops every field past max_input_vars and the full settings form sends over 1000 with Pro active, so on low limits each tab loads and saves on its own
+if( !defined('EM_SETTINGS_TABS') && (int) ini_get('max_input_vars') > 0 && (int) ini_get('max_input_vars') < 2000 ) define('EM_SETTINGS_TABS', true);
+
function em_options_save(){
global $EM_Notices; /* @var EM_Notices $EM_Notices */
+ // a form with more fields than max_input_vars arrives truncated, losing em-submitted and the nonce from the end of the form, so nothing saves and the admin is otherwise told nothing
+ if( current_user_can('manage_options') && !empty($_POST) && empty($_POST['em-submitted']) && !empty($_REQUEST['page']) && $_REQUEST['page'] === 'events-manager-options' ){
+ $max_input_vars = (int) ini_get('max_input_vars');
+ if( $max_input_vars > 0 && count( $_POST, COUNT_RECURSIVE ) >= $max_input_vars ){
+ $EM_Notices->add_error( sprintf( esc_html__('Your settings were not saved. The settings form sends more fields than your server accepts, so PHP cut the request short. Ask your host to raise the PHP setting %1$s from %2$d to 3000 or more.', 'events-manager'), '<code>max_input_vars</code>', $max_input_vars ) );
+ }
+ }
/*
* Here's the idea, we have an array of all options that need super admin approval if in multi-site mode
* since options are only updated here, its one place fit all
@@ -16,9 +26,11 @@
// only run this if saving main CPT options
if ( defined('EM_SETTINGS_ARCHETYPES_MERGED') && EM_SETTINGS_ARCHETYPES_MERGED || Archetypes::get_current() === Archetypes::$event['cpt'] ) {
- // fix some known empty issues, such as phone multiselectors
- if ( !isset($_POST['dbem_phone_countries_include']) ) $_POST['dbem_phone_countries_include'] = [];
- if ( !isset($_POST['dbem_phone_countries_exclude']) ) $_POST['dbem_phone_countries_exclude'] = [];
+ // fix some known empty issues, such as phone multiselectors, but only when the general tab holding them was submitted
+ if ( !defined('EM_SETTINGS_TABS') || !EM_SETTINGS_TABS || empty($_REQUEST['em_tab']) || $_REQUEST['em_tab'] === 'general' ) {
+ if ( !isset($_POST['dbem_phone_countries_include']) ) $_POST['dbem_phone_countries_include'] = [];
+ if ( !isset($_POST['dbem_phone_countries_exclude']) ) $_POST['dbem_phone_countries_exclude'] = [];
+ }
foreach ($_POST as $postKey => $postValue){
if( $postKey != 'dbem_data' && substr($postKey, 0, 5) == 'dbem_' ){
@@ -558,7 +570,7 @@
$bookings_placeholder_tip = " ". sprintf(__('This accepts %s, %s and %s placeholders.','events-manager'), $bookings_placeholders, $events_placeholders, $locations_placeholders);
global $save_button;
- $save_button = '<tr><th> </th><td><p class="submit" style="margin:0px; padding:0px; text-align:right;"><input type="submit" class="button-primary" name="Submit" value="'. __( 'Save Changes', 'events-manager') .' ('. __('All','events-manager') .')" /></p></td></tr>';
+ $save_button = '<tr><th> </th><td><p class="submit" style="margin:0px; padding:0px; text-align:right;"><input type="submit" class="button-primary" name="Submit" value="'. __( 'Save Changes', 'events-manager') .( defined('EM_SETTINGS_TABS') && EM_SETTINGS_TABS ? '' : ' ('. __('All','events-manager') .')' ).'" /></p></td></tr>';
do_action('em_options_page_header');
@@ -569,8 +581,10 @@
$formats_tab_link = esc_url(add_query_arg( array('em_tab'=>'formats')));
$bookings_tab_link = esc_url(add_query_arg( array('em_tab'=>'bookings')));
$emails_tab_link = esc_url(add_query_arg( array('em_tab'=>'emails')));
+ $active_tab = !empty($_GET['em_tab']) ? sanitize_key($_GET['em_tab']) : 'general';
}else{
$general_tab_link = $pages_tab_link = $formats_tab_link = $bookings_tab_link = $emails_tab_link = '';
+ $active_tab = 'general';
}
$current_archetype = ($_REQUEST['post_type'] ?? '') === Archetypes::$event['cpt'] ? 'all' : Archetypes::get_current();
?>
@@ -602,13 +616,13 @@
</ul>
<?php endif; ?>
<h2 class="nav-tab-wrapper">
- <a href="<?php echo $general_tab_link; ?>#general" id="em-menu-general" class="nav-tab nav-tab-active"><?php _e('General','events-manager'); ?></a>
- <a href="<?php echo $pages_tab_link; ?>#pages" id="em-menu-pages" class="nav-tab"><?php _e('Pages','events-manager'); ?></a>
- <a href="<?php echo $formats_tab_link; ?>#formats" id="em-menu-formats" class="nav-tab"><?php _e('Formatting','events-manager'); ?></a>
+ <a href="<?php echo $general_tab_link; ?>#general" id="em-menu-general" class="nav-tab <?php if( $active_tab === 'general' ) echo 'nav-tab-active'; ?>"><?php _e('General','events-manager'); ?></a>
+ <a href="<?php echo $pages_tab_link; ?>#pages" id="em-menu-pages" class="nav-tab <?php if( $active_tab === 'pages' ) echo 'nav-tab-active'; ?>"><?php _e('Pages','events-manager'); ?></a>
+ <a href="<?php echo $formats_tab_link; ?>#formats" id="em-menu-formats" class="nav-tab <?php if( $active_tab === 'formats' ) echo 'nav-tab-active'; ?>"><?php _e('Formatting','events-manager'); ?></a>
<?php if( get_option('dbem_rsvp_enabled') ): ?>
- <a href="<?php echo $bookings_tab_link; ?>#bookings" id="em-menu-bookings" class="nav-tab"><?php _e('Bookings','events-manager'); ?></a>
+ <a href="<?php echo $bookings_tab_link; ?>#bookings" id="em-menu-bookings" class="nav-tab <?php if( $active_tab === 'bookings' ) echo 'nav-tab-active'; ?>"><?php _e('Bookings','events-manager'); ?></a>
<?php endif; ?>
- <a href="<?php echo $emails_tab_link; ?>#emails" id="em-menu-emails" class="nav-tab"><?php _e('Emails','events-manager'); ?></a>
+ <a href="<?php echo $emails_tab_link; ?>#emails" id="em-menu-emails" class="nav-tab <?php if( $active_tab === 'emails' ) echo 'nav-tab-active'; ?>"><?php _e('Emails','events-manager'); ?></a>
<?php
$custom_tabs = apply_filters('em_options_page_tabs', array());
foreach( $custom_tabs as $tab_key => $tab_name ){
--- a/events-manager/admin/settings/tabs/bookings.php
+++ b/events-manager/admin/settings/tabs/bookings.php
@@ -129,7 +129,9 @@
em_options_radio_binary ( __( 'Choose tickets on the event page?', 'events-manager'), 'dbem_bookings_checkout_card_tickets', __( 'If enabled, the booking card lists the tickets with a total, and the checkout opens with the chosen tickets at the booking details. Events with a date or time to choose first keep the card that asks for it. Applies when booking through the checkout.', 'events-manager') );
em_options_radio_binary ( __( 'Display login form?', 'events-manager'), 'dbem_bookings_login_form', __( 'Choose whether or not to display a login form in the booking form area to remind your members to log in before booking.', 'events-manager') );
em_options_radio_binary ( __( 'Hide form until tickets selected?', 'events-manager'), 'dbem_bookings_form_hide_dynamic', __( 'If enabled, the entire booking form will show once a space is selected, or if an ticket is already pre-selected with minimum spaces.', 'events-manager') );
- em_options_select ( __( 'Recurring Events Picker', 'events-manager'), 'dbem_recurrence_picker', ['select' => __('Dropdown Selection', 'events-manager'), 'calendar' => __('Calendar Selection', 'events-manager')], __( 'Recurring events have a picker in order to load the right booking form, choose your picker style for your booking forms.', 'events-manager') );
+ em_options_select ( __( 'Recurring Events Picker', 'events-manager'), 'dbem_recurrence_picker', ['select' => __('Dropdown Selection', 'events-manager'), 'calendar' => __('Calendar Selection', 'events-manager'), 'dates' => __('Date Strip Selection', 'events-manager')], __( 'Recurring events have a picker in order to load the right booking form, choose your picker style for your booking forms.', 'events-manager'), '', ['dates' => '#dbem_bookings_dates_show_empty_row, #dbem_bookings_dates_show_fully_booked_row'] );
+ em_options_radio_binary ( __( 'Show days without dates?', 'events-manager'), 'dbem_bookings_dates_show_empty', __( 'If enabled, the date strip lists every day and grays out the ones that cannot be booked, otherwise it lists only the dates of the event.', 'events-manager') );
+ em_options_radio_binary ( __( 'Show fully booked dates?', 'events-manager'), 'dbem_bookings_dates_show_fully_booked', __( 'If enabled, fully booked dates are marked as sold out in the date strip, otherwise they are treated as days that cannot be booked.', 'events-manager') );
em_options_input_text ( __( 'Submit button text', 'events-manager'), 'dbem_bookings_submit_button', sprintf(__( 'The text used by the submit button. To use an image instead, enter the full url starting with %s or %s.', 'events-manager'), '<code>http://</code>','<code>https://</code>') ). ' ' . __( 'This button text would be shown for a free booking', 'events-manager');
em_options_input_text ( __( 'Submit button text (payment)', 'events-manager'), 'dbem_bookings_submit_button_paid', sprintf(__( 'The text shown when a booking is not free, %s will be replaced by the total amount due.', 'events-manager'), '<code>%s</code>'). ' <strong>' . __( 'This text will be shown only if the default (free) button is not an image.', 'events-manager') . '</strong>' );
em_options_input_text ( __( 'Submit button text (processing)', 'events-manager'), 'dbem_bookings_submit_button_processing', sprintf(__( 'The text shown when a booking is being submitted, %s will be replaced by the total amount due.', 'events-manager'), '<code>%s</code>'). ' <strong>' . __( 'This text will be shown only if the default (free) button is not an image.', 'events-manager') . '</strong>' );
@@ -247,6 +249,28 @@
</div> <!-- . inside -->
</div> <!-- .postbox -->
+ <div class="postbox " id="em-opt-conversion-tracking" >
+ <div class="handlediv" title="<?php __('Click to toggle', 'events-manager'); ?>"><br /></div><h3><span><?php esc_html_e('Conversion Tracking','events-manager'); ?> </span></h3>
+ <div class="inside">
+ <table class='form-table'>
+ <tr><td colspan='2'>
+ <p><?php esc_html_e('Report bookings to your analytics and advertising tools as ecommerce events: viewing an event that can be booked, starting a booking, choosing a payment method, and a purchase once a booking is placed, or a lead for a free booking. A booking paid on the payment provider's own page is reported once its payment arrives.','events-manager'); ?></p>
+ </td></tr>
+ <?php
+ em_options_radio_binary ( __( 'Track bookings as conversions?', 'events-manager'), 'dbem_conversion_tracking', __( 'If enabled, these events are pushed to the page's dataLayer for Google Tag Manager, and sent to each destination turned on below.', 'events-manager'), '', '.em-conversion-tracking-options' );
+ ?>
+ <tbody class="em-conversion-tracking-options">
+ <?php
+ em_options_select ( __( 'Report free bookings as', 'events-manager'), 'dbem_conversion_tracking_free', array( 'lead' => __( 'A lead', 'events-manager' ), 'purchase' => __( 'A purchase of zero', 'events-manager' ) ), __( 'Paid bookings are always reported as a purchase of the booking total, including bookings paid by deposit.', 'events-manager'), 'lead' );
+ EMConversion_Tracking::output_settings();
+ do_action('em_options_page_conversion_tracking_bottom');
+ ?>
+ </tbody>
+ <?php echo $save_button; ?>
+ </table>
+ </div> <!-- . inside -->
+ </div> <!-- .postbox -->
+
<div class="postbox " id="em-opt-no-user-bookings" >
<div class="handlediv" title="<?php __('Click to toggle', 'events-manager'); ?>"><br /></div><h3><span><?php _e('No-User Booking Mode','events-manager'); ?> </span></h3>
<div class="inside">
--- a/events-manager/buddypress/bp-em-activity.php
+++ b/events-manager/buddypress/bp-em-activity.php
@@ -126,7 +126,7 @@
function bp_em_record_activity_event_save( $result, $EM_Event ){
if( $result && $EM_Event->event_status == 1 && $EM_Event->get_previous_status() != 1 ){
$user = get_userdata($EM_Event->event_owner);
- $member_link = bp_core_get_user_domain($user->ID);
+ $member_link = function_exists('bp_members_get_user_url') ? bp_members_get_user_url($user->ID) : bp_core_get_user_domain($user->ID);
if( empty($EM_Event->group_id) ){
bp_em_record_activity( array(
'user_id' => $user->ID,
@@ -166,7 +166,7 @@
$EM_Booking->last_bp_activity = $action_type;
$rejected_statuses = array(0,2,3); //these statuses apply to rejected/cancelled bookings
$user = $EM_Booking->get_person();
- $member_link = bp_core_get_user_domain($user->ID);
+ $member_link = function_exists('bp_members_get_user_url') ? bp_members_get_user_url($user->ID) : bp_core_get_user_domain($user->ID);
$user_link = "<a href='".$member_link."/'>".$user->display_name."</a>";
$event_link = $EM_Booking->get_event()->output('#_EVENTLINK');
$status = $EM_Booking->booking_status;
--- a/events-manager/buddypress/screens/my-events.php
+++ b/events-manager/buddypress/screens/my-events.php
@@ -44,9 +44,9 @@
global $EM_Event;
if( is_object($EM_Event) ){
if($EM_Event->is_recurring( true )){
- echo __( "Reschedule Events", 'events-manager')." '{$EM_Event->event_name}'";
+ echo __( "Reschedule Events", 'events-manager')." '". esc_html($EM_Event->event_name) ."'";
}else{
- echo __( "Edit Event", 'events-manager') . " '" . $EM_Event->event_name . "'";
+ echo __( "Edit Event", 'events-manager') . " '" . esc_html($EM_Event->event_name) . "'";
}
}else{
_e( 'Add Event', 'events-manager');
--- a/events-manager/classes/api/em-api-service.php
+++ b/events-manager/classes/api/em-api-service.php
@@ -360,7 +360,7 @@
}
// Terms also go on as soon as the event's post exists, because saving a repeating event copies the template's tags to its recurrences before save() returns. They are applied again afterwards since EM's own category save runs after the post insert.
$apply_terms = function( $post_id, $post ) use ( $EM_Event, $data, &$apply_terms ) {
- if ( !in_array( $post->post_type, array( EM_POST_TYPE_EVENT, 'event-recurring' ), true ) ) return;
+ if ( !in_array( $post->post_type, array( EM_POST_TYPE_EVENT, 'event-recurring' ), true ) && !EMArchetypes::is_event( $post->post_type ) ) return;
remove_action( 'wp_insert_post', $apply_terms, 10 );
static::save_event_terms( $EM_Event, $data, $post_id );
};
@@ -589,7 +589,10 @@
protected static function list_location_geo_column( $column, $params, $filter_columns ) {
global $wpdb;
$params = Utils::normalize_input( $params );
- $conds = array();
+ $conds = array( 'location_status = 1' );
+ if ( !current_user_can( 'read_private_locations' ) ) {
+ $conds[] = 'location_private = 0';
+ }
foreach ( $filter_columns as $filter ) {
if ( !empty( $params[ $filter ] ) ) {
$conds[] = $wpdb->prepare( "location_{$filter} = %s", sanitize_text_field( $params[ $filter ] ) );
@@ -798,7 +801,7 @@
return Utils::error( 'em_api_booking_forbidden', __( 'You do not have permission to create bookings through the API.', 'events-manager' ), 403 );
}
// Booking-manager authority is per event, so resolve the event being booked and check management against it. On create $EM_Booking is unsaved, so its own can_manage() is unconditionally true, and the site-wide manage_bookings capability (held by contributors and authors by default) would otherwise let a caller manage bookings on events they do not own.
- $target_event_id = $data['event_id'] ?? $data['event'] ?? ( !empty( $EM_Booking->event_id ) ? $EM_Booking->event_id : 0 );
+ $target_event_id = static::booking_event_id( $data, $EM_Booking );
$target_event = $target_event_id ? em_get_event( $target_event_id ) : false;
if ( $target_event && $target_event->event_id ) {
$can_manage_target = $target_event->can_manage( 'manage_bookings', 'manage_others_bookings' );
@@ -811,6 +814,10 @@
if ( !$id && $target_event && $target_event->event_id && !$can_manage_target && !static::can_read_event( $target_event ) ) {
return Utils::error( 'em_api_event_forbidden', __( 'You do not have permission to view this event.', 'events-manager' ), 403 );
}
+ // Moving a saved booking to another event needs booking management rights there too, otherwise a booking manager could move one onto an event they cannot read and read it from the response.
+ if ( $id && $target_event && $target_event->event_id && $target_event->event_id != $EM_Booking->event_id && !$can_manage_target ) {
+ return Utils::error( 'em_api_booking_forbidden', __( 'You do not have permission to save this booking.', 'events-manager' ), 403 );
+ }
// Let an add-on (Events Manager Pro) reshape the request data — e.g. map a structured booker `person` object onto the booking-form field names. Core books under the authenticated account, so it leaves the request data as-is.
$request_data = apply_filters( 'em_api_booking_request_data', static::booking_request_data( $data, $EM_Booking, $can_manage_target ), $data, $EM_Booking, $id );
// The gateway is only applied when a booking is made, so an update naming a different one would report success while changing nothing; a free booking is made without one, so there it is ignored unless the update makes the booking paid.
@@ -1505,15 +1512,39 @@
* admin-only fields (booking_tax_rate, person_id, booking_status, manual_booking*,
* payment_*) when the caller is not a booking manager.
*/
+ /**
+ * The event a booking request is for, read in one place so the event checked for access is the event booked. A top-level event_id or event wins; otherwise one inside a booking-form group is used, then the booking's own event.
+ * @param array $data
+ * @param EM_Booking $EM_Booking
+ * @return int|string
+ */
+ protected static function booking_event_id( $data, $EM_Booking ) {
+ $event_id = $data['event_id'] ?? $data['event'] ?? null;
+ if ( $event_id === null ) {
+ foreach ( static::BOOKING_FIELD_GROUPS as $key ) {
+ if ( isset( $data[ $key ] ) && is_array( $data[ $key ] ) && isset( $data[ $key ]['event_id'] ) ) {
+ $event_id = $data[ $key ]['event_id'];
+ break;
+ }
+ }
+ }
+ if ( $event_id === null ) {
+ $event_id = !empty( $EM_Booking->event_id ) ? $EM_Booking->event_id : 0;
+ }
+ return $event_id;
+ }
+
protected static function booking_request_data( $data, $EM_Booking, $can_manage_target = false ) {
$request = $data;
- $request['event_id'] = $data['event_id'] ?? $data['event'] ?? $EM_Booking->event_id ?? null;
+ $event_id = static::booking_event_id( $data, $EM_Booking );
// Flatten booking-form sub-objects so EM_Form / Pro forms read them from $_REQUEST.
foreach ( static::BOOKING_FIELD_GROUPS as $key ) {
if ( !empty( $data[ $key ] ) && is_array( $data[ $key ] ) ) {
$request = array_merge( $request, $data[ $key ] );
}
}
+ // Set after flattening, since a group's own event_id would otherwise replace the event save_booking() checked.
+ $request['event_id'] = $event_id ? $event_id : null;
// Liberal input: agents sometimes prefix booking-form fields. EM core reads them by
// bare fieldid, so strip a `booking_form_field_` prefix before they reach $_REQUEST.
foreach ( $request as $key => $value ) {
--- a/events-manager/classes/checkout/booking-checkout.php
+++ b/events-manager/classes/checkout/booking-checkout.php
@@ -38,6 +38,18 @@
public static function init() {
add_action( 'init', array( static::class, 'hooks' ) );
+ add_action( 'em_admin_notice_v-update', array( static::class, 'upgrade_notice' ) );
+ }
+
+ /**
+ * Takes down the 7.7 upgrade notice once the checkout is on, as it says the booking form stays as it is until the checkout is switched on. Every version's notice is named v-update, so that one is known by its post link.
+ * @param EM_Admin_Notice $EM_Admin_Notice
+ */
+ public static function upgrade_notice( $EM_Admin_Notice ) {
+ if ( strpos( (string) $EM_Admin_Notice->message, 'pxlink.cc/em-7-7' ) !== false && static::is_enabled() ) {
+ EM_Admin_Notices::remove( $EM_Admin_Notice->name, $EM_Admin_Notice->network );
+ $EM_Admin_Notice->name = '';
+ }
}
/**
--- a/events-manager/classes/conversion-tracking/destination.php
+++ b/events-manager/classes/conversion-tracking/destination.php
@@ -0,0 +1,231 @@
+<?php
+namespace EMConversion_Tracking;
+
+/**
+ * A place bookings are reported to, such as an analytics or advertising platform: its row in the Conversion Tracking settings, its saved settings in dbem_conversion_tracking_destinations under its id, and what the tracking script gets to send it events and add its tag, through the adapter of the same id in includes/js/conversion-tracking.js.
+ *
+ * Destinations are registered by id with the em_conversion_tracking_destinations filter, see EMConversion_Tracking::get_destinations().
+ */
+abstract class Destination {
+
+ /**
+ * Its id: the key of its settings and of its adapter in the tracking script.
+ * @var string
+ */
+ public static $id = '';
+
+ /**
+ * The group it is listed under in the settings: tags, analytics or ads.
+ * @var string
+ */
+ public static $group = 'analytics';
+
+ /**
+ * The consent category its tag waits for with a WP Consent API plugin: statistics or marketing.
+ * @var string
+ */
+ public static $consent = 'statistics';
+
+ /**
+ * Whether it is sent events through a tag the page already has, such as one Site Kit, a Pixel plugin or the theme adds. Such a destination is on until it is turned off, since it sends nothing on a page without its tag.
+ * @var bool
+ */
+ public static $detected = true;
+
+ /**
+ * Its name as the settings show it.
+ * @return string
+ */
+ abstract public static function get_name();
+
+ /**
+ * What it is sent and how, under its name in the settings.
+ * @return string
+ */
+ public static function get_description() {
+ return '';
+ }
+
+ /**
+ * What its tag is called in the settings, such as "the Google tag".
+ * @return string
+ */
+ public static function get_tag_name() {
+ return static::get_name();
+ }
+
+ /**
+ * Its settings fields, by key, each with 'label' and 'description', and optionally 'pattern' (a regular expression a value must match to be used), 'case' (upper or lower), 'type' (text or url), 'placeholder' and 'default' (used while the field is empty). The keys enabled and add_tag are taken.
+ * @return array[]
+ */
+ public static function get_fields() {
+ return array();
+ }
+
+ /**
+ * Whether Events Manager can add its tag to the site.
+ * @return bool
+ */
+ public static function can_add_tag() {
+ return true;
+ }
+
+ /**
+ * What its tag needs from its fields to be added by the tracking script's adapter, or null while they do not allow it.
+ * @return array|null
+ */
+ public static function get_tag() {
+ return null;
+ }
+
+ /**
+ * Its saved settings: enabled, add_tag and its fields.
+ * @return array
+ */
+ public static function get_settings() {
+ $settings = em_get_option( 'dbem_conversion_tracking_destinations' );
+ return is_array( $settings ) && isset( $settings[ static::$id ] ) && is_array( $settings[ static::$id ] ) ? $settings[ static::$id ] : array();
+ }
+
+ /**
+ * Whether bookings are reported to it: as saved, or until its settings are saved, whether it is sent events through a tag the page already has (see $detected).
+ * @return bool
+ */
+ public static function is_enabled() {
+ $settings = static::get_settings();
+ return isset( $settings['enabled'] ) ? ! empty( $settings['enabled'] ) : static::$detected;
+ }
+
+ /**
+ * A field's saved value, or its default, when it is valid, otherwise an empty string.
+ * @param string $key
+ * @return string
+ */
+ public static function get_field( $key ) {
+ $fields = static::get_fields();
+ if ( empty( $fields[ $key ] ) ) {
+ return '';
+ }
+ $settings = static::get_settings();
+ $value = isset( $settings[ $key ] ) && is_scalar( $settings[ $key ] ) ? static::clean_value( $settings[ $key ], $fields[ $key ] ) : '';
+ if ( $value === '' && ! empty( $fields[ $key ]['default'] ) ) {
+ $value = $fields[ $key ]['default'];
+ }
+ return static::is_valid( $value, $fields[ $key ] ) ? $value : '';
+ }
+
+ /**
+ * Whether its tag is to be added to the site: asked for, and its fields allow it.
+ * @return bool
+ */
+ public static function adds_tag() {
+ $settings = static::get_settings();
+ return static::can_add_tag() && ! empty( $settings['add_tag'] ) && static::get_tag() !== null;
+ }
+
+ /**
+ * What the tracking script gets for it while it is enabled, as EM_Conversion_Tracking.destinations[id]: the consent category its tag waits for, and the tag to add when it is to be added.
+ * @return array
+ */
+ public static function get_script_vars() {
+ $vars = array( 'consent' => static::$consent );
+ if ( static::adds_tag() ) {
+ $vars['tag'] = static::get_tag();
+ }
+ return $vars;
+ }
+
+ /**
+ * Its settings as saved from the settings form: enabled and add_tag as 0 or 1, and each of its fields trimmed, in the case it asks for. Anything else is dropped.
+ * @param array $raw
+ * @return array
+ */
+ public static function sanitize( $raw ) {
+ $raw = is_array( $raw ) ? $raw : array();
+ $clean = array(
+ 'enabled' => empty( $raw['enabled'] ) ? 0 : 1,
+ 'add_tag' => empty( $raw['add_tag'] ) || ! static::can_add_tag() ? 0 : 1,
+ );
+ foreach ( static::get_fields() as $key => $field ) {
+ $clean[ $key ] = isset( $raw[ $key ] ) && is_scalar( $raw[ $key ] ) ? static::clean_value( sanitize_text_field( (string) $raw[ $key ] ), $field ) : '';
+ }
+ return $clean;
+ }
+
+ protected static function clean_value( $value, $field ) {
+ $value = trim( (string) $value );
+ if ( ! empty( $field['case'] ) ) {
+ $value = $field['case'] === 'upper' ? strtoupper( $value ) : strtolower( $value );
+ }
+ if ( ! empty( $field['type'] ) && $field['type'] === 'url' && $value !== '' ) {
+ $value = esc_url_raw( $value, array( 'https', 'http' ) );
+ }
+ return $value;
+ }
+
+ protected static function is_valid( $value, $field ) {
+ return $value !== '' && ( empty( $field['pattern'] ) || preg_match( $field['pattern'], $value ) );
+ }
+
+ /**
+ * Prints its rows in the Conversion Tracking settings: a switch that turns it on and shows its fields, then its fields, whether to add its tag, and the rows add-ons print for it on em_conversion_tracking_destination_fields.
+ */
+ public static function output_settings() {
+ $id = static::$id;
+ $settings = static::get_settings();
+ $enabled = static::is_enabled();
+ $name = 'dbem_conversion_tracking_destinations[' . $id . ']';
+ $rows = 'em-conversion-tracking-' . $id . '-options';
+ $class = $rows . ( $enabled ? '' : ' hidden' );
+ ?>
+ <tr valign="top" class="em-conversion-tracking-destination" id="em-conversion-tracking-<?php echo esc_attr( $id ); ?>" data-group="<?php echo esc_attr( static::$group ); ?>">
+ <th scope="row"><?php echo esc_html( static::get_name() ); ?></th>
+ <td>
+ <label>
+ <input type="checkbox" name="<?php echo esc_attr( $name ); ?>[enabled]" value="1" class="em-trigger" data-trigger=".<?php echo esc_attr( $rows ); ?>" <?php checked( $enabled ); ?>>
+ <?php echo esc_html( sprintf( __( 'Send booking events to %s', 'events-manager' ), static::get_name() ) ); ?>
+ </label>
+ <?php if ( static::get_description() ) : ?>
+ <br><em><?php echo esc_html( static::get_description() ); ?></em>
+ <?php endif; ?>
+ </td>
+ </tr>
+ <?php foreach ( static::get_fields() as $key => $field ) : ?>
+ <?php
+ $value = isset( $settings[ $key ] ) && is_scalar( $settings[ $key ] ) ? (string) $settings[ $key ] : '';
+ $field_id = 'em-conversion-tracking-' . $id . '-' . $key;
+ ?>
+ <tr valign="top" class="<?php echo esc_attr( $class ); ?>">
+ <th scope="row"><label for="<?php echo esc_attr( $field_id ); ?>"><?php echo esc_html( $field['label'] ); ?></label></th>
+ <td>
+ <input type="text" id="<?php echo esc_attr( $field_id ); ?>" name="<?php echo esc_attr( $name . '[' . $key . ']' ); ?>" value="<?php echo esc_attr( $value ); ?>" size="45" <?php if ( ! empty( $field['placeholder'] ) ) echo 'placeholder="' . esc_attr( $field['placeholder'] ) . '"'; ?>>
+ <?php if ( ! empty( $field['description'] ) ) : ?>
+ <br><em><?php echo esc_html( $field['description'] ); ?></em>
+ <?php endif; ?>
+ <?php if ( trim( $value ) !== '' && static::get_field( $key ) === '' ) : ?>
+ <br><strong class="em-conversion-tracking-invalid"><?php esc_html_e( 'This is not in the format shown, so it is not used.', 'events-manager' ); ?></strong>
+ <?php endif; ?>
+ </td>
+ </tr>
+ <?php endforeach; ?>
+ <?php if ( static::can_add_tag() ) : ?>
+ <?php $add_tag = ! empty( $settings['add_tag'] ); ?>
+ <tr valign="top" class="<?php echo esc_attr( $class ); ?>">
+ <th scope="row"><?php esc_html_e( 'Add its tag to the site?', 'events-manager' ); ?></th>
+ <td>
+ <?php esc_html_e( 'Yes', 'events-manager' ); ?> <input name="<?php echo esc_attr( $name ); ?>[add_tag]" type="radio" value="1" <?php checked( $add_tag ); ?>>
+ <?php esc_html_e( 'No', 'events-manager' ); ?> <input name="<?php echo esc_attr( $name ); ?>[add_tag]" type="radio" value="0" <?php checked( ! $add_tag ); ?>>
+ <br><em><?php echo esc_html( sprintf( __( 'If enabled, %1$s is added to every page for the details above, unless the page already has it. Leave this off if a plugin or your theme already adds it, or visits are counted twice. With a consent plugin that supports the WP Consent API, it waits for consent to %2$s.', 'events-manager' ), static::get_tag_name(), static::$consent === 'marketing' ? __( 'marketing', 'events-manager' ) : __( 'statistics', 'events-manager' ) ) ); ?></em>
+ </td>
+ </tr>
+ <?php endif; ?>
+ <?php
+ /**
+ * Prints further rows for a destination in the Conversion Tracking settings, after its own, such as the Conversion Tracking add-on's server fields. Give each row the class passed so it shows only while the destination is on.
+ * @param string $id the destination's id
+ * @param string $class the destination's class
+ * @param string $row_class the class its rows have
+ */
+ do_action( 'em_conversion_tracking_destination_fields', $id, static::class, $class );
+ }
+}
--- a/events-manager/classes/conversion-tracking/destinations/fathom.php
+++ b/events-manager/classes/conversion-tracking/destinations/fathom.php
@@ -0,0 +1,45 @@
+<?php
+namespace EMConversion_TrackingDestinations;
+
+use EMConversion_TrackingDestination;
+
+/**
+ * Fathom, sent each booking event, with a purchase's value in cents.
+ */
+class Fathom extends Destination {
+
+ public static $id = 'fathom';
+
+ public static $group = 'analytics';
+
+ public static $consent = 'statistics';
+
+ public static function get_name() {
+ return 'Fathom';
+ }
+
+ public static function get_description() {
+ return __( 'Booking events are sent to Fathom whenever the page loads its script, for example from the Fathom plugin. To have Events Manager load it, enter your site ID and add its tag.', 'events-manager' );
+ }
+
+ public static function get_tag_name() {
+ return __( 'Fathom's script', 'events-manager' );
+ }
+
+ public static function get_fields() {
+ return array(
+ 'site_id' => array(
+ 'label' => __( 'Site ID', 'events-manager' ),
+ 'description' => __( 'Your site ID in Fathom, found in its embed code as data-site, such as ABCDEFGH.', 'events-manager' ),
+ 'pattern' => '/^[A-Z0-9]+$/',
+ 'case' => 'upper',
+ 'placeholder' => 'ABCDEFGH',
+ ),
+ );
+ }
+
+ public static function get_tag() {
+ $id = static::get_field( 'site_id' );
+ return $id ? array( 'id' => $id ) : null;
+ }
+}
--- a/events-manager/classes/conversion-tracking/destinations/ga4.php
+++ b/events-manager/classes/conversion-tracking/destinations/ga4.php
@@ -0,0 +1,45 @@
+<?php
+namespace EMConversion_TrackingDestinations;
+
+use EMConversion_TrackingDestination;
+
+/**
+ * Google Analytics 4, sent GA4's own ecommerce events through the Google tag (gtag.js).
+ */
+class GA4 extends Destination {
+
+ public static $id = 'ga4';
+
+ public static $group = 'analytics';
+
+ public static $consent = 'statistics';
+
+ public static function get_name() {
+ return __( 'Google Analytics 4', 'events-manager' );
+ }
+
+ public static function get_description() {
+ return __( 'Booking events are sent through the Google tag when the page has it, for example from Site Kit or your theme.', 'events-manager' );
+ }
+
+ public static function get_tag_name() {
+ return __( 'the Google tag', 'events-manager' );
+ }
+
+ public static function get_fields() {
+ return array(
+ 'measurement_id' => array(
+ 'label' => __( 'Measurement ID', 'events-manager' ),
+ 'description' => __( 'Your GA4 measurement ID, such as G-ABC123XYZ. Only needed to add the Google tag to the site.', 'events-manager' ),
+ 'pattern' => '/^G-[A-Z0-9]+$/',
+ 'case' => 'upper',
+ 'placeholder' => 'G-ABC123XYZ',
+ ),
+ );
+ }
+
+ public static function get_tag() {
+ $id = static::get_field( 'measurement_id' );
+ return $id ? array( 'id' => $id ) : null;
+ }
+}
--- a/events-manager/classes/conversion-tracking/destinations/gtm.php
+++ b/events-manager/classes/conversion-tracking/destinations/gtm.php
@@ -0,0 +1,47 @@
+<?php
+namespace EMConversion_TrackingDestinations;
+
+use EMConversion_TrackingDestination;
+
+/**
+ * Google Tag Manager. Booking events are always pushed to the page's dataLayer, where a container's triggers pick them up, so this destination only adds a container to the site.
+ */
+class GTM extends Destination {
+
+ public static $id = 'gtm';
+
+ public static $group = 'tags';
+
+ public static $consent = 'statistics';
+
+ public static $detected = false;
+
+ public static function get_name() {
+ return __( 'Google Tag Manager', 'events-manager' );
+ }
+
+ public static function get_description() {
+ return __( 'Booking events are always pushed to the page's dataLayer as GA4 ecommerce events, ready for the triggers of a Tag Manager container on the site. Turn this on to have Events Manager add your container.', 'events-manager' );
+ }
+
+ public static function get_tag_name() {
+ return __( 'your Tag Manager container', 'events-manager' );
+ }
+
+ public static function get_fields() {
+ return array(
+ 'container_id' => array(
+ 'label' => __( 'Container ID', 'events-manager' ),
+ 'description' => __( 'Your Tag Manager container ID, such as GTM-ABC1234.', 'events-manager' ),
+ 'pattern' => '/^GTM-[A-Z0-9]+$/',
+ 'case' => 'upper',
+ 'placeholder' => 'GTM-ABC1234',
+ ),
+ );
+ }
+
+ public static function get_tag() {
+ $id = static::get_field( 'container_id' );
+ return $id ? array( 'id' => $id ) : null;
+ }
+}
--- a/events-manager/classes/conversion-tracking/destinations/matomo.php
+++ b/events-manager/classes/conversion-tracking/destinations/matomo.php
@@ -0,0 +1,52 @@
+<?php
+namespace EMConversion_TrackingDestinations;
+
+use EMConversion_TrackingDestination;
+
+/**
+ * Matomo, sent a purchase as an ecommerce order, which Matomo counts once per order ID, and the other booking events as events in a Bookings category.
+ */
+class Matomo extends Destination {
+
+ public static $id = 'matomo';
+
+ public static $group = 'analytics';
+
+ public static $consent = 'statistics';
+
+ public static function get_name() {
+ return 'Matomo';
+ }
+
+ public static function get_description() {
+ return __( 'Booking events are sent to Matomo whenever the page loads its tracking code, for example from a Matomo plugin. Purchases are ecommerce orders, so turn on ecommerce for the site in Matomo. To have Events Manager load it, enter your Matomo address and site ID and add its tag.', 'events-manager' );
+ }
+
+ public static function get_tag_name() {
+ return __( 'Matomo's tracking code', 'events-manager' );
+ }
+
+ public static function get_fields() {
+ return array(
+ 'url' => array(
+ 'label' => __( 'Matomo URL', 'events-manager' ),
+ 'description' => __( 'The address of your Matomo, such as https://example.matomo.cloud/ or your own server's.', 'events-manager' ),
+ 'type' => 'url',
+ 'pattern' => '#^https?://S+$#i',
+ 'placeholder' => 'https://example.matomo.cloud/',
+ ),
+ 'site_id' => array(
+ 'label' => __( 'Site ID', 'events-manager' ),
+ 'description' => __( 'The ID Matomo gives this website, which is a number.', 'events-manager' ),
+ 'pattern' => '/^[0-9]+$/',
+ 'placeholder' => '1',
+ ),
+ );
+ }
+
+ public static function get_tag() {
+ $url = static::get_field( 'url' );
+ $site_id = static::get_field( 'site_id' );
+ return $url && $site_id ? array( 'url' => trailingslashit( $url ), 'site_id' => $site_id ) : null;
+ }
+}
--- a/events-manager/classes/conversion-tracking/destinations/meta-pixel.php
+++ b/events-manager/classes/conversion-tracking/destinations/meta-pixel.php
@@ -0,0 +1,44 @@
+<?php
+namespace EMConversion_TrackingDestinations;
+
+use EMConversion_TrackingDestination;
+
+/**
+ * The Meta Pixel, which counts for Facebook and Instagram ads, sent Meta's standard events with the event ID a server copy of the same event shares.
+ */
+class Meta_Pixel extends Destination {
+
+ public static $id = 'meta';
+
+ public static $group = 'ads';
+
+ public static $consent = 'marketing';
+
+ public static function get_name() {
+ return __( 'Meta Pixel', 'events-manager' );
+ }
+
+ public static function get_description() {
+ return __( 'Booking events are sent to the Meta Pixel as Meta's standard events (ViewContent, InitiateCheckout, AddPaymentInfo, Purchase and Lead) when the page has it, for example from a Pixel plugin. Counts for Facebook and Instagram ads.', 'events-manager' );
+ }
+
+ public static function get_tag_name() {
+ return __( 'the Meta Pixel', 'events-manager' );
+ }
+
+ public static function get_fields() {
+ return array(
+ 'pixel_id' => array(
+ 'label' => __( 'Pixel ID', 'events-manager' ),
+ 'description' => __( 'Your Meta Pixel ID, which is a number. Only needed to add the Pixel to the site.', 'events-manager' ),
+ 'pattern' => '/^[0-9]+$/',
+ 'placeholder' => '1234567890',
+ ),
+ );
+ }
+
+ public static function get_tag() {
+ $id = static::get_field( 'pixel_id' );
+ return $id ? array( 'id' => $id ) : null;
+ }
+}
--- a/events-manager/classes/conversion-tracking/destinations/plausible.php
+++ b/events-manager/classes/conversion-tracking/destinations/plausible.php
@@ -0,0 +1,45 @@
+<?php
+namespace EMConversion_TrackingDestinations;
+
+use EMConversion_TrackingDestination;
+
+/**
+ * Plausible, sent each booking event as a custom event with its details as properties, and a purchase's revenue.
+ */
+class Plausible extends Destination {
+
+ public static $id = 'plausible';
+
+ public static $group = 'analytics';
+
+ public static $consent = 'statistics';
+
+ public static function get_name() {
+ return 'Plausible';
+ }
+
+ public static function get_description() {
+ return __( 'Booking events are sent to Plausible whenever the page loads its script, for example from the Plausible plugin. To have Events Manager load it, enter your script URL and add its tag. Create a goal in Plausible for each event you want reported, such as purchase.', 'events-manager' );
+ }
+
+ public static function get_tag_name() {
+ return __( 'Plausible's script', 'events-manager' );
+ }
+
+ public static function get_fields() {
+ return array(
+ 'script_url' => array(
+ 'label' => __( 'Script URL', 'events-manager' ),
+ 'description' => __( 'The script address in your site's installation instructions in Plausible, such as https://plausible.io/js/pa-AbC123.js.', 'events-manager' ),
+ 'type' => 'url',
+ 'pattern' => '#^https?://S+.js(?S*)?$#i',
+ 'placeholder' => 'https://plausible.io/js/pa-AbC123.js',
+ ),
+ );
+ }
+
+ public static function get_tag() {
+ $src = static::get_field( 'script_url' );
+ return $src ? array( 'src' => $src ) : null;
+ }
+}
--- a/events-manager/classes/conversion-tracking/destinations/umami.php
+++ b/events-manager/classes/conversion-tracking/destinations/umami.php
@@ -0,0 +1,53 @@
+<?php
+namespace EMConversion_TrackingDestinations;
+
+use EMConversion_TrackingDestination;
+
+/**
+ * Umami, sent each booking event with its value and currency, and a purchase's revenue for Umami's revenue report.
+ */
+class Umami extends Destination {
+
+ public static $id = 'umami';
+
+ public static $group = 'analytics';
+
+ public static $consent = 'statistics';
+
+ public static function get_name() {
+ return 'Umami';
+ }
+
+ public static function get_description() {
+ return __( 'Booking events are sent to Umami whenever the page loads its script, for example from an Umami plugin. To have Events Manager load it, enter your website ID and add its tag.', 'events-manager' );
+ }
+
+ public static function get_tag_name() {
+ return __( 'Umami's script', 'events-manager' );
+ }
+
+ public static function get_fields() {
+ return array(
+ 'website_id' => array(
+ 'label' => __( 'Website ID', 'events-manager' ),
+ 'description' => __( 'Your website's ID in Umami, found in its tracking code as data-website-id.', 'events-manager' ),
+ 'pattern' => '/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/',
+ 'case' => 'lower',
+ 'placeholder' => '00000000-0000-0000-0000-000000000000',
+ ),
+ 'script_url' => array(
+ 'label' => __( 'Script URL', 'events-manager' ),
+ 'description' => __( 'Where your Umami script is loaded from. Leave it empty for Umami Cloud, or enter your own server's script URL.', 'events-manager' ),
+ 'type' => 'url',
+ 'pattern' => '#^https?://S+$#i',
+ 'default' => 'https://cloud.umami.is/script.js',
+ 'placeholder' => 'https://cloud.umami.is/script.js',
+ ),
+ );
+ }
+
+ public static function get_tag() {
+ $id = static::get_field( 'website_id' );
+ return $id ? array( 'id' => $id, 'src' => static::get_field( 'script_url' ) ) : null;
+ }
+}
--- a/events-manager/classes/em-archetypes-admin.php
+++ b/events-manager/classes/em-archetypes-admin.php
@@ -142,11 +142,11 @@
update_option( "dbem_cp_{$base}_slug", Archetypes::$event['slug'] );
}
$can_rename_labels = static::can_rename_labels();
- if ( $can_rename_labels && $_POST["dbem_cp_{$base}_label"] ) {
+ if ( $can_rename_labels && !empty($_POST["dbem_cp_{$base}_label"]) ) {
Archetypes::$event['label'] = em_options_save_kses_deep( $_POST["dbem_cp_{$base}_label"] );
update_option( "dbem_cp_{$base}_label", Archetypes::$event['label'] );
}
- if ( $can_rename_labels && $_POST["dbem_cp_{$base}_label_single"] ) {
+ if ( $can_rename_labels && !empty($_POST["dbem_cp_{$base}_label_single"]) ) {
Archetypes::$event['label_single'] = em_options_save_kses_deep( $_POST["dbem_cp_{$base}_label_single"] );
update_option( "dbem_cp_{$base}_label_single", Archetypes::$event['label_single'] );
}
--- a/events-manager/classes/em-archetypes.php
+++ b/events-manager/classes/em-archetypes.php
@@ -304,9 +304,10 @@
$event_page_ids = [
static::$event['cpt'] => get_option( $option ),
];
+ $options = static::get_options();
foreach ( static::$types as $type => $archetype ) {
- if ( !empty( static::$options[$type][$option] ) ) {
- $event_page_ids[ $type ] = static::$options[$type][$option];
+ if ( !empty( $options[$type][$option] ) ) {
+ $event_page_ids[ $type ] = $options[$type][$option];
}
}
return $event_page_ids;
--- a/events-manager/classes/em-bookings-table.php
+++ b/events-manager/classes/em-bookings-table.php
@@ -394,7 +394,7 @@
$result = $EM_Booking->$action();
if( $action === 'delete' && $result ) {
// just output an icon with feedback message, no updated row to show
- echo '<span class="em-icon em-icon-trash em-tooltip" aria-label="'. $EM_Booking->feedback_message .'"></span>';
+ echo '<span class="em-icon em-icon-trash em-tooltip" aria-label="'. esc_attr( $EM_Booking->feedback_message ) .'"></span>';
} else {
$EM_Bookings_Table = new EM_Bookings_Table();
}
--- a/events-manager/classes/em-conversion-tracking.php
+++ b/events-manager/classes/em-conversion-tracking.php
@@ -0,0 +1,513 @@
+<?php
+namespace EM;
+
+use EM_Booking, EM_Event, EM_Scripts_and_Styles;
+use EMConversion_TrackingDestination, EMConversion_TrackingDestinations;
+
+include_once __DIR__ . '/conversion-tracking/destination.php';
+include_once __DIR__ . '/conversion-tracking/destinations/gtm.php';
+include_once __DIR__ . '/conversion-tracking/destinations/ga4.php';
+include_once __DIR__ . '/conversion-tracking/destinations/meta-pixel.php';
+include_once __DIR__ . '/conversion-tracking/destinations/umami.php';
+include_once __DIR__ . '/conversion-tracking/destinations/plausible.php';
+include_once __DIR__ . '/conversion-tracking/destinations/matomo.php';
+include_once __DIR__ . '/conversion-tracking/destinations/fathom.php';
+
+/**
+ * Conversion tracking: tells the site's analytics and advertising tools about bookings as GA4 ecommerce events, always pushed to the dataLayer for Google Tag Manager, and sent to each destination turned on in the settings (see get_destinations()) through its adapter in includes/js/conversion-tracking.js.
+ *
+ * A booking reports a purchase, or a lead when it is free (see get_conversion()), in the booking_add reply when it is made. A booking still waiting for an online payment, such as one paid on Stripe's or PayPal's own page, reports nothing until the payment reaches it, and the visitor's browser then claims it once from any page of the site (see get_claim_reply()), so a return from paying or a reload counts it once.
+ *
+ * On for new installs and off for sites that had Events Manager before (option dbem_conversion_tracking), and nothing is printed or loaded while it is off. Each destination is sent events through the tag the page already has, those that need no more than that are on until turned off, and a tag is added to the site only when asked for the details given (option dbem_conversion_tracking_destinations). The Conversion Tracking add-on sends the same conversions from the server, on em_conversion_tracking_booking.
+ */
+class Conversion_Tracking {
+
+ /**
+ * AJAX action that hands a visitor's browser the conversions of the bookings it made that have since been paid, see get_claim_reply().
+ * @var string
+ */
+ public static $claim_action = 'em_conversion_claim';
+
+ /**
+ * Events whose booking card the page printed, by event ID, for the view_item event, printed with the page's footer.
+ * @var array
+ */
+ public static $card_items = array();
+
+ public static function init() {
+ add_action( 'init', array( static::class, 'hooks' ) );
+ add_filter( 'pre_update_option_dbem_conversion_tracking_destinations', array( static::class, 'sanitize_destinations' ) );
+ }
+
+ /**
+ * Attaches conversion tracking while it is on. Runs on init, before the booking actions are handled, see em_init_actions().
+ */
+ public static function hooks() {
+ if ( ! static::is_enabled() ) {
+ return;
+ }
+ add_action( 'wp_enqueue_scripts', array( static::class, 'enqueue_scripts' ) );
+ add_action( 'em_booking_form_header', array( static::class, 'output_form_item' ) );
+ add_filter( 'em_booking_checkout_get_card_vars', array( static::class, 'add_card_item' ), 10, 2 );
+ add_action( 'wp_footer', array( static::class, 'output_card_items' ) );
+ add_filter( 'em_action_booking_add', array( static::class, 'booking_add_reply' ), 110, 2 );
+ add_action( 'wp_ajax_' . static::$claim_action, array( static::class, 'claim' ) );
+ add_action( 'wp_ajax_nopriv_' . static::$claim_action, array( static::class, 'claim' ) );
+ }
+
+ /**
+ * Whether bookings are reported to the site's tags (option dbem_conversion_tracking).
+ * @return bool
+ */
+ public static function is_enabled() {
+ return (bool) apply_filters( 'em_conversion_tracking_is_enabled', (bool) em_get_option( 'dbem_conversion_tracking' ) );
+ }
+
+ /**
+ * Enqueues the tracking script on every front-end page, since a visitor can come back from paying to any page, with what it needs to know: where to claim paid bookings, the currency, and the destinations to send events to, with the tags to add.
+ */
+ public static function enqueue_scripts() {
+ $js_min = EM_Scripts_and_Styles::get_minified_extension_js();
+ wp_enqueue_script( 'em-conversion-tracking', plugins_url( 'includes/js/conversion-tracking' . $js_min . '.js', EM_FILE ), array(), EM_VERSION, true );
+ wp_localize_script( 'em-conversion-tracking', 'EM_Conversion_Tracking', static::get_script_vars() );
+ }
+
+ /**
+ * The tracking script's settings.
+ * @return array
+ */
+ public static function get_script_vars() {
+ $vars = array(
+ 'ajaxurl' => admin_url( 'admin-ajax.php' ),
+ 'action' => static::$claim_action,
+ 'currency' => em_get_option( 'dbem_bookings_currency', 'USD' ),
+ 'destinations' => array(),
+ );
+ foreach ( static::get_enabled_destinations() as $id => $class ) {
+ $vars['destinations'][ $id ] = $class::get_script_vars();
+ }
+ /**
+ * The tracking script's settings, as EM_Conversion_Tracking in the page.
+ * @param array $vars 'ajaxurl', 'action', 'currency' and 'destinations' (by id, what each enabled destination's adapter gets, see Destination::get_script_vars(); an add-on that sends a destination's events from the server adds 'server', the GA4 names of those events, so the browser leaves them out for that destination, or 'relay', with the 'url' of the site's own endpoint and the GA4 names of the 'events' the browser sends there for the add-on to send on, instead of to the destination's tag)
+ */
+ return apply_filters( 'em_conversion_tracking_get_script_vars', $vars );
+ }
+
+ /* ------------------------------------------------------------------------------------------------------------------
+ * Destinations
+ * ------------------------------------------------------------------------------------------------------------------ */
+
+ /**
+ * Where bookings can be reported, by id, each a class extending EMConversion_TrackingDestination whose $id is that id. The tracking script sends events to those enabled through its adapter of the same id.
+ * @return string[]
+ */
+ public static function get_destinations() {
+ /**
+ * Where bookings can be reported, by id. A destination's browser adapter goes in em_conversion_tracking_destinations in the tracking script, under the same id.
+ * @param string[] $destinations class names extending EMConversion_TrackingDestination, by id
+ */
+ $destinations = apply_filters( 'em_conversion_tracking_destinations', array(
+ 'gtm' => DestinationsGTM::class,
+ 'ga4' => DestinationsGA4::class,
+ 'meta' => DestinationsMeta_Pixel::class,
+ 'umami' => DestinationsUmami::class,
+ 'plausible' => DestinationsPlausible::class,
+ 'matomo' => DestinationsMatomo::class,
+ 'fathom' => DestinationsFathom::class,
+ ) );
+ return array_filter( is_array( $destinations ) ? $destinations : array(), function ( $class, $id ) {
+ return is_string( $class ) && is_subclass_of( $class, Destination::class ) && $class::$id === $id;
+ }, ARRAY_FILTER_USE_BOTH );
+ }
+
+ /**
+ * A destination's class by its id, or null when there is none.
+ * @param string $id
+ * @return string|null
+ */
+ public static function get_destination( $id ) {
+ $destinations = static::get_destinations();
+ return isset( $destinations[ $id ] ) ? $destinations[ $id ] : null;
+ }
+
+ /**
+ * The destinations bookings are reported to, by id.
+ * @return string[]
+ */
+ public static function get_enabled_destinations() {
+ return array_filter( static::get_destinations(), function ( $class ) {
+ return $class::is_enabled();
+ } );
+ }
+
+ /**
+ * The groups the settings list destinations under, by the group a destination names, in the order shown.
+ * @return string[]
+ */
+ public static function get_destination_groups() {
+ return apply_filters( 'em_conversion_tracking_destination_groups', array(
+ 'tags' => __( 'Tag managers', 'events-manager' ),
+ 'analytics' => __( 'Analytics', 'events-manager' ),
+ 'ads' => __( 'Advertising', 'events-manager' ),
+ ) );
+ }
+
+ /**
+ * Cleans dbem_conversion_tracking_destinations as it is saved, keeping each destination's own settings (see Destination::sanitize()).
+ * @param mixed $value
+ * @return array
+ */
+ public static function sanitize_destinations( $value ) {
+ $value = is_array( $value ) ? $value : array();
+ $clean = array();
+ foreach ( static::get_destinations() as $id => $class ) {
+ $raw = isset( $value[ $id ] ) && is_array( $value[ $id ] ) ? $value[ $id ] : array();
+ /**
+ * A destination's settings as saved, for add-ons that print fields in its row to keep their own.
+ * @param array $settings what the destination keeps
+ * @param array $raw what the settings form sent
+ * @param string $class the destination's class
+ */
+ $clean[ $id ] = apply_filters( 'em_conversion_tracking_sanitize_destination', $class::sanitize( $raw ), $raw, $class );
+ }
+ return $clean;
+ }
+
+ /**
+ * Prints the destinations in the Conversion Tracking settings, by group.
+ */
+ public static function output_settings() {
+ $destinations = static::get_destinations();
+ foreach ( static::get_destination_groups() as $group => $label ) {
+ $classes = array_filter( $destinations, function ( $class ) use ( $group ) {
+ return $class::$group === $group;
+ } );
+ if ( ! $classes ) {
+ c