2017-03-26 05:46:43 +00:00
< ? php
// Exit if accessed directly
if ( ! defined ( 'ABSPATH' ) ) { exit ; }
2017-10-12 02:22:55 +00:00
/**
* Init Booking Activities settings
2019-03-01 14:02:54 +00:00
* @ version 1.7 . 0
2017-10-12 02:22:55 +00:00
*/
2017-03-26 05:46:43 +00:00
function bookacti_init_settings () {
/* General settings Section */
add_settings_section (
'bookacti_settings_section_general' ,
2019-03-01 14:02:54 +00:00
esc_html__ ( 'General settings' , BOOKACTI_PLUGIN_NAME ),
2017-03-26 05:46:43 +00:00
'bookacti_settings_section_general_callback' ,
'bookacti_general_settings'
);
add_settings_field (
'booking_method' ,
2019-03-01 14:02:54 +00:00
esc_html__ ( 'Booking method' , BOOKACTI_PLUGIN_NAME ),
2017-03-26 05:46:43 +00:00
'bookacti_settings_field_booking_method_callback' ,
'bookacti_general_settings' ,
'bookacti_settings_section_general'
);
2017-08-08 06:44:04 +00:00
add_settings_field (
'when_events_load' ,
2019-03-01 14:02:54 +00:00
esc_html__ ( 'When to load the events?' , BOOKACTI_PLUGIN_NAME ),
2017-08-08 06:44:04 +00:00
'bookacti_settings_field_when_events_load_callback' ,
'bookacti_general_settings' ,
'bookacti_settings_section_general'
);
2017-12-27 07:49:04 +00:00
add_settings_field (
'event_load_interval' ,
2019-03-01 14:02:54 +00:00
esc_html__ ( 'Load events every' , BOOKACTI_PLUGIN_NAME ),
2017-12-27 07:49:04 +00:00
'bookacti_settings_field_event_load_interval_callback' ,
'bookacti_general_settings' ,
'bookacti_settings_section_general'
);
2017-03-26 05:46:43 +00:00
add_settings_field (
'started_events_bookable' ,
2019-03-01 14:02:54 +00:00
esc_html__ ( 'Are started events bookable?' , BOOKACTI_PLUGIN_NAME ),
2017-03-26 05:46:43 +00:00
'bookacti_settings_field_started_events_bookable_callback' ,
'bookacti_general_settings' ,
'bookacti_settings_section_general'
);
2017-08-08 06:44:04 +00:00
2018-02-24 04:45:35 +00:00
add_settings_field (
'started_groups_bookable' ,
2019-03-01 14:02:54 +00:00
esc_html__ ( 'Are started groups of events bookable?' , BOOKACTI_PLUGIN_NAME ),
2018-02-24 04:45:35 +00:00
'bookacti_settings_field_started_groups_bookable_callback' ,
'bookacti_general_settings' ,
'bookacti_settings_section_general'
);
add_settings_field (
'availability_period_start' ,
/* translators: Followed by a field indicating a number of days before the event. E.g.: "Events will be bookable in 2 days from today". */
2019-03-01 14:02:54 +00:00
esc_html__ ( 'Events will be bookable in' , BOOKACTI_PLUGIN_NAME ),
2018-02-24 04:45:35 +00:00
'bookacti_settings_field_availability_period_start_callback' ,
'bookacti_general_settings' ,
'bookacti_settings_section_general'
);
add_settings_field (
'availability_period_end' ,
/* translators: Followed by a field indicating a number of days before the event. E.g.: "Events are bookable for up to 30 days from today". */
2019-03-01 14:02:54 +00:00
esc_html__ ( 'Events are bookable for up to' , BOOKACTI_PLUGIN_NAME ),
2018-02-24 04:45:35 +00:00
'bookacti_settings_field_availability_period_end_callback' ,
'bookacti_general_settings' ,
'bookacti_settings_section_general'
);
2017-08-08 06:44:04 +00:00
add_settings_field (
'default_booking_state' ,
2019-03-01 14:02:54 +00:00
esc_html__ ( 'Default booking state' , BOOKACTI_PLUGIN_NAME ),
2017-08-08 06:44:04 +00:00
'bookacti_settings_field_default_booking_state_callback' ,
'bookacti_general_settings' ,
'bookacti_settings_section_general'
);
add_settings_field (
2018-01-28 04:50:59 +00:00
'default_payment_status' ,
2019-03-01 14:02:54 +00:00
esc_html__ ( 'Default payment status' , BOOKACTI_PLUGIN_NAME ),
2018-01-28 04:50:59 +00:00
'bookacti_settings_field_default_payment_status_callback' ,
2017-08-08 06:44:04 +00:00
'bookacti_general_settings' ,
'bookacti_settings_section_general'
);
add_settings_field (
2018-01-28 04:50:59 +00:00
'timezone' ,
2019-03-01 14:02:54 +00:00
esc_html__ ( 'Calendars timezone' , BOOKACTI_PLUGIN_NAME ),
2018-01-28 04:50:59 +00:00
'bookacti_settings_field_timezone_callback' ,
2017-08-08 06:44:04 +00:00
'bookacti_general_settings' ,
'bookacti_settings_section_general'
);
2018-05-05 09:17:09 +00:00
add_settings_field (
'default_calendar_view_threshold' ,
2019-05-10 13:52:39 +00:00
esc_html__ ( 'Load the "Day" view if the calendar width is less than' , BOOKACTI_PLUGIN_NAME ),
2018-05-05 09:17:09 +00:00
'bookacti_settings_field_default_calendar_view_threshold_callback' ,
'bookacti_general_settings' ,
'bookacti_settings_section_general'
);
2018-11-29 15:34:52 +00:00
add_settings_field (
'delete_data_on_uninstall' ,
esc_html__ ( 'Delete data on uninstall' , BOOKACTI_PLUGIN_NAME ),
'bookacti_settings_field_delete_data_on_uninstall_callback' ,
'bookacti_general_settings' ,
'bookacti_settings_section_general'
);
2017-03-26 05:46:43 +00:00
/* Cancellation settings Section */
add_settings_section (
'bookacti_settings_section_cancellation' ,
2019-03-01 14:02:54 +00:00
esc_html__ ( 'Cancellation settings' , BOOKACTI_PLUGIN_NAME ),
2017-03-26 05:46:43 +00:00
'bookacti_settings_section_cancellation_callback' ,
'bookacti_cancellation_settings'
);
add_settings_field (
'allow_customers_to_cancel' ,
2019-03-01 14:02:54 +00:00
esc_html__ ( 'Allow customers to cancel their bookings' , BOOKACTI_PLUGIN_NAME ),
2017-03-26 05:46:43 +00:00
'bookacti_settings_field_activate_cancel_callback' ,
'bookacti_cancellation_settings' ,
'bookacti_settings_section_cancellation'
);
add_settings_field (
'allow_customers_to_reschedule' ,
__ ( 'Allow customers to reschedule their bookings' , BOOKACTI_PLUGIN_NAME ),
'bookacti_settings_field_activate_reschedule_callback' ,
'bookacti_cancellation_settings' ,
'bookacti_settings_section_cancellation'
);
add_settings_field (
2018-02-24 04:45:35 +00:00
'cancellation_min_delay_before_event' ,
/* translators: Followed by a field indicating a number of days before the event. E.g.: "Changes permitted up to 2 days before the event". */
2019-03-01 14:02:54 +00:00
esc_html__ ( 'Changes permitted up to' , BOOKACTI_PLUGIN_NAME ),
2017-03-26 05:46:43 +00:00
'bookacti_settings_field_cancellation_delay_callback' ,
'bookacti_cancellation_settings' ,
'bookacti_settings_section_cancellation'
);
add_settings_field (
2017-10-12 02:22:55 +00:00
'refund_actions_after_cancellation' ,
2019-03-01 14:02:54 +00:00
esc_html__ ( 'Possible actions customers can take to be refunded' , BOOKACTI_PLUGIN_NAME ),
2017-10-12 02:22:55 +00:00
'bookacti_settings_field_cancellation_refund_actions_callback' ,
'bookacti_cancellation_settings' ,
'bookacti_settings_section_cancellation'
);
2017-11-17 08:24:51 +00:00
/* Notifications settings Section - 1 - General settings */
2017-10-12 02:22:55 +00:00
add_settings_section (
2017-11-17 08:24:51 +00:00
'bookacti_settings_section_notifications_general' ,
2019-03-01 14:02:54 +00:00
esc_html__ ( 'Notifications' , BOOKACTI_PLUGIN_NAME ),
2017-11-17 08:24:51 +00:00
'bookacti_settings_section_notifications_general_callback' ,
2017-10-12 02:22:55 +00:00
'bookacti_notifications_settings'
);
2017-11-17 08:24:51 +00:00
add_settings_field (
'notifications_async' ,
2019-03-01 14:02:54 +00:00
esc_html__ ( 'Asynchronous notifications' , BOOKACTI_PLUGIN_NAME ),
2017-11-17 08:24:51 +00:00
'bookacti_settings_field_notifications_async_callback' ,
'bookacti_notifications_settings' ,
'bookacti_settings_section_notifications_general'
);
/* Notifications settings Section - 2 - Email settings */
add_settings_section (
'bookacti_settings_section_notifications_email' ,
2019-03-01 14:02:54 +00:00
esc_html__ ( 'Email notifications settings' , BOOKACTI_PLUGIN_NAME ),
2017-11-17 08:24:51 +00:00
'bookacti_settings_section_notifications_email_callback' ,
'bookacti_notifications_settings'
);
2017-10-12 02:22:55 +00:00
add_settings_field (
'notifications_from_name' ,
2019-03-01 14:02:54 +00:00
esc_html__ ( 'From name' , BOOKACTI_PLUGIN_NAME ),
2017-10-12 02:22:55 +00:00
'bookacti_settings_field_notifications_from_name_callback' ,
'bookacti_notifications_settings' ,
2017-11-17 08:24:51 +00:00
'bookacti_settings_section_notifications_email'
2017-10-12 02:22:55 +00:00
);
add_settings_field (
'notifications_from_email' ,
2019-03-01 14:02:54 +00:00
esc_html__ ( 'From email' , BOOKACTI_PLUGIN_NAME ),
2017-10-12 02:22:55 +00:00
'bookacti_settings_field_notifications_from_email_callback' ,
'bookacti_notifications_settings' ,
2017-11-17 08:24:51 +00:00
'bookacti_settings_section_notifications_email'
2017-10-12 02:22:55 +00:00
);
/* Messages settings Section */
add_settings_section (
'bookacti_settings_section_messages' ,
2019-03-01 14:02:54 +00:00
esc_html__ ( 'Messages' , BOOKACTI_PLUGIN_NAME ),
2017-10-12 02:22:55 +00:00
'bookacti_settings_section_messages_callback' ,
'bookacti_messages_settings'
2017-03-26 05:46:43 +00:00
);
2019-03-01 14:02:54 +00:00
/* Messages settings Section */
add_settings_section (
'bookacti_settings_section_system' ,
esc_html__ ( 'System' , BOOKACTI_PLUGIN_NAME ),
'bookacti_settings_section_system_callback' ,
'bookacti_system_settings'
);
2017-03-26 05:46:43 +00:00
do_action ( 'bookacti_add_settings' );
2017-11-17 08:24:51 +00:00
register_setting ( 'bookacti_general_settings' , 'bookacti_general_settings' );
register_setting ( 'bookacti_cancellation_settings' , 'bookacti_cancellation_settings' );
register_setting ( 'bookacti_notifications_settings' , 'bookacti_notifications_settings' );
register_setting ( 'bookacti_messages_settings' , 'bookacti_messages_settings' );
2019-03-01 14:02:54 +00:00
register_setting ( 'bookacti_system_settings' , 'bookacti_system_settings' );
2017-03-26 05:46:43 +00:00
}
2017-10-12 02:22:55 +00:00
add_action ( 'admin_init' , 'bookacti_init_settings' );
2017-03-26 05:46:43 +00:00
2018-01-28 04:50:59 +00:00
// SCREEN OPTIONS
/**
* Add screen options
*
* @ since 1.3 . 0
2018-05-05 09:17:09 +00:00
* @ version 1.5 . 0
2018-01-28 04:50:59 +00:00
*/
function bookacti_add_screen_options () {
add_action ( 'load-booking-activities_page_bookacti_bookings' , 'bookacti_display_bookings_screen_options' );
2018-05-05 09:17:09 +00:00
add_action ( 'load-booking-activities_page_bookacti_forms' , 'bookacti_display_forms_screen_options' );
2018-01-28 04:50:59 +00:00
}
add_action ( 'admin_menu' , 'bookacti_add_screen_options' , 20 );
2018-05-05 09:17:09 +00:00
2018-01-28 04:50:59 +00:00
/**
* Add booking page columns screen options
2018-05-05 09:17:09 +00:00
* @ since 1.3 . 0
2018-11-29 15:34:52 +00:00
* @ version 1.6 . 0
2018-01-28 04:50:59 +00:00
*/
function bookacti_add_booking_page_screen_option () {
2018-11-29 15:34:52 +00:00
$booking_list = new Bookings_List_Table ();
$booking_list -> process_bulk_action ();
2018-01-28 04:50:59 +00:00
}
add_action ( 'admin_head-booking-activities_page_bookacti_bookings' , 'bookacti_add_booking_page_screen_option' );
2018-05-05 09:17:09 +00:00
/**
* Add form page columns screen options
* @ since 1.5 . 0
*/
function bookacti_add_form_page_screen_option () {
if ( empty ( $_REQUEST [ 'action' ] ) || ! in_array ( $_REQUEST [ 'action' ], array ( 'edit' , 'new' ), true ) ) {
new Forms_List_Table ();
}
}
add_action ( 'admin_head-booking-activities_page_bookacti_forms' , 'bookacti_add_form_page_screen_option' );
2018-01-28 04:50:59 +00:00
/**
* Save screen options
2018-05-05 09:17:09 +00:00
* @ since 1.5 . 0 ( was bookacti_save_bookings_screen_options )
2018-01-28 04:50:59 +00:00
*/
2018-05-05 09:17:09 +00:00
function bookacti_save_screen_options ( $status , $option , $value ) {
if ( 'bookacti_bookings_per_page' == $option || 'bookacti_forms_per_page' == $option ) {
2018-01-28 04:50:59 +00:00
return $value ;
}
return $status ;
}
2018-05-05 09:17:09 +00:00
add_filter ( 'set-screen-option' , 'bookacti_save_screen_options' , 10 , 3 );
2018-01-28 04:50:59 +00:00
2017-10-12 02:22:55 +00:00
// NOTIFICATIONS
/**
* Create a settings page for each notification
*
2017-11-17 08:24:51 +00:00
* @ since 1.2 . 1 ( was bookacti_fill_notifications_settings_section in 1.2 . 1 )
* @ param string $notification_id
2017-10-12 02:22:55 +00:00
*/
2017-11-17 08:24:51 +00:00
function bookacti_fill_notification_settings_page ( $notification_id ) {
if ( ! $notification_id ) { return ; }
$notification_settings = bookacti_get_notification_settings ( $notification_id );
?>
< h2 >< ? php echo __ ( 'Notification' , BOOKACTI_PLUGIN_NAME ) . ' - ' . $notification_settings [ 'title' ]; ?> </h2>
< p >
< a href = '<?php echo esc_url( ' ? page = bookacti_settings & tab = notifications ' ); ?>' >
< ? php _e ( 'Go back to notifications settings' , BOOKACTI_PLUGIN_NAME ); ?>
</ a >
</ p >
< p >< ? php echo $notification_settings [ 'description' ]; ?> </p>
< ? php do_action ( 'bookacti_notification_settings_page_before' , $notification_settings , $notification_id ); ?>
2018-05-05 09:17:09 +00:00
< h3 >< ? php _e ( 'Global notifications settings' , BOOKACTI_PLUGIN_NAME ); ?> </h3>
2017-11-17 08:24:51 +00:00
< table class = 'form-table' id = 'bookacti-notification-global-settings' >
< tbody >
< tr >
< th scope = 'row' >< ? php _e ( 'Enable' , BOOKACTI_PLUGIN_NAME ); ?> </th>
< td >
2017-10-12 02:22:55 +00:00
< ? php
2017-11-17 08:24:51 +00:00
$args = array (
'type' => 'checkbox' ,
'name' => 'bookacti_notification[active]' ,
'id' => 'bookacti_notification_' . $notification_id . 'active' ,
'value' => $notification_settings [ 'active' ] ? $notification_settings [ 'active' ] : 0 ,
'tip' => __ ( 'Enable or disable this automatic notification.' , BOOKACTI_PLUGIN_NAME )
);
bookacti_display_field ( $args );
2017-10-12 02:22:55 +00:00
?>
2017-11-17 08:24:51 +00:00
</ td >
</ tr >
< ? php do_action ( 'bookacti_notification_settings_page_global' , $notification_settings , $notification_id ); ?>
</ tbody >
</ table >
< h3 >< ? php _e ( 'Email notifications settings' , BOOKACTI_PLUGIN_NAME ); ?> </h3>
< table class = 'form-table' id = 'bookacti-notification-email-settings' >
< tbody >
< ? php
do_action ( 'bookacti_notification_settings_page_email_before' , $notification_settings , $notification_id );
if ( substr ( $notification_id , 0 , 8 ) !== 'customer' ) { ?>
< tr >
< th scope = 'row' >< ? php _e ( 'Recipient(s)' , BOOKACTI_PLUGIN_NAME ); ?> </th>
< td >
2017-10-12 02:22:55 +00:00
< ? php
2017-11-17 08:24:51 +00:00
$args = array (
'type' => 'text' ,
'name' => 'bookacti_notification[email][to]' ,
'id' => 'bookacti_notification_' . $notification_id . '_email_to' ,
'value' => is_array ( $notification_settings [ 'email' ][ 'to' ] ) ? implode ( ',' , $notification_settings [ 'email' ][ 'to' ] ) : strval ( $notification_settings [ 'email' ][ 'to' ] ),
'tip' => __ ( 'Recipient(s) email address(es) (comma separated).' , BOOKACTI_PLUGIN_NAME )
);
bookacti_display_field ( $args );
2017-10-12 02:22:55 +00:00
?>
2017-11-17 08:24:51 +00:00
</ td >
</ tr >
< ? php } ?>
< tr >
< th scope = 'row' >< ? php _ex ( 'Subject' , 'email subject' , BOOKACTI_PLUGIN_NAME ); ?> </th>
< td >
< ? php
$args = array (
'type' => 'text' ,
'name' => 'bookacti_notification[email][subject]' ,
'id' => 'bookacti_notification_' . $notification_id . '_email_subject' ,
'value' => $notification_settings [ 'email' ][ 'subject' ] ? $notification_settings [ 'email' ][ 'subject' ] : '' ,
'tip' => __ ( 'The email subject.' , BOOKACTI_PLUGIN_NAME )
);
bookacti_display_field ( $args );
2017-10-12 02:22:55 +00:00
?>
2017-11-17 08:24:51 +00:00
</ td >
</ tr >
< tr >
< th scope = 'row' >
< ? php
_ex ( 'Email content' , 'email message' , BOOKACTI_PLUGIN_NAME );
$tags = bookacti_get_notifications_tags ( $notification_id );
if ( $tags ) {
?>
< div class = 'bookacti-notifications-tags-list' >
2017-12-27 07:49:04 +00:00
< p >< ? php _e ( 'Use these tags:' , BOOKACTI_PLUGIN_NAME ); ?> </p>
2017-11-17 08:24:51 +00:00
< ? php
foreach ( $tags as $tag => $tip ) {
?>
< div class = 'bookacti-notifications-tag' >
< code >< ? php echo $tag ; ?> </code>
< ? php bookacti_help_tip ( $tip ); ?>
</ div >
< ? php
2017-10-12 02:22:55 +00:00
}
2017-11-17 08:24:51 +00:00
// Notification Pack promo
$is_plugin_active = bookacti_is_plugin_active ( 'ba-notification-pack/ba-notification-pack.php' );
if ( ! $is_plugin_active ) {
2018-09-28 15:08:54 +00:00
$addon_link = '<a href="https://booking-activities.fr/en/downloads/notification-pack/?utm_source=plugin&utm_medium=plugin&utm_campaign=notification-pack&utm_content=settings-notification-list" target="_blank" >Notification Pack</a>' ;
2017-11-17 08:24:51 +00:00
/* translators: %1$s is the placeholder for Notification Pack add-on link */
$tip = sprintf ( esc_html__ ( 'You can set a specific message on events, activities, groups of events and group categories and use it in your notifications thanks to %1$s add-on.' , BOOKACTI_PLUGIN_NAME ), $addon_link );
?>
< div class = 'bookacti-notifications-tag' >
< code class = 'bookacti-notifications-tag-promo' > { specific_message } </ code >
< ? php bookacti_help_tip ( $tip ); ?>
</ div >
< ? php
}
?>
</ div >
< ? php
}
?>
</ th >
< td >
< ? php
$args = array (
'type' => 'editor' ,
'name' => 'bookacti_notification[email][message]' ,
'id' => 'bookacti_notification_' . $notification_id . '_email_message' ,
'value' => $notification_settings [ 'email' ][ 'message' ] ? $notification_settings [ 'email' ][ 'message' ] : ''
);
bookacti_display_field ( $args );
2017-10-12 02:22:55 +00:00
?>
2017-11-17 08:24:51 +00:00
</ td >
</ tr >
< ? php do_action ( 'bookacti_notification_settings_page_email_after' , $notification_settings , $notification_id ); ?>
</ tbody >
</ table >
< ? php
do_action ( 'bookacti_notification_settings_page_after' , $notification_settings , $notification_id );
2017-10-12 02:22:55 +00:00
}
2017-11-17 08:24:51 +00:00
add_action ( 'bookacti_notification_settings_page' , 'bookacti_fill_notification_settings_page' , 10 , 1 );
2017-10-12 02:22:55 +00:00
/**
* Update notifications data
*
* @ since 1.2 . 0
2017-11-17 08:24:51 +00:00
* @ version 1.2 . 1
2017-10-12 02:22:55 +00:00
*/
function bookacti_controller_update_notification () {
$option_page = sanitize_title_with_dashes ( $_POST [ 'option_page' ] );
// Check nonce and capabilities
$is_nonce_valid = check_ajax_referer ( $option_page , '_wpnonce' , false );
$is_allowed = current_user_can ( 'bookacti_manage_booking_activities_settings' );
if ( $is_nonce_valid && $is_allowed ) {
2017-11-17 08:24:51 +00:00
if ( ! $_POST [ 'bookacti_notification' ] || ! $_POST [ 'notification_id' ] ) {
wp_send_json ( array ( 'status' => 'failed' , 'error' => 'missing_data' ) );
}
2017-10-12 02:22:55 +00:00
2017-11-17 08:24:51 +00:00
// Sanitize values
$notification_settings = bookacti_sanitize_notification_settings ( $_POST [ 'bookacti_notification' ], $_POST [ 'notification_id' ] );
$updated = update_option ( $option_page , $notification_settings );
2017-10-12 02:22:55 +00:00
if ( $updated ) {
wp_send_json ( array ( 'status' => 'success' ) );
} else {
wp_send_json ( array ( 'status' => 'failed' , 'error' => 'not_updated' ) );
}
}
2017-11-17 08:24:51 +00:00
wp_send_json ( array ( 'status' => 'failed' , 'error' => 'not_allowed' ) );
2017-10-12 02:22:55 +00:00
}
add_action ( 'wp_ajax_bookactiUpdateNotification' , 'bookacti_controller_update_notification' );
2018-01-28 04:50:59 +00:00
2017-10-12 02:22:55 +00:00
// MESSAGES
/**
* Display messages fields
* @ since 1.2 . 0