PluginProbe
Booktics – Appointment Booking Calendar for Service Businesses / 1.0.15
Booktics – Appointment Booking Calendar for Service Businesses v1.0.15
1.0.29 1.0.28 1.0.27 1.0.26 1.0.25 1.0.24 1.0.23 1.0.22 1.0.21 1.0.20 1.0.19 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.2 1.0.3 All 31 releases
booktics / base / booktics.php

booktics.php in Booktics – Appointment Booking Calendar for Service Businesses 1.0.15, at base/booktics.php

259 lines 5.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Booktics Main Class
4 *
5 * @package Booktics/Booktics
6 */
7
8 namespace Booktics;
9
10 use Booktics\Container\Container;
11
12 /**
13 * Class Booktics
14 */
15 class Booktics {
16
17 /**
18 * Plugin version.
19 *
20 * @var string
21 */
22 public $version;
23
24 /**
25 * Plugin file.
26 *
27 * @var string
28 */
29 public $plugin_file;
30
31 /**
32 * Plugin directory.
33 *
34 * @var string
35 */
36 public $plugin_directory;
37
38 /**
39 * @var string
40 */
41 public $build_url;
42
43 /**
44 * Plugin base name.
45 *
46 * @var string
47 */
48 public $basename;
49
50 /**
51 * Plugin text directory path.
52 *
53 * @var string
54 */
55 public $text_domain_directory;
56
57 /**
58 * Plugin text directory path.
59 *
60 * @var string
61 */
62 public $template_directory;
63
64 /**
65 * Plugin assets directory path.
66 *
67 * @var string
68 */
69 public $assets_url;
70
71 /**
72 * Plugin url.
73 *
74 * @var string
75 */
76 public $plugin_url;
77
78 /**
79 * Container that holds all the services.
80 *
81 * @var Container
82 */
83 public $container;
84
85 /**
86 * Booktics Constructor.
87 */
88 public function __construct() {
89 $this->init();
90 add_action( 'init', array( $this, 'init_classes' ) );
91 }
92
93 /**
94 * Initialize the plugin.
95 *
96 * @return void
97 */
98 protected function init(): void {
99 $this->version = BOOKTICS_VERSION;
100 $this->plugin_file = BOOKTICS_FILE;
101 $this->plugin_directory = BOOKTICS_DIR;
102 $this->basename = plugin_basename( $this->plugin_file );
103 $this->text_domain_directory = $this->plugin_directory . '/languages';
104 $this->template_directory = $this->plugin_directory . '/templates';
105 $this->plugin_url = plugins_url( '', $this->plugin_file );
106 $this->assets_url = $this->plugin_url . '/assets';
107 $this->build_url = $this->plugin_url . '/build';
108 register_activation_hook(
109 $this->plugin_file, array(
110 $this,
111 'activate',
112 )
113 );
114 register_deactivation_hook(
115 $this->plugin_file, array(
116 $this,
117 'deactivate',
118 )
119 );
120 }
121
122 /**
123 * Init classes
124 *
125 * @return void
126 */
127 public function init_classes() {
128 if ( ! session_id() ) {
129 session_start();
130 }
131 self::register_custom_post_type();
132
133 ( new \Booktics\Base\Services\Post_Status_Service() )->register();
134
135 $service_provider = $this->get_container()->get( 'global' );
136
137 // Initilize Plugin Banner Notice.
138 Plugin_Notice::run();
139
140 self::version_check();
141 }
142
143 /**
144 * Get container
145 *
146 * @return Container
147 */
148 public function get_container() {
149 return booktics_container();
150 }
151
152 /**
153 * Initializes the Booktics class.
154 *
155 * Checks for an existing WeMeal instance
156 * and if it doesn't find one, creates it.
157 *
158 * @return Booktics
159 */
160 public static function instance(): Booktics {
161 static $instance = false;
162
163 if ( ! $instance ) {
164 $instance = new self();
165 }
166
167 return $instance;
168 }
169
170 /**
171 * Trigger plugin activation class
172 *
173 * @return void
174 */
175 public function activate() {
176 Activate::handle();
177 }
178
179 /**
180 * Trigger plugin deactivation
181 *
182 * @return void
183 */
184 public function deactivate() {
185 Deactivate::handle();
186 }
187
188 /**
189 * returns assets url
190 *
191 * @return string
192 */
193 public static function assets_url(): string {
194 return trailingslashit( plugins_url( '', BOOKTICS_FILE ) . '/assets' );
195 }
196
197 /**
198 * Check if the plugin version is up to date
199 *
200 * @return void
201 */
202 public static function version_check() {
203 $latest_version = BOOKTICS_VERSION;
204 if ( is_multisite() ) {
205 $sites = get_sites();
206
207 foreach ( $sites as $site ) {
208 switch_to_blog( $site->blog_id );
209
210 $installed_version = booktics_get_option( 'booktics_version' );
211 if ( $installed_version < $latest_version ) {
212 self::run_migration();
213 booktics_update_option( 'booktics_version', booktics()->version );
214 }
215
216 restore_current_blog();
217 }
218 } else {
219 $installed_version = booktics_get_option( 'booktics_version' );
220 if ( $installed_version < $latest_version ) {
221 self::run_migration();
222 booktics_update_option( 'booktics_version', booktics()->version );
223 }
224 }
225 }
226
227 /**
228 * Run migration
229 *
230 * @return void
231 */
232 public static function run_migration() {
233 Installer::create_tables();
234 }
235
236 /**
237 * Register post type
238 *
239 * @return void
240 */
241 public static function register_custom_post_type() {
242 register_post_type(
243 'booktics-service', array(
244 'labels' => array(
245 'name' => __( 'Services', 'booktics' ),
246 'singular_name' => __( 'Service', 'booktics' ),
247 ),
248 'public' => true,
249 'has_archive' => true,
250 'has_single' => true,
251 'rewrite' => true,
252 'supports' => array( 'title', 'editor', 'thumbnail' ),
253 'show_in_rest' => true,
254 'show_in_menu' => false,
255 )
256 );
257 }
258 }
259