-
Notifications
You must be signed in to change notification settings - Fork 1
/
TheBookingClass.php
197 lines (167 loc) · 6.14 KB
/
TheBookingClass.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
<?php
namespace TheBooking;
use TheBooking\Bus\Bus;
use TheBooking\Classes\Shortcode_Booking;
use TheBooking\Integrations\Elementor_Widget;
use VSHM_Framework\Abstracts\Single;
defined('ABSPATH') || exit;
/**
* Class TheBooking
*
* @package TheBooking
* @author VonStroheim
* @since 1.0.0
*/
final class TheBookingClass extends Single
{
/**
* @var Loader
*/
public $loader;
/**
* @var Settings
*/
public $settings;
/**
* @var Services
*/
public $services;
/**
* @var Customers
*/
public $customers;
/**
* @var Bus
*/
public $bus;
/**
* @var Reservations
*/
public $reservations;
/**
* @var Availability
*/
public $availability;
protected function __construct()
{
$this->loader = Loader::instance();
$this->settings = Settings::instance();
$this->bus = new Bus();
}
/**
* Loads the text domain on plugin load.
*
* @return bool
*/
protected static function _load_textdomain()
{
$rel_path = plugin_basename(TBKG_FILE__) . '/languages/';
return load_plugin_textdomain('thebooking', FALSE, $rel_path);
}
public function init()
{
Update::maybeUpdate();
$this->services = Services::instance();
$this->reservations = Reservations::instance();
$this->customers = Customers::instance();
$this->availability = Availability::instance();
/**
* Set scheduled hooks
*/
if (!wp_get_schedule('tbk_daily_cron')) {
wp_schedule_event(time(), 'daily', 'tbk_daily_cron');
}
if (!wp_get_schedule('tbk_hourly_cron')) {
wp_schedule_event(time(), 'hourly', 'tbk_hourly_cron');
}
/**
* Load textdomain
*/
self::_load_textdomain();
if (\VSHM_Framework\Tools::is_request('admin')) {
$this->loader->add_action('admin_menu', Admin::class, 'backend_menu', 9);
$this->loader->add_action('admin_enqueue_scripts', Admin::class, 'load_backend_resources');
$this->loader->add_filter('plugin_row_meta', NULL, '\TheBooking\plugin_row_meta', 10, 2);
/* Block editor support */
$this->loader->add_action('enqueue_block_editor_assets', Admin::class, 'load_block_editor_scripts');
Frontend\UI::load_actions();
$this->loader->add_filter('block_categories', Admin::class, 'load_block_editor_category', 10, 2);
} elseif (\VSHM_Framework\Tools::is_request('rest')) {
Routes\SaveSettingsRoute::register();
Routes\DeleteServiceRoute::register();
Routes\GetServicePropertyRoute::register();
Routes\SelectServiceRoute::register();
Routes\CreateServiceRoute::register();
Routes\UploadFileRoute::register();
Routes\SubmitBookingRoute::register();
Routes\DeleteReservationRoute::register();
Routes\CreateCustomerRoute::register();
Routes\EditCustomerRoute::register();
Routes\SaveAvailabilityRoute::register();
Routes\DeleteCustomerRoute::register();
Routes\CreateLocationRoute::register();
Routes\EditLocationRoute::register();
Routes\DeleteLocationRoute::register();
Routes\RedirectRoute::register();
Routes\SaveUserPrefsRoute::register();
Routes\ReservationStatusChangeRoute::register();
Routes\ReservationRescheduleRoute::register();
} elseif (\VSHM_Framework\Tools::is_request('frontend')) {
$this->loader->add_action('wp_enqueue_scripts', Frontend\UI::class, 'load_resources');
Frontend\UI::load_actions();
}
if (!\VSHM_Framework\Tools::is_request('cron')) {
add_shortcode(Shortcode_Booking::SHORTCODE, [
Shortcode_Booking::class,
'render',
]);
$this->loader->add_action('init', Admin::class, 'load_block_editor_blocks');
$this->loader->add_filter('wp_privacy_personal_data_exporters', NULL, 'TheBooking\personal_data_exporter_register');
$this->loader->add_filter('wp_privacy_personal_data_erasers', NULL, 'TheBooking\personal_data_eraser_register');
/* Elementor support */
if (did_action('elementor/loaded')) {
add_action('elementor/widgets/widgets_registered', static function () {
\Elementor\Plugin::instance()->widgets_manager->register_widget_type(new Elementor_Widget());
});
add_action('elementor/editor/before_enqueue_scripts', static function () {
Frontend\UI::load_resources();
wp_enqueue_script('tbkl-elementor-editor',
TBKG_URL__ . 'Integrations/elementor.js',
[],
filemtime(TBKG_DIR__ . DIRECTORY_SEPARATOR . 'Integrations' . DIRECTORY_SEPARATOR . 'elementor.js')
);
wp_enqueue_style('tbk-elementor-styles',
TBKG_URL__ . 'Integrations/elementor.css',
[],
filemtime(TBKG_DIR__
. DIRECTORY_SEPARATOR . 'Integrations'
. DIRECTORY_SEPARATOR . 'elementor.css')
);
});
}
}
if (\VSHM_Framework\Tools::is_request('cron')) {
$this->loader->add_action('tbk_daily_cron', NULL, '\TheBooking\daily_jobs');
$this->loader->add_action('tbk_hourly_cron', NULL, '\TheBooking\hourly_jobs');
}
Modules::load_modules();
Actions::load_actions();
do_action('tbk-init');
$this->loader->run();
do_action('tbk-loaded');
}
/**
* @return bool
*/
public static function isAdministrator()
{
return current_user_can(self::admin_cap());
}
/**
* @return mixed|void
*/
public static function admin_cap()
{
return apply_filters('tbk_admin_capability', 'tbk_can_admin');
}
}