-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
315 lines (255 loc) · 8.79 KB
/
index.php
File metadata and controls
315 lines (255 loc) · 8.79 KB
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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
<?php
/**
* Plugin Name: WP Booking System - Square Add-on
* Plugin URI: https://www.wpbookingsystem.com/
* Description: Allow customers to pay with their credit cards through Square.
* Version: 1.1.0
* Author: Ghettifish, Nic Bovee
* Author URI: https://www.wpbookingsystem.com/
* Text Domain: wp-booking-system-square
* License: GPL2
*
*/
// Exit if accessed directly
if (!defined('ABSPATH')) {
exit;
}
/**
* Main plugin class
*
*/
class WP_Booking_System_Square
{
/**
* The current instance of the object
*
* @access private
* @var WP_Booking_System_Square
*
*/
private static $instance;
/**
* A list with the objects that handle submenu pages
*
* @access public
* @var array
*
*/
public $submenu_pages = array();
/**
* Constructor
*
*/
public function __construct()
{
// Check if main plugin is active
if (!in_array('wp-booking-system-premium/index.php', apply_filters('active_plugins', get_option('active_plugins')))) {
return false;
}
// Enable pricing Module in main plugin
if (!defined('WPBS_ENABLE_PRICING')) {
define('WPBS_ENABLE_PRICING', true);
}
// Defining constants
define('WPBS_SQUARE_VERSION', '1.1.0');
define('WPBS_SQUARE_MIN_WPBS_VERSION', '5.6.6');
define('WPBS_SQUARE_FILE', __FILE__);
define('WPBS_SQUARE_BASENAME', plugin_basename(__FILE__));
define('WPBS_SQUARE_PLUGIN_DIR', plugin_dir_path(__FILE__));
define('WPBS_SQUARE_PLUGIN_DIR_URL', plugin_dir_url(__FILE__));
$this->include_files();
define('WPBS_SQUARE_TRANSLATION_TEXTDOMAIN', 'wp-booking-system-square');
// Check if we have the required version of the main plugin.
add_action('plugins_loaded', array($this, 'requirement_check'), 10);
// Check if just updated
add_action('plugins_loaded', array($this, 'update_check'), 20);
// Load the textdomain and the translation folders
add_action('plugins_loaded', array($this, 'load_text_domain'), 30);
// Admin scripts
add_action('admin_enqueue_scripts', array($this, 'enqueue_admin_scripts'));
// Front-end scripts
add_action('wpbs_enqueue_front_end_scripts', array($this, 'enqueue_front_end_scripts'));
// Remove plugin query args from the URL
add_filter('removable_query_args', array($this, 'removable_query_args'));
register_activation_hook(__FILE__, array($this, 'set_cron_jobs'));
register_deactivation_hook(__FILE__, array($this, 'unset_cron_jobs'));
/**
* Plugin initialized
*
*/
do_action('wpbs_square_initialized');
}
/**
* Returns an instance of the plugin object
*
* @return WP_Booking_System_Square
*
*/
public static function instance()
{
if (!isset(self::$instance) && !(self::$instance instanceof WP_Booking_System)) {
self::$instance = new WP_Booking_System_Square;
}
return self::$instance;
}
/**
* Checks to see if the add-on is compatible with the main plugin
*
* @return void
*
*/
public function requirement_check()
{
if (version_compare(WPBS_SQUARE_MIN_WPBS_VERSION, WPBS_VERSION) > 0) {
// Add-on Installed
wpbs_admin_notices()->register_notice('square_minimum_version', '<p>' . __('The <strong>Square</strong> Add-on requires WP Booking System version ' . WPBS_SQUARE_MIN_WPBS_VERSION . ' or greater. Please <a href="' . admin_url('plugins.php') . '">update</a> to the latest version.', 'wp-booking-system-square') . '</p>', 'error');
wpbs_admin_notices()->display_notice('square_minimum_version');
}
}
/**
* Checks to see if the current version of the plugin matches the version
* saved in the database
*
* @return void
*
*/
public function update_check()
{
$db_version = get_option('wpbs_square_version', '');
$do_update = false;
// If current version number differs from saved version number
if ($db_version != WPBS_SQUARE_VERSION) {
$do_update = true;
// Update the version number in the db
update_option('wpbs_square_version', WPBS_SQUARE_VERSION);
// Add first activation time
if (get_option('wpbs_square_first_activation', '') == '') {
update_option('wpbs_square_first_activation', time());
}
}
if ($do_update) {
// Hook for fresh update
do_action('wpbs_square_update_check', $db_version);
// Trigger set cron jobs
$this->set_cron_jobs();
}
}
/**
* Loads plugin text domain
*
*/
public function load_text_domain()
{
$locale = apply_filters('plugin_locale', get_locale(), WPBS_SQUARE_TRANSLATION_TEXTDOMAIN);
// Search for Translation in /wp-content/languages/plugin/
if (file_exists(trailingslashit(WP_LANG_DIR) . 'plugins' . WPBS_SQUARE_TRANSLATION_TEXTDOMAIN . '-' . $locale . '.mo')) {
load_plugin_textdomain(WPBS_SQUARE_TRANSLATION_TEXTDOMAIN, false, trailingslashit(WP_LANG_DIR));
}
// Search for Translation in /wp-content/languages/
elseif (file_exists(trailingslashit(WP_LANG_DIR) . WPBS_SQUARE_TRANSLATION_TEXTDOMAIN . '-' . $locale . '.mo')) {
load_textdomain(WPBS_SQUARE_TRANSLATION_TEXTDOMAIN, trailingslashit(WP_LANG_DIR) . WPBS_SQUARE_TRANSLATION_TEXTDOMAIN . '-' . $locale . '.mo');
// Search for Translation in /wp-content/plugins/wp-booking-system-premium/languages/
} else {
load_plugin_textdomain(WPBS_SQUARE_TRANSLATION_TEXTDOMAIN, false, plugin_basename(dirname(__FILE__)) . '/languages');
}
}
/**
* Sets an action hook for modules to add custom schedules
*
*/
public function set_cron_jobs()
{
do_action('wpbs_square_set_cron_jobs');
}
/**
* Sets an action hook for modules to remove custom schedules
*
*/
public function unset_cron_jobs()
{
do_action('wpbs_square_unset_cron_jobs');
}
/**
* Include files
*
* @return void
*
*/
public function include_files()
{
/**
* Include all functions.php files from all plugin folders
*
*/
$this->_recursively_include_files(WPBS_SQUARE_PLUGIN_DIR . 'includes');
/**
* Helper hook to include files early
*
*/
do_action('wpbs_square_include_files');
}
/**
* Recursively includes all functions.php files from the given directory path
*
* @param string $dir_path
*
*/
protected function _recursively_include_files($dir_path)
{
$folders = array_filter(glob($dir_path . '/*'), 'is_dir');
foreach ($folders as $folder_path) {
if (file_exists($folder_path . '/functions.php')) {
include $folder_path . '/functions.php';
}
$this->_recursively_include_files($folder_path);
}
}
/**
* Enqueue the scripts and style for the admin area
*
*/
public function enqueue_admin_scripts($hook)
{
/**
* Hook to enqueue scripts immediately after the plugin's scripts
*
*/
do_action('wpbs_square_enqueue_admin_scripts');
}
/**
* Enqueue the scripts and style for the front-end part
*
*/
public function enqueue_front_end_scripts()
{
// Plugin styles from the front-end.
wp_register_style('wpbs-square-front-end-style', WPBS_SQUARE_PLUGIN_DIR_URL . 'assets/css/style-front-end.css', array(), WPBS_SQUARE_VERSION);
wp_enqueue_style('wpbs-square-front-end-style');
include_once WPBS_SQUARE_PLUGIN_DIR . 'includes/libs/vendor/square-api.php';
$api = WPBS_Square_API::keys();
unset($api["access_token"]);
wp_register_script('squareSDK', "https://" . ($api['environment'] === 'sandbox' ? 'sandbox.' : '') . 'web.squarecdn.com/v1/square.js', null, null, true);
wp_enqueue_script('squareSDK');
wp_enqueue_script("wpbs-square", WPBS_SQUARE_PLUGIN_DIR_URL . "/assets/js/square.js");
wp_localize_script("wpbs-square", "square", $api);
}
/**
* Removes the query variables from the URL upon page load
*
*/
public function removable_query_args($args = array())
{
$args[] = 'wpbs_square_message';
return $args;
}
}
/**
* Returns the WP Booking System instanced object
*
*/
function wp_booking_system_square()
{
return WP_Booking_System_Square::instance();
}
// Let's get the party started
wp_booking_system_square();