PluginProbe ʕ •ᴥ•ʔ
VikAppointments Services Booking Calendar / 1.2.18
VikAppointments Services Booking Calendar v1.2.18
1.2.21 1.2.20 trunk 1.2.17 1.2.18 1.2.19
vikappointments / libraries / lite / manager.php
vikappointments / libraries / lite Last commit date
helper.php 6 months ago manager.php 6 months ago
manager.php
214 lines
1 <?php
2 /**
3 * @package VikAppointments - Libraries
4 * @subpackage lite
5 * @author E4J s.r.l.
6 * @copyright Copyright (C) 2021 E4J s.r.l. All Rights Reserved.
7 * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
8 * @link https://vikwp.com
9 */
10
11 // No direct access
12 defined('ABSPATH') or die('No script kiddies please!');
13
14 /**
15 * Manager class used to setup the LITE version of the plugin.
16 *
17 * @since 1.2.3
18 */
19 abstract class VikAppointmentsLiteManager
20 {
21 /**
22 * Flag used to avoid initializing the setup more than once.
23 *
24 * @var boolean
25 */
26 private static $setup = false;
27
28 /**
29 * Accessor used to start the setup.
30 *
31 * @param mixed $helper The implementor instance or a static class.
32 *
33 * @return void
34 */
35 final public static function setup($helper = null)
36 {
37 if (!static::$setup && !static::guessPro())
38 {
39 if (!$helper)
40 {
41 // use the default implementor
42 VikAppointmentsLoader::import('lite.helper');
43 $helper = new VikAppointmentsLiteHelper();
44 }
45
46 // set up only once and in case of missing PRO version
47 static::$setup = static::doSetup($helper);
48 }
49 }
50
51 /**
52 * Helper method used to assume whether the PRO version is
53 * installed or not, because it is not enough to check whether
54 * a PRO license is registered. In example, we cannot automatically
55 * re-enable the LITE restrictions after a PRO license expires.
56 *
57 * @return boolean
58 */
59 public static function guessPro()
60 {
61 // immediately check whether we have a valid PRO license
62 if (VikAppointmentsLicense::isPro())
63 {
64 return true;
65 }
66
67 // Missing PRO license or expired... First make sure the
68 // license key was specified.
69 if (!VikAppointmentsLicense::getKey())
70 {
71 // missing license key, never allow usage of PRO features
72 return false;
73 }
74
75 // Check whether the PRO license was ever installed, which
76 // can be easily done by looking for the PayPal integration.
77 return VikAppointmentsLoader::import('payments.paypal');
78 }
79
80 /**
81 * Setup implementor.
82 *
83 * @param mixed $helper The implementor instance or a static class.
84 *
85 * @return boolean
86 */
87 protected static function doSetup($helper)
88 {
89 /**
90 * Filters which capabilities a role has.
91 *
92 * @since 2.0.0
93 *
94 * @param bool[] $capabilities Array of key/value pairs where keys represent a capability name and boolean values
95 * represent whether the role has that capability.
96 * @param string $cap Capability name.
97 * @param string $name Role name.
98 */
99 add_filter('role_has_cap', array($helper, 'restrictCapabilities'));
100
101 /**
102 * Dynamically filter a user's capabilities.
103 *
104 * @since 2.0.0
105 * @since 3.7.0 Added the `$user` parameter.
106 *
107 * @param bool[] $allcaps Array of key/value pairs where keys represent a capability name
108 * and boolean values represent whether the user has that capability.
109 * @param string[] $caps Required primitive capabilities for the requested capability.
110 * @param array $args Arguments that accompany the requested capability check.
111 * @param WP_User $user The user object.
112 */
113 add_filter('user_has_cap', array($helper, 'restrictCapabilities'));
114
115 /**
116 * Fires after WordPress has finished loading but before any headers are sent.
117 *
118 * Most of WP is loaded at this stage, and the user is authenticated. WP continues
119 * to load on the {@see 'init'} hook that follows (e.g. widgets), and many plugins instantiate
120 * themselves on it for all sorts of reasons (e.g. they need a user, a taxonomy, etc.).
121 *
122 * @since 1.5.0
123 */
124 add_action('init', array($helper, 'preventEditReservationAccess'), 5);
125
126 /**
127 * Fires before the controller of VikAppointments is dispatched.
128 * Useful to require libraries and to check user global permissions.
129 *
130 * @since 1.0
131 */
132 add_action('vikappointments_before_dispatch', array($helper, 'listenTosFieldSavingTask'));
133 add_action('vikappointments_before_dispatch', array($helper, 'displayBanners'));
134
135 /**
136 * Fires after the controller of VikAppointments is dispatched.
137 * Useful to include web resources (CSS and JS).
138 *
139 * If the controller terminates the process (exit or die),
140 * this hook won't be fired.
141 *
142 * @since 1.0
143 */
144 add_action('vikappointments_after_dispatch', array($helper, 'includeLiteAssets'));
145
146 /**
147 * Trigger event after completing the wizard setup.
148 * This is useful, in example, to rearrange the registered steps.
149 *
150 * @param boolean $status True on success, false otherwise.
151 * @param VAPWizard $wizard The wizard instance.
152 *
153 * @since 1.2.3
154 */
155 add_action('vikappointments_after_setup_wizard', array($helper, 'removeWizardSteps'), 15, 2);
156
157 /**
158 * Fires before the controller displays the view.
159 *
160 * @param JView $view The view instance.
161 *
162 * @since 1.0
163 */
164 add_action('vikappointments_before_display_customf', array($helper, 'disableCustomFieldsGroupFilter'));
165
166 /**
167 * Fires after the controller displays the view.
168 *
169 * @param JView $view The view instance.
170 *
171 * @since 1.0
172 */
173 add_action('vikappointments_after_display_customf', array($helper, 'displayTosFieldManagementForm'));
174
175 /**
176 * Fires after the controller displays the view.
177 *
178 * @param JView $view The view instance.
179 *
180 * @since 1.0
181 */
182 add_action('vikappointments_after_display_managereservation', array($helper, 'adjustToolbarFromReservationManagement'));
183
184 /**
185 * Fires after the controller displays the view.
186 *
187 * @param JView $view The view instance.
188 *
189 * @since 1.0
190 */
191 add_action('vikappointments_after_display_caldays', array($helper, 'disableEditFromOrderinfoModal'));
192 add_action('vikappointments_after_display_calendar', array($helper, 'disableEditFromOrderinfoModal'));
193 add_action('vikappointments_after_display_findreservation', array($helper, 'disableEditFromOrderinfoModal'));
194 add_action('vikappointments_after_display_vikappointments', array($helper, 'disableEditFromOrderinfoDashboardModal'));
195
196 /**
197 * Fires after the controller displays the view.
198 *
199 * @param JView $view The view instance.
200 *
201 * @since 1.0
202 */
203 add_action('vikappointments_after_display_editconfig', array($helper, 'removeMultilingualSettingFromConfiguration'));
204 add_action('vikappointments_after_display_editconfig', array($helper, 'removeConversionsSettingFromConfiguration'));
205 add_action('vikappointments_after_display_editconfig', array($helper, 'removeMailTextSettingFromConfiguration'));
206 add_action('vikappointments_after_display_editconfig', array($helper, 'removeShopCartSettingsFromConfiguration'));
207 add_action('vikappointments_after_display_editconfig', array($helper, 'removeShopWaitingListTabFromConfiguration'));
208 add_action('vikappointments_after_display_editconfig', array($helper, 'removeShopRecurrenceTabFromConfiguration'));
209 add_action('vikappointments_after_display_editconfig', array($helper, 'removeShopReviewsTabFromConfiguration'));
210 add_action('vikappointments_after_display_editconfig', array($helper, 'removeShopPackagesTabFromConfiguration'));
211 add_action('vikappointments_after_display_editconfig', array($helper, 'removeShopSubscriptionsTabFromConfiguration'));
212 }
213 }
214