-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbkap-wc.php
217 lines (181 loc) · 6.61 KB
/
bkap-wc.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
<?php
/**
* Plugin Name: Booking & Appointment Plugin for WooCommerce
* Plugin URI: https://www.tychesoftwares.com/products/woocommerce-booking-and-appointment-plugin/
* Description: This plugin lets you capture the Booking Date & Booking Time for each product thereby allowing your WooCommerce store to effectively function as a Booking system. It allows you to add different time slots for different days, set maximum bookings per time slot, set maximum bookings per day, set global & product specific holidays and much more.
* Version: 5.21.1
* Author: Tyche Softwares
* Author URI: https://www.tychesoftwares.com/
* Text Domain: woocommerce-booking
* Requires PHP: 5.6
* WC requires at least: 3.9
* WC tested up to: 7.7.0
*
* @package BKAP
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( ! class_exists( 'Woocommerce_Booking' ) ) {
/**
* Booking & Appointment Plugin Core Class
*
* @class woocommerce_booking
*/
class Woocommerce_Booking {
/**
* Default constructor
*
* @since 1.0
*/
public function __construct() {
/**
* Defining Constants.
*/
$this->bkap_define_constants();
/**
* Check required pugins.
*/
add_action( 'admin_init', array( $this, 'bkap_do_required_plugin_check' ) );
if ( ! self::bkap_is_required_plugin_active() ) {
return;
}
/**
* Including Plugin Files
*/
self::bkap_maybe_include_files();
/**
* Plugin Updater
*/
include dirname( __FILE__ ) . '/includes/plugin-updates/EDD_Plugin_Updater.php';
/**
* Initialize settings
*/
register_activation_hook( __FILE__, array( &$this, 'bkap_bookings_activate' ) );
/**
* Delete options and setting on deactivation of plugin.
*/
register_deactivation_hook( __FILE__, array( &$this, 'bkap_bookings_deactivate' ) );
}
/**
* Including plugin files.
*
* @since 1.7
*/
public static function bkap_include_files() {
require_once BKAP_BOOKINGS_INCLUDE_PATH . 'bkap-availability-search.php';
require_once BKAP_BOOKINGS_INCLUDE_PATH . 'class-bkap-webhooks.php';
require_once BKAP_BOOKINGS_INCLUDE_PATH . 'class-bkap-include-files.php';
require_once BKAP_BOOKINGS_INCLUDE_PATH . 'api/class-bkap-api-include-files.php'; // Include API files.
require_once BKAP_BOOKINGS_INCLUDE_PATH . 'class-bkap-wc-hpos.php';
}
/**
* Define constants to be used accross the plugin
*
* @since 4.6.0
*/
public static function bkap_define_constants() {
/**
* This is the URL our updater / license checker pings. This should be the URL of the site with EDD installed
* IMPORTANT: change the name of this constant to something unique to prevent conflicts with other plugins using this system
*/
define( 'EDD_SL_STORE_URL_BOOK', 'https://www.tychesoftwares.com/' );
/**
* The name of your product. This is the title of your product in EDD and should match the download title in EDD exactly
* IMPORTANT: change the name of this constant to something unique to prevent conflicts with other plugins using this system
*/
define( 'EDD_SL_ITEM_NAME_BOOK', 'Booking & Appointment Plugin for WooCommerce' );
define( 'BKAP_VERSION', '5.21.1' );
define( 'BKAP_CDN', 'https://static.tychesoftwares.com/woocommerce-booking' );
define( 'BKAP_DEV_MODE', false );
if ( ! defined( 'BKAP_FILE' ) ) {
define( 'BKAP_FILE', __FILE__ );
}
if ( ! defined( 'BKAP_PLUGIN_PATH' ) ) {
define( 'BKAP_PLUGIN_PATH', untrailingslashit( plugin_dir_path( __FILE__ ) ) );
}
if ( ! defined( 'BKAP_PLUGIN_URL' ) ) {
define( 'BKAP_PLUGIN_URL', untrailingslashit( plugins_url( '/', __FILE__ ) ) );
}
if ( ! defined( 'BKAP_REQUIRED_PLUGIN_ERROR_MESSAGE' ) ) {
define( 'BKAP_REQUIRED_PLUGIN_ERROR_MESSAGE', sprintf( __( 'WooCommerce not found. %s requires a minimum of WooCommerce v3.3.0.', 'woocommerce-booking' ), EDD_SL_ITEM_NAME_BOOK ) );
}
define( 'BKAP_BOOKINGS_INCLUDE_PATH', BKAP_PLUGIN_PATH . '/includes/' );
define( 'BKAP_BOOKINGS_TEMPLATE_PATH', BKAP_PLUGIN_PATH . '/templates/' );
define( 'BKAP_VENDORS_INCLUDES_PATH', BKAP_PLUGIN_PATH . '/includes/vendors/' );
define( 'BKAP_VENDORS_LIBRARIES_PATH', BKAP_PLUGIN_PATH . '/includes/libraries/' );
define( 'BKAP_VENDORS_TEMPLATE_PATH', BKAP_BOOKINGS_TEMPLATE_PATH . 'vendors-integration/' );
define( 'AJAX_URL', get_admin_url() . 'admin-ajax.php' );
}
/**
* This function creates all the tables necessary in database detects when the booking plugin is activated.
*/
public function bkap_bookings_activate() {
if ( ! self::bkap_is_required_plugin_active() ) {
deactivate_plugins( plugin_basename( __FILE__ ) );
wp_die( BKAP_REQUIRED_PLUGIN_ERROR_MESSAGE );
}
require_once plugin_dir_path( __FILE__ ) . 'includes/class-bkap-plugin-activate.php';
Bkap_Plugin_Activate::bkap_activate();
}
/**
* Delete orphaned records from database on deactivation.
*/
public function bkap_bookings_deactivate() {
delete_transient( 'bkap_timeslot_notice' );
}
/**
* Checks if WooCommerce is installed and active.
*
* @since 5.12.0
*/
public static function bkap_do_required_plugin_check() {
if ( ! self::bkap_is_required_plugin_active() ) {
if ( is_plugin_active( plugin_basename( __FILE__ ) ) ) {
deactivate_plugins( plugin_basename( __FILE__ ) );
add_action( 'admin_notices', array( 'Woocommerce_Booking', 'show_required_plugin_error_notice' ) );
if ( isset( $_GET['activate'] ) ) {
unset( $_GET['activate'] );
}
}
}
}
/**
* Checks if WooCommerce is installed and active.
*
* @since 5.12.0
*/
public static function bkap_is_required_plugin_active() {
// WooCommerce is required, so we do a check.
$woocommerce_path = 'woocommerce/woocommerce.php';
$active_plugins = (array) get_option( 'active_plugins', array() );
$active = false;
if ( is_multisite() ) {
$plugins = get_site_option( 'active_sitewide_plugins' );
if ( isset( $plugins[ $woocommerce_path ] ) ) {
$active = true;
}
}
return in_array( $woocommerce_path, $active_plugins ) || array_key_exists( $woocommerce_path, $active_plugins ) || $active;
}
/**
* Displays WooCommerce Required Notice.
*
* @since 5.12.0
*/
public static function show_required_plugin_error_notice() {
echo '<div class="error"><p><strong>' . BKAP_REQUIRED_PLUGIN_ERROR_MESSAGE . '</strong></p></div>';
}
/**
* Checks whether to inlcude BKAP core files.
*
* @since 5.12.0
*/
public static function bkap_maybe_include_files() {
if ( self::bkap_is_required_plugin_active() ) {
self::bkap_include_files();
}
}
}
$woocommerce_booking = new Woocommerce_Booking();
}