PluginProbe
Booking Calendar / 10.10.2
Booking Calendar v10.10.2
11.8.2 11.8.1 11.8 11.7 11.6.1 11.6 11.5 11.4.3 11.4.2 11.4.1 11.4 11.3 11.2.1 11.2 11.1 11.0 10.15.7 10.15.6 10.1.3 10.10 10.10.1 10.10.2 10.11 10.11.2 10.11.3 All 202 releases
booking / core / any / activation.php

activation.php in Booking Calendar 10.10.2, at core/any/activation.php

313 lines 10.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * @version 1.0
4 * @package Booking Calendar
5 * @category Installation
6 * @author wpdevelop
7 *
8 * @web-site https://wpbookingcalendar.com/
9 * @email info@wpbookingcalendar.com
10 *
11 * @modified 2015-04-09, 2016-03-17
12 */
13
14 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
15
16
17 /**
18 * Activation | Deactivation Class
19 */
20 abstract class WPBC_Install {
21
22 /**
23 * Init option
24 *
25 * @var array
26 */
27 private $init_option;
28
29 /**
30 * Constructor
31 */
32 public function __construct() {
33
34 $default_init_option_names = array(
35 'option-version_num' => 'booking_version_num',
36 'option-is_delete_if_deactive' => 'booking_is_delete_if_deactive',
37 'option-activation_process' => 'booking_activation_process',
38 'transient-wpbc_activation_redirect' => '_booking_activation_redirect',
39 'message-delete_data' => '<strong>Warning!</strong> All plugin data will be deleted when plugin had deactivated.<br />' . sprintf( 'If you want to save your plugin data, please uncheck the %s"Delete plugin data"%s at the', '<strong>', '</strong>' ),
40 'link_settings' => '<a href="">Settings</a>',
41 'link_whats_new' => '<a href="">Whats New</a>',
42 );
43
44 $init_option = $this->get_init_option_names();
45
46 $this->init_option = wp_parse_args( $init_option, $default_init_option_names );
47
48 // WordPress > Plugins > "Activate" link.
49 register_activation_hook( WPBC_FILE, array( $this, 'wpbc_activate_initial' ) );
50
51 // WordPress > Plugins > "Deactivate" link.
52 register_deactivation_hook( WPBC_FILE, array( $this, 'wpbc_deactivate' ) );
53
54 // Upgrade during bulk upgrade of plugins.
55 add_filter( 'upgrader_post_install', array( $this, 'wpbc_install_in_bulk_upgrade' ), 10, 2 );
56
57 // Settings link at the plugin page.
58 add_filter( 'plugin_action_links', array( $this, 'plugin_links' ), 10, 2 );
59 // Warning message in plugin info.
60 add_filter( 'plugin_row_meta', array( $this, 'plugin_row_meta' ), 10, 4 );
61
62 $this->check_if_need_to_update(); // Check upgrade, if was no activation process
63 }
64
65
66 /**
67 * Must be overloaded in child CLASS
68 *
69 * * Important! for correct loading of trasnaltions later, we must do not use here loacale of plugin. So here will be untranslated strings!!!
70 *
71 * Exmaple:
72 * return array(
73 'option-version_num' => 'booking_version_num'
74 , 'option-is_delete_if_deactive' => 'booking_is_delete_if_deactive'
75 , 'option-activation_process' => 'booking_activation_process'
76 , 'transient-wpbc_activation_redirect' => '_booking_activation_redirect'
77 , 'message-delete_data' => '<strong>Warning !!!</strong> ' . 'All plugin data will be deleted when plugin had deactivated.' . '<br />'
78 . sprintf( 'If you want to save your plugin data, please uncheck the %s"Delete plugin data"%s at the settings page.', '<strong>', '</strong>')
79 , 'link_settings' => '<a href="">Settings</a>'
80 , 'link_whats_new' => '<a href="">Whats New</a>'
81 );
82 */
83 abstract function get_init_option_names();
84
85
86 /**
87 * Must be overloaded in child CLASS
88 * Exmaple:
89 *
90 return false
91 */
92 abstract function is_update_from_lower_to_high_version();
93
94
95 // -----------------------------------------------------------------------------------------------------------------
96 // <editor-fold defaultstate="collapsed" desc=" Update info of plugin at the plugins section ">
97
98 /** Update info of plugin at the plugins section */
99 function plugin_row_meta( $plugin_meta, $plugin_file, $plugin_data, $context ) {
100
101 $this_plugin = plugin_basename( WPBC_FILE );
102
103 if ($plugin_file == $this_plugin ) {
104
105 $is_delete_if_deactive = get_bk_option( $this->init_option['option-is_delete_if_deactive'] ); // check
106
107 if ($is_delete_if_deactive == 'On') { ?>
108 <div class="plugin-update-tr">
109 <div class="update-message notice inline notice-warning notice-altNO" style="font-size: 1em;line-height: 2em;margin:0 5px 10px;border-left: 3px solid #dd7000;"><?php
110 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
111 echo $this->init_option['message-delete_data']; ?></div>
112 </div>
113 <?php
114 }
115
116 /*
117 [$plugin_meta] => Array
118 (
119 [0] => Version 2.8.35
120 [1] => By wpdevelop
121 [2] => Visit plugin site
122 )
123
124 [$plugin_file] => booking/WPBC.php
125 [$plugin_data] => Array
126 (
127 [Name] => Booking Calendar
128 [PluginURI] => https://wpbookingcalendar.com/demo/
129 [Version] => 2.8.35
130 [Description] => Online booking and availability checking service for your site.
131 [Author] => wpdevelop
132 [AuthorURI] => https://wpbookingcalendar.com/
133 [TextDomain] =>
134 [DomainPath] =>
135 [Network] =>
136 [Title] => Booking Calendar
137 [AuthorName] => wpdevelop
138 )
139
140 [$context] => all
141 /**/
142
143 // Echo plugin description here
144 return $plugin_meta;
145
146 } else
147 return $plugin_meta;
148 }
149
150
151 // Adds Settings link to plugins settings
152 function plugin_links($links, $file) {
153
154 $this_plugin = plugin_basename( WPBC_FILE );
155
156 if ( $file == $this_plugin ) {
157
158 array_unshift( $links, $this->init_option['link_settings'] );
159
160 //array_unshift( $links, $this->init_option['link_whats_new'] );
161 array_unshift( $links, $this->init_option['link_faq'] );
162
163
164 $links = array_merge( $links, array(
165 '<a class="wpbc_plugins_links__start_tour" title="' . esc_attr( sprintf( __('We\'ll guide you through the steps to set up WP Booking Calendar on your site.','booking'), '<strong>WP Booking Calendar</strong>' ) ) . '" href="'
166 . esc_url( wpbc_get_settings_url() . '&wpbc_setup_wizard=reset&_wpnonce=' . wp_create_nonce( 'wpbc_settings_url_nonce' ) )
167 //. esc_url( admin_url( add_query_arg( array( 'page' => 'wpbc-about' ), 'index.php' ) ) )
168 . '">' . esc_attr__( 'Start Setup Wizard', 'booking' ) . '</a>'
169 )
170 );
171
172
173 if ( ! class_exists( 'wpdev_bk_personal' ) ) {
174 array_unshift( $links, $this->init_option['link_up'] );
175 } else {
176 if ( ! class_exists( 'wpdev_bk_multiuser' ) ) {
177 array_unshift( $links, $this->init_option['link_upgrade'] );
178 }
179 }
180
181 }
182 return $links;
183 }
184
185 // </editor-fold>
186
187
188 // -----------------------------------------------------------------------------------------------------------------
189
190 /**
191 * Check about ability to upgrade, if was no activation process
192 *
193 * @return void
194 */
195 private function check_if_need_to_update() {
196
197 if ( is_admin() ) {
198
199 $wpbc_version_num = get_option( $this->init_option['option-version_num'] );
200
201 if ( false === $wpbc_version_num ) {
202 $wpbc_version_num = '0';
203 }
204
205 $is_make_activation = false;
206
207 if ( version_compare( WP_BK_VERSION_NUM, $wpbc_version_num ) > 0 ) {
208
209 $is_make_activation = true;
210
211 } else {
212
213 // Check if we was update from free to paid or from lower to higher versions, and do not make normal activation. In this case we need to make update.
214 $is_make_activation = $this->is_update_from_lower_to_high_version();
215
216 }
217
218 // Add hook for initial activation.
219 if ( $is_make_activation ) {
220 add_action( 'plugins_loaded', array( $this, 'wpbc_activate_initial' ), 1030 );
221 }
222 }
223 }
224
225
226 /**
227 * Upgrade during bulk upgrade of plugins
228 *
229 * @param type $return_val
230 * @param type $hook_extra
231 *
232 * @return type
233 */
234 public function wpbc_install_in_bulk_upgrade( $return_val, $hook_extra ) {
235
236 if ( is_wp_error( $return_val ) ) {
237 return $return_val;
238 }
239
240 if ( isset( $hook_extra ) ) {
241 if ( isset( $hook_extra['plugin'] ) ) {
242 $file_name = basename( WPBC_FILE );
243 $pos = strpos( $hook_extra['plugin'], trim( $file_name ) );
244 if ( false !== $pos ) {
245 $this->wpbc_activate();
246 }
247 }
248 }
249
250 return $return_val;
251 }
252
253
254 /**
255 * User clicked on "Activate" link at Plugins Menu.
256 *
257 * @return type
258 */
259 public function wpbc_activate_initial() {
260
261 // Activate the plugin.
262 $this->wpbc_activate();
263
264 // Bail if this demo or activating from network, or bulk.
265 if ( is_network_admin() || isset( $_GET['activate-multi'] ) || wpbc_is_this_demo() ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
266 return;
267 }
268
269 // Add the transient to redirect - Showing Welcome screen.
270 set_transient( $this->init_option['transient-wpbc_activation_redirect'], true, 30 );
271 }
272
273 // -----------------------------------------------------------------------------------------------------------------
274
275 /**
276 * Run Activate
277 */
278 public function wpbc_activate() {
279
280 WPBC_Action_Scheduler_Compatibility::raise_memory_limit();
281 WPBC_Action_Scheduler_Compatibility::raise_time_limit( 300 );
282
283 update_bk_option( $this->init_option['option-activation_process'], 'On' );
284
285 make_bk_action( 'wpbc_activation' ); // S T A R T.
286
287 update_bk_option( $this->init_option['option-version_num'], WP_BK_VERSION_NUM );
288
289 update_bk_option( $this->init_option['option-activation_process'], 'Off' );
290 }
291
292
293 /**
294 * Run Deactivate
295 */
296 public function wpbc_deactivate() {
297
298 WPBC_Action_Scheduler_Compatibility::raise_memory_limit();
299 WPBC_Action_Scheduler_Compatibility::raise_time_limit( 300 );
300
301 $is_delete_if_deactive = get_bk_option( $this->init_option['option-is_delete_if_deactive'] ); // check.
302
303 if ( 'On' === $is_delete_if_deactive ) {
304
305 make_bk_action( 'wpbc_deactivation' ); // F I N I S H.
306
307 delete_bk_option( $this->init_option['option-version_num'] );
308
309 delete_bk_option( $this->init_option['option-activation_process'] );
310 }
311 }
312
313 }