PluginProbe
Timetics – Appointment Booking Calendar & Scheduling / 1.0.3
Timetics – Appointment Booking Calendar & Scheduling v1.0.3
1.0.61 1.0.60 1.0.59 1.0.58 1.0.57 1.0.56 trunk 1.0.0 1.0.1 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.15 1.0.16 1.0.17 1.0.18 1.0.19 1.0.2 1.0.20 1.0.21 1.0.22 1.0.23 1.0.24 All 62 releases
timetics / timetics.php

timetics.php in Timetics – Appointment Booking Calendar & Scheduling 1.0.3, at timetics.php

292 lines 7.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Plugin Name: Timetics
5 * Plugin URI: https://arraytics.com/timetics/
6 * Description: Schedule, Appointment and Seat Booking plugin.
7 * Version: 1.0.3
8 * Requires at least: 5.2
9 * Requires PHP: 7.3
10 * Author: Arraytics
11 * Author URI: https://arraytics.com/
12 * License: GPL v2 or later
13 * License URI: https://www.gnu.org/licenses/gpl-2.0.html
14 * Text Domain: timetics
15 * Domain Path: /languages
16
17 * Timetics is free software: you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License as published by
19 * the Free Software Foundation, either version 2 of the License, or
20 * any later version.
21
22 * Timetics Essential is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26
27 * You should have received a copy of the GNU General Public License
28 * along with Timetics. If not, see <http://www.gnu.org/licenses/>.
29 *
30 * @package Timetics
31 * @category Core
32 * @author Arraytics
33 * @version 1.0.0
34 */
35
36 // Exit if accessed directly.
37 defined('ABSPATH') || exit;
38
39 /**
40 * The Main Plugin Requirements Checker
41 *
42 * @since 1.0.0
43 */
44 final class Timetics
45 {
46
47 /**
48 * Static Property To Hold Singleton Instance
49 *
50 * @var Timetics The Timetics Requirement Checker Instance
51 */
52 private static $instance;
53
54 /**
55 * Plugin Current Production Version
56 *
57 * @return string
58 */
59 public static function get_version()
60 {
61 return '1.0.3';
62 }
63
64 /**
65 * Requirements Array
66 *
67 * @since 1.0.0
68 * @var array
69 */
70 private $requirements = array(
71 'php' => array(
72 'name' => 'PHP',
73 'minimum' => '7.3',
74 'exists' => true,
75 'met' => false,
76 'checked' => false,
77 'current' => false,
78 ),
79 'wp' => array(
80 'name' => 'WordPress',
81 'minimum' => '5.2',
82 'exists' => true,
83 'checked' => false,
84 'met' => false,
85 'current' => false,
86 ),
87 );
88
89 /**
90 * Singleton Instance
91 *
92 * @return Timetics
93 */
94 public static function get_instance()
95 {
96 if (null === self::$instance) {
97 self::$instance = new self();
98 }
99
100 return self::$instance;
101 }
102
103 /**
104 * Setup Plugin Requirements
105 *
106 * @since 1.0.0
107 */
108 private function __construct()
109 {
110 // Always load translation.
111 add_action('plugins_loaded', array($this, 'load_text_domain'));
112
113 // Initialize plugin functionalities or quit.
114 $this->requirements_met() ? $this->initialize_modules() : $this->quit();
115 }
116
117 /**
118 * Load Localization Files
119 *
120 * @since 1.0
121 * @return void
122 */
123 public function load_text_domain()
124 {
125 $locale = apply_filters('plugin_locale', get_user_locale(), 'timetics');
126
127 unload_textdomain('timetics');
128 load_textdomain('timetics', WP_LANG_DIR . '/timetics/timetics-' . $locale . '.mo');
129 load_plugin_textdomain('timetics', false, self::get_plugin_dir() . 'languages/');
130 }
131
132 /**
133 * Initialize Plugin Modules
134 *
135 * @since 1.0.0
136 * @return void
137 */
138 private function initialize_modules()
139 {
140 require_once dirname(__FILE__) . '/autoloader.php';
141 require_once dirname(__FILE__) . '/core/settings/settings.php';
142
143 require_once dirname(__FILE__) . '/utils/global-helper.php';
144
145 // Include the bootstrap file if not loaded.
146 if (!class_exists('Timetics\Bootstrap')) {
147 require_once self::get_plugin_dir() . 'bootstrap.php';
148 }
149
150 // Initialize the bootstraper if exists.
151 if (class_exists('Timetics\Bootstrap')) {
152
153 // Initialize all modules through plugins_loaded.
154 add_action('plugins_loaded', array($this, 'init'));
155
156 register_activation_hook(self::get_plugin_file(), array($this, 'activate'));
157 register_deactivation_hook(self::get_plugin_file(), array($this, 'deactivate'));
158 }
159 }
160
161 /**
162 * Check If All Requirements Are Fulfilled
163 *
164 * @return boolean
165 */
166 private function requirements_met()
167 {
168 $this->prepare_requirement_versions();
169
170 $passed = true;
171 $to_meet = wp_list_pluck($this->requirements, 'met');
172
173 foreach ($to_meet as $met) {
174 if (empty($met)) {
175 $passed = false;
176 continue;
177 }
178 }
179
180 return $passed;
181 }
182
183 /**
184 * Requirement Version Prepare
185 *
186 * @since 1.0.0
187 *
188 * @return void
189 */
190 private function prepare_requirement_versions()
191 {
192 foreach ($this->requirements as $dependency => $config) {
193 switch ($dependency) {
194 case 'php':
195 $version = phpversion();
196 break;
197 case 'wp':
198 $version = get_bloginfo('version');
199 break;
200 default:
201 $version = false;
202 }
203
204 if (!empty($version)) {
205 $this->requirements[$dependency]['current'] = $version;
206 $this->requirements[$dependency]['checked'] = true;
207 $this->requirements[$dependency]['met'] = version_compare($version, $config['minimum'], '>=');
208 }
209 }
210 }
211
212 /**
213 * Initialize everything
214 *
215 * @since 1.0.0
216 *
217 * @return void
218 */
219 public function init()
220 {
221 Timetics\Bootstrap::instantiate(self::get_plugin_file());
222 }
223
224 /**
225 * Called Only Once While Activation
226 *
227 * @return void
228 */
229 public function activate()
230 {
231 // Insert new role.
232 Timetics\Base\Role::instance()->init();
233
234 // Update default settings.
235 timetics_update_default_settings();
236
237 // Register cron
238 timetics_register_cron();
239 }
240
241 /**
242 * Called Only Once While Deactivation
243 *
244 * @return void
245 */
246 public function deactivate()
247 {
248 }
249
250 /**
251 * Quit Plugin Execution
252 *
253 * @return void
254 */
255 private function quit()
256 {
257 add_action('admin_head', array($this, 'show_plugin_requirements_not_met_notice'));
258 }
259
260 /**
261 * Show Error Notice For Missing Requirements
262 *
263 * @return void
264 */
265 public function show_plugin_requirements_not_met_notice()
266 {
267 printf('<div>Minimum requirements for Timetics are not met. Please update requirements to continue.</div>');
268 }
269
270 /**
271 * Plugin Main File
272 *
273 * @return string
274 */
275 public static function get_plugin_file()
276 {
277 return __FILE__;
278 }
279
280 /**
281 * Plugin Base Directory Path
282 *
283 * @return string
284 */
285 public static function get_plugin_dir()
286 {
287 return trailingslashit(plugin_dir_path(self::get_plugin_file()));
288 }
289 }
290
291 Timetics::get_instance();
292