PluginProbe
Timetics – Appointment Booking Calendar & Scheduling / 1.0.1
Timetics – Appointment Booking Calendar & Scheduling v1.0.1
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.1, at timetics.php

289 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.1
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 * Requirements Array
56 *
57 * @since 1.0.0
58 * @var array
59 */
60 private $requirements = array(
61 'php' => array(
62 'name' => 'PHP',
63 'minimum' => '7.3',
64 'exists' => true,
65 'met' => false,
66 'checked' => false,
67 'current' => false,
68 ),
69 'wp' => array(
70 'name' => 'WordPress',
71 'minimum' => '5.2',
72 'exists' => true,
73 'checked' => false,
74 'met' => false,
75 'current' => false,
76 ),
77 );
78
79 /**
80 * Singleton Instance
81 *
82 * @return Timetics
83 */
84 public static function get_instance()
85 {
86 if (null === self::$instance) {
87 self::$instance = new self();
88 }
89
90 return self::$instance;
91 }
92
93 /**
94 * Setup Plugin Requirements
95 *
96 * @since 1.0.0
97 */
98 private function __construct()
99 {
100 // Always load translation.
101 add_action('plugins_loaded', array($this, 'load_text_domain'));
102
103 // Initialize plugin functionalities or quit.
104 $this->requirements_met() ? $this->initialize_modules() : $this->quit();
105 }
106
107 /**
108 * Load Localization Files
109 *
110 * @since 1.0
111 * @return void
112 */
113 public function load_text_domain()
114 {
115 $locale = apply_filters('plugin_locale', get_user_locale(), 'timetics');
116
117 unload_textdomain('timetics');
118 load_textdomain('timetics', WP_LANG_DIR . '/timetics/timetics-' . $locale . '.mo');
119 load_plugin_textdomain('timetics', false, self::get_plugin_dir() . 'languages/');
120 }
121
122 /**
123 * Initialize Plugin Modules
124 *
125 * @since 1.0.0
126 * @return void
127 */
128 private function initialize_modules()
129 {
130 require_once dirname(__FILE__) . '/autoloader.php';
131 require_once dirname(__FILE__) . '/core/settings/settings.php';
132
133 require_once dirname(__FILE__) . '/utils/global-helper.php';
134
135 // Include the bootstrap file if not loaded.
136 if (!class_exists('Timetics\Bootstrap')) {
137 require_once self::get_plugin_dir() . 'bootstrap.php';
138 }
139
140 // Initialize the bootstraper if exists.
141 if (class_exists('Timetics\Bootstrap')) {
142
143 // Initialize all modules through plugins_loaded.
144 add_action('plugins_loaded', array($this, 'init'));
145
146 register_activation_hook(self::get_plugin_file(), array($this, 'activate'));
147 register_deactivation_hook(self::get_plugin_file(), array($this, 'deactivate'));
148 }
149 }
150
151 /**
152 * Check If All Requirements Are Fulfilled
153 *
154 * @return boolean
155 */
156 private function requirements_met()
157 {
158 $this->prepare_requirement_versions();
159
160 $passed = true;
161 $to_meet = wp_list_pluck($this->requirements, 'met');
162
163 foreach ($to_meet as $met) {
164 if (empty($met)) {
165 $passed = false;
166 continue;
167 }
168 }
169
170 return $passed;
171 }
172
173 /**
174 * Requirement Version Prepare
175 *
176 * @since 1.0.0
177 *
178 * @return void
179 */
180 private function prepare_requirement_versions()
181 {
182 foreach ($this->requirements as $dependency => $config) {
183 switch ($dependency) {
184 case 'php':
185 $version = phpversion();
186 break;
187 case 'wp':
188 $version = get_bloginfo('version');
189 break;
190 default:
191 $version = false;
192 }
193
194 if (!empty($version)) {
195 $this->requirements[$dependency]['current'] = $version;
196 $this->requirements[$dependency]['checked'] = true;
197 $this->requirements[$dependency]['met'] = version_compare($version, $config['minimum'], '>=');
198 }
199 }
200 }
201
202 /**
203 * Initialize everything
204 *
205 * @since 1.0.0
206 *
207 * @return void
208 */
209 public function init()
210 {
211 Timetics\Bootstrap::instantiate(self::get_plugin_file());
212 }
213
214 /**
215 * Called Only Once While Activation
216 *
217 * @return void
218 */
219 public function activate()
220 {
221 // Insert new role.
222 Timetics\Base\Role::instance()->init();
223
224 // Update default settings.
225 timetics_update_default_settings();
226 }
227
228 /**
229 * Called Only Once While Deactivation
230 *
231 * @return void
232 */
233 public function deactivate()
234 {
235 }
236
237 /**
238 * Quit Plugin Execution
239 *
240 * @return void
241 */
242 private function quit()
243 {
244 add_action('admin_head', array($this, 'show_plugin_requirements_not_met_notice'));
245 }
246
247 /**
248 * Show Error Notice For Missing Requirements
249 *
250 * @return void
251 */
252 public function show_plugin_requirements_not_met_notice()
253 {
254 printf('<div>Minimum requirements for Timetics are not met. Please update requirements to continue.</div>');
255 }
256
257 /**
258 * Plugin Current Production Version
259 *
260 * @return string
261 */
262 public static function get_version()
263 {
264 return '1.0.0';
265 }
266
267 /**
268 * Plugin Main File
269 *
270 * @return string
271 */
272 public static function get_plugin_file()
273 {
274 return __FILE__;
275 }
276
277 /**
278 * Plugin Base Directory Path
279 *
280 * @return string
281 */
282 public static function get_plugin_dir()
283 {
284 return trailingslashit(plugin_dir_path(self::get_plugin_file()));
285 }
286 }
287
288 Timetics::get_instance();
289