PluginProbe
Booktics – Appointment Booking Calendar for Service Businesses / 1.0.19
Booktics – Appointment Booking Calendar for Service Businesses v1.0.19
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 1.0.4 1.0.5 1.0.6 1.0.7 All 27 releases
booktics / core / extensions / plugin-manager.php

plugin-manager.php in Booktics – Appointment Booking Calendar for Service Businesses 1.0.19, at core/extensions/plugin-manager.php

351 lines 14.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Booktics\Extensions;
4
5 /**
6 * Plugin manager
7 */
8 class Plugin_Manager {
9
10 /**
11 * Check if a plugin is installed.
12 *
13 * @param string $slug The slug of the plugin.
14 *
15 * @return bool True if installed, false otherwise.
16 */
17 public static function is_installed( string $slug ): bool {
18 if ( ! function_exists( 'get_plugins' ) ) {
19 require_once ABSPATH . 'wp-admin/includes/plugin.php';
20 }
21
22 $plugins = get_plugins();
23
24 if ( is_array( $plugins ) ) {
25 foreach ( $plugins as $plugin_path => $plugin ) {
26 if ( strpos( $plugin_path, $slug . '/' ) === 0 ) {
27 return true;
28 }
29 }
30 }
31
32 return false;
33 }
34
35 /**
36 * Check if a plugin is active.
37 *
38 * @param string $slug The slug of the plugin.
39 *
40 * @return bool True if activated, false otherwise.
41 */
42 public static function is_activated( string $slug ): bool {
43 if ( ! self::is_installed( $slug ) ) {
44 return false;
45 }
46
47 return is_plugin_active( self::get_plugin_path( $slug ) );
48 }
49
50 /**
51 * Install a plugin from the WordPress repository by slug.
52 *
53 * @param string $slug The slug of the plugin.
54 *
55 * @return bool True if installation succeeds, false otherwise.
56 */
57 public static function install_plugin( string $slug ): bool {
58 if ( self::is_installed( $slug ) ) {
59 return true; // Already installed
60 }
61
62 include_once ABSPATH . 'wp-admin/includes/file.php';
63 include_once ABSPATH . 'wp-admin/includes/misc.php';
64 include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
65
66 $skin = new \Automatic_Upgrader_Skin();
67 $upgrader = new \Plugin_Upgrader( $skin );
68 $download_link = null;
69 foreach ( self::extensions() as $extension ) {
70 if ( $extension['slug'] === $slug && ! empty( $extension['download_link'] ) ) {
71 $download_link = $extension['download_link'];
72 break;
73 }
74 }
75
76 if ( ! $download_link ) {
77 return false;
78 }
79
80 $result = $upgrader->install( $download_link );
81
82 return (bool) $result;
83 }
84
85 /**
86 * Activate a plugin by slug.
87 *
88 * @param string $slug The slug of the plugin.
89 *
90 * @return bool True if activated, false otherwise.
91 */
92 public static function activate_plugin( string $slug ): bool {
93 if ( ! self::is_installed( $slug ) ) {
94 return false; // Plugin isn't installed
95 }
96
97 $plugin_path = self::get_plugin_path( $slug );
98 $result = activate_plugin( $plugin_path );
99
100 if ( is_wp_error( $result ) ) {
101 return $result;
102 }
103
104 return true;
105 }
106
107 /**
108 * Deactivate a plugin by slug.
109 *
110 * @param string $slug The slug of the plugin.
111 *
112 * @return bool True if deactivated, false otherwise.
113 */
114 public static function deactivate_plugin( string $slug ) {
115 if ( ! self::is_activated( $slug ) ) {
116 return false; // Plugin isn't activated
117 }
118
119 $plugin_path = self::get_plugin_path( $slug );
120
121 deactivate_plugins( $plugin_path );
122
123 return true;
124 }
125
126 /**
127 * Get the plugin path by slug.
128 *
129 * @param string $slug The slug of the plugin.
130 *
131 * @return string The path to the plugin file.
132 */
133 private static function get_plugin_path( string $slug ) {
134 if ( ! function_exists( 'get_plugins' ) ) {
135 require_once ABSPATH . 'wp-admin/includes/plugin.php';
136 }
137
138 $plugins = get_plugins();
139
140 if ( is_array( $plugins ) ) {
141 foreach ( $plugins as $plugin_path => $plugin ) {
142 if ( strpos( $plugin_path, $slug . '/' ) === 0 ) {
143 return $plugin_path;
144 }
145 }
146 }
147
148 return false;
149 }
150
151 /**
152 * Check if the provided file is the main plugin file.
153 *
154 * @param string $file Path to the file.
155 *
156 * @return bool True if it is the main plugin file, false otherwise.
157 */
158 private static function is_main_plugin_file( string $file ): bool {
159
160 $plugin_data = get_file_data( $file, array( 'Name' => 'Plugin Name' ) );
161
162 return ! empty( $plugin_data['Name'] );
163 }
164
165 /**
166 * Get the plugin name by slug.
167 *
168 * @param string $slug Plugin slug (e.g., 'woocommerce).
169 *
170 * @return string|null Returns the plugin name if found, or null if not found.
171 */
172 public static function get_plugin_name_by_slug( string $slug ) {
173 if ( ! function_exists( 'get_plugins' ) ) {
174 require_once ABSPATH . 'wp-admin/includes/plugin.php';
175 }
176
177 $all_plugins = get_plugins();
178
179 foreach ( $all_plugins as $plugin_file => $plugin_data ) {
180 if ( strpos( $plugin_file, $slug ) !== false ) {
181 return $plugin_data['Name'];
182 }
183 }
184
185 return null;
186 }
187
188 /**
189 * List of all extensions
190 *
191 * @return array
192 */
193 public static function extensions(): array {
194 return array(
195 'booktics-stripe-addon' => array(
196 'name' => 'booktics-stripe-addon',
197 'slug' => 'booktics-stripe-addon',
198 'type' => 'addon',
199 'upgrade' => true,
200 'upgrade_link' => 'https://themewinter.com/purchase-history',
201 'status' => 'off',
202 'is_pro' => false,
203 'title' => __( 'Booktics Stripe Addon', 'booktics' ),
204 'description' => __( 'It allows you to use stripe payment.', 'booktics' ),
205 'icon' => Extension_Icon::get( 'booktics-stripe-addon' ),
206 'notice' => '',
207 'demo_link' => 'https://support.themewinter.com/docs/plugins/plugin-docs/integration/booktics-stripe-addon',
208 'settings_link' => '',
209 'doc_link' => 'https://docs.arraytics.com/docs/booktics/payment-type/how-to-configure-the-stripe-in-booktics/',
210 'download_link' => 'https://products.arraytics.com/booktics-addons/booktics-stripe-addon-1.0.0.zip',
211 ),
212 'booktics-google-calendar' => array(
213 'name' => 'booktics-google-calendar',
214 'slug' => 'booktics-google-calendar',
215 'type' => 'addon',
216 'upgrade' => true,
217 'upgrade_link' => 'https://themewinter.com/purchase-history',
218 'status' => 'off',
219 'is_pro' => false,
220 'title' => __( 'Booktics Google Calendar', 'booktics' ),
221 'description' => __( 'It allows you to use google calendar.', 'booktics' ),
222 'icon' => Extension_Icon::get( 'booktics-google-calendar' ),
223 'notice' => '',
224 'demo_link' => 'https://support.themewinter.com/docs/plugins/plugin-docs/integration/booktics-google-calendar',
225 'settings_link' => '',
226 'doc_link' => 'https://docs.arraytics.com/docs/booktics/integration/how-to-integrate-google-calendar-with-booktics/',
227 'download_link' => 'https://products.arraytics.com/booktics-addons/booktics-google-calendar-1.0.0.zip',
228 ),
229 'booktics-outlook-calendar' => array(
230 'name' => 'booktics-outlook-calendar',
231 'slug' => 'booktics-outlook-calendar',
232 'type' => 'addon',
233 'upgrade' => true,
234 'upgrade_link' => 'https://themewinter.com/purchase-history',
235 'status' => 'off',
236 'is_pro' => false,
237 'title' => __( 'Booktics Outlook Calendar', 'booktics' ),
238 'description' => __( 'It allows you to use outlook calendar.', 'booktics' ),
239 'icon' => Extension_Icon::get( 'booktics-outlook-calendar' ),
240 'notice' => '',
241 'demo_link' => 'https://support.themewinter.com/docs/plugins/plugin-docs/integration/booktics-outlook-calendar-addon',
242 'settings_link' => '',
243 'doc_link' => 'https://docs.arraytics.com/docs/booktics/integration/how-to-integrate-outlook-calendar-with-booktics/',
244 'download_link' => 'https://products.arraytics.com/booktics-addons/booktics-outlook-calendar-addon-1.0.0.zip',
245 ),
246 'booktics-fluentcrm-addon' => array(
247 'name' => 'booktics-fluentcrm-addon',
248 'slug' => 'booktics-fluentcrm-addon',
249 'type' => 'addon',
250 'upgrade' => true,
251 'upgrade_link' => 'https://themewinter.com/purchase-history',
252 'status' => 'off',
253 'is_pro' => false,
254 'title' => __( 'Booktics FluentCRM Addon', 'booktics' ),
255 'description' => __( 'It allows you to use FluentCRM.', 'booktics' ),
256 'icon' => Extension_Icon::get( 'booktics-fluentcrm-addon' ),
257 'notice' => '',
258 'demo_link' => 'https://support.themewinter.com/docs/plugins/plugin-docs/integration/booktics-fluentcrm-addon',
259 'settings_link' => '',
260 'doc_link' => 'https://docs.arraytics.com/docs/booktics/',
261 'download_link' => 'https://products.arraytics.com/booktics-addons/booktics-fluentcrm-addon-1.0.0.zip',
262 ),
263 'booktics-paypal-addon' => array(
264 'name' => 'booktics-paypal-addon',
265 'slug' => 'booktics-paypal-addon',
266 'type' => 'addon',
267 'upgrade' => true,
268 'upgrade_link' => 'https://themewinter.com/purchase-history',
269 'status' => 'off',
270 'is_pro' => false,
271 'title' => __( 'Booktics PayPal Addon', 'booktics' ),
272 'description' => __( 'It allows you to use PayPal.', 'booktics' ),
273 'icon' => Extension_Icon::get( 'booktics-paypal-addon' ),
274 'notice' => '',
275 'demo_link' => 'https://support.themewinter.com/docs/plugins/plugin-docs/integration/booktics-paypal-addon',
276 'settings_link' => '',
277 'doc_link' => 'https://docs.arraytics.com/docs/booktics/payment-type/how-to-configure-the-paypal-in-booktics-pro/',
278 'download_link' => 'https://products.arraytics.com/booktics-addons/booktics-paypal-addon-1.0.0.zip',
279 ),
280 'eventin' => array(
281 'name' => 'eventin',
282 'slug' => 'wp-event-solution',
283 'type' => 'plugin',
284 'upgrade' => false,
285 'upgrade_link' => '',
286 'status' => 'off',
287 'is_pro' => false,
288 'title' => __( 'Eventin', 'booktics' ),
289 'description' => __( 'Best Free WordPress Event Calendar Plugin to manage booking, registration, RSVPs, schedule recurring events and sell event tickets with WooCommerce.', 'booktics' ),
290 'icon' => Extension_Icon::get( 'eventin' ),
291 'notice' => '',
292 'demo_link' => 'https://product.themewinter.com/eventin',
293 'settings_link' => '',
294 'doc_link' => 'https://support.themewinter.com/docs/plugins/docs/eventin/',
295 'download_link' => 'https://downloads.wordpress.org/plugin/wp-event-solution.latest-stable.zip',
296 ),
297 'wp-cafe' => array(
298 'name' => 'wp-cafe',
299 'slug' => 'wp-cafe',
300 'type' => 'plugin',
301 'upgrade' => false,
302 'upgrade_link' => '',
303 'status' => 'off',
304 'is_pro' => false,
305 'title' => __( 'WPCafe', 'booktics' ),
306 'description' => __( 'WPCafe - A restaurant plugin to increase sales with an Online Ordering System, Delivery, Pickup, Food Menu, Reservations, and Table Management.', 'booktics' ),
307 'icon' => Extension_Icon::get( 'wpcafe' ),
308 'notice' => '',
309 'demo_link' => 'https://product.themewinter.com/wpcafe',
310 'settings_link' => '',
311 'doc_link' => 'https://support.themewinter.com/docs/plugins/docs/wp-cafe/',
312 'download_link' => 'https://downloads.wordpress.org/plugin/wp-cafe.latest-stable.zip',
313 ),
314 'timetics' => array(
315 'name' => 'timetics',
316 'slug' => 'timetics',
317 'type' => 'plugin',
318 'upgrade' => false,
319 'upgrade_link' => '',
320 'status' => 'off',
321 'is_pro' => false,
322 'title' => __( 'WP Timetics', 'booktics' ),
323 'description' => __( 'Appointment Booking and Scheduling Calendar Plugin - WP Timetics', 'booktics' ),
324 'icon' => Extension_Icon::get( 'timetics' ),
325 'notice' => '',
326 'demo_link' => 'https://arraytics.com/timetics',
327 'settings_link' => '',
328 'doc_link' => 'https://docs.arraytics.com/docs/timetics/getting-started/',
329 'download_link' => 'https://downloads.wordpress.org/plugin/timetics.latest-stable.zip',
330 ),
331 'poptics' => array(
332 'name' => 'poptics',
333 'slug' => 'poptics',
334 'type' => 'plugin',
335 'upgrade' => false,
336 'upgrade_link' => '',
337 'status' => 'off',
338 'is_pro' => false,
339 'title' => __( 'Poptics', 'booktics' ),
340 'description' => __( 'Discover the ultimate popup mix with Poptics Popup Builder to boost your lead generation and sales conversions.', 'booktics' ),
341 'icon' => Extension_Icon::get( 'poptics' ),
342 'notice' => '',
343 'demo_link' => 'https://demo.aethonic.com/popticsadmin/',
344 'settings_link' => '',
345 'doc_link' => 'https://docs.aethonic.com/docs/getting-started/intro/',
346 'download_link' => 'https://downloads.wordpress.org/plugin/poptics.latest-stable.zip',
347 ),
348 );
349 }
350 }
351