PluginProbe
Booking Manager – Sync WP Booking Calendar – Import Events, Export Bookings to ICS Calendar / 2.0
Booking Manager – Sync WP Booking Calendar – Import Events, Export Bookings to ICS Calendar v2.0
2.1.21 2.1.20 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 trunk 1.1 2.0 2.0.1 2.0.10.2 2.0.11 2.0.12 2.0.13 2.0.14 2.0.15 2.0.16 2.0.17 2.0.18 2.0.2 2.0.20 2.0.21 2.0.22 All 55 releases
booking-manager / core / any / activation.php

activation.php in Booking Manager – Sync WP Booking Calendar – Import Events, Export Bookings to ICS Calendar 2.0, at core/any/activation.php

274 lines 10.7 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 oPlugins
5 * @category Installation
6 * @author wpdevelop
7 *
8 * @web-site http://oplugins.com/
9 * @email info@oplugins.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 WPBM_Install {
21
22 private $init_option;
23
24 function __construct() {
25
26 $default_init_option_names = array(
27 'option-version_num' => 'bookingmanager_version_num'
28 , 'option-is_delete_if_deactive' => 'bookingmanager_is_delete_if_deactive'
29 , 'option-activation_process' => 'bookingmanager_activation_process'
30 , 'transient-wpbm_activation_redirect' => '_bookingmanager_activation_redirect'
31 , 'message-delete_data' => '<strong>Warning!</strong> ' . 'All plugin data will be deleted when plugin had deactivated.' . '<br />'
32 . sprintf( 'If you want to save your plugin data, please uncheck the %s"Delete plugin data"%s at the', '<strong>', '</strong>')
33 , 'link_settings' => '<a href="">Settings</a>'
34 , 'link_whats_new' => '<a href="">Whats New</a>'
35 );
36
37 $init_option = $this->get_init_option_names();
38
39 $this->init_option = wp_parse_args( $init_option, $default_init_option_names );
40
41
42 register_activation_hook( WPBM_FILE, array( $this, 'wpbm_activate_initial' ) ); // WordPress > Plugins > "Activate" link.
43
44 register_deactivation_hook( WPBM_FILE, array( $this, 'wpbm_deactivate' ) ); // WordPress > Plugins > "Deactivate" link.
45
46 add_filter('upgrader_post_install', array( $this, 'wpbm_install_in_bulk_upgrade' ), 10, 2 ); // Upgrade during bulk upgrade of plugins
47
48 // Settings link at the plugin page
49 add_filter('plugin_action_links', array( $this, 'plugin_links'), 10, 2 );
50 // Warning message in plugin info
51 add_filter('plugin_row_meta', array( $this, 'plugin_row_meta'), 10, 4 );
52
53 $this->check_if_need_to_update(); // Check upgrade, if was no activation process
54 }
55
56
57 /** Must be overloaded in child CLASS
58 * Exmaple:
59 * return array(
60 'option-version_num' => 'bookingmanager_version_num'
61 , 'option-is_delete_if_deactive' => 'bookingmanager_is_delete_if_deactive'
62 , 'option-activation_process' => 'bookingmanager_activation_process'
63 , 'transient-wpbm_activation_redirect' => '_bookingmanager_activation_redirect'
64 , 'message-delete_data' => '<strong>Warning !!!</strong> ' . 'All plugin data will be deleted when plugin had deactivated.' . '<br />'
65 . sprintf( 'If you want to save your plugin data, please uncheck the %s"Delete plugin data"%s at the settings page.', '<strong>', '</strong>')
66 , 'link_settings' => '<a href="">Settings</a>'
67 , 'link_whats_new' => '<a href="">Whats New</a>'
68 );
69 */
70 abstract function get_init_option_names();
71
72
73 /** Must be overloaded in child CLASS
74 * Exmaple:
75 *
76 return false
77 */
78 abstract function is_update_from_lower_to_high_version();
79
80
81 ////////////////////////////////////////////////////////////////////////////
82
83
84 // <editor-fold defaultstate="collapsed" desc=" Update info of plugin at the plugins section ">
85
86 /** Update info of plugin at the plugins section */
87 function plugin_row_meta( $plugin_meta, $plugin_file, $plugin_data, $context ) {
88
89 $this_plugin = plugin_basename( WPBM_FILE );
90
91 if ($plugin_file == $this_plugin ) {
92
93 $is_delete_if_deactive = get_wpbm_option( $this->init_option['option-is_delete_if_deactive'] ); // check
94
95 if ($is_delete_if_deactive == 'On') { ?>
96 <div class="plugin-update-tr">
97 <div class="update-message notice inline notice-warning notice-altNO" style="font-size: 1em;line-height: 2em;margin:0 5px 10px;"><?php echo $this->init_option['message-delete_data']; ?></div>
98 </div>
99 <?php
100 }
101
102 /*
103 [$plugin_meta] => Array
104 (
105 [0] => Version 2.8.35
106 [1] => By wpdevelop
107 [2] => Visit plugin site
108 )
109
110 [$plugin_file] => bookingmanager/WPBM.php
111 [$plugin_data] => Array
112 (
113 [Name] => pluginname
114 [PluginURI] => http://oplugins.com/plugins/booking-manager/
115 [Version] => 2.8.35
116 [Description] => Some description...
117 [Author] => wpdevelop
118 [AuthorURI] => http://oplugins.com/
119 [TextDomain] =>
120 [DomainPath] =>
121 [Network] =>
122 [Title] => Title
123 [AuthorName] => wpdevelop
124 )
125
126 [$context] => all
127 /**/
128
129 // Echo plugin description here
130 return $plugin_meta;
131
132 } else
133 return $plugin_meta;
134 }
135
136
137 // Adds Settings link to plugins settings
138 function plugin_links($links, $file) {
139
140 $this_plugin = plugin_basename( WPBM_FILE );
141
142 if ( $file == $this_plugin ) {
143
144 if ( ! empty( $this->init_option[ 'link_settings' ] ) )
145 array_unshift( $links, $this->init_option[ 'link_settings' ] );
146
147 if ( ! empty( $this->init_option[ 'link_whats_new' ] ) )
148 array_unshift( $links, $this->init_option[ 'link_whats_new' ] );
149 }
150 return $links;
151 }
152
153 // </editor-fold>
154
155
156 ////////////////////////////////////////////////////////////////////////////
157
158
159 // Check about ability to upgrade, if was no activation process
160 private function check_if_need_to_update() {
161
162 if( is_admin() ) {
163
164 $wpbm_version_num = get_option( $this->init_option['option-version_num'] );
165
166 if ($wpbm_version_num === false )
167 $wpbm_version_num = '0';
168
169 $is_make_activation = false;
170
171 if ( version_compare( WPBM_VERSION_NUM, $wpbm_version_num) > 0 ) {
172
173 $is_make_activation = true;
174
175 } else {
176
177 // Check if we was update from free to paid or from lower to higher versions,
178 // and do not make normal activation. In this case we need to make update.
179 $is_make_activation = $this->is_update_from_lower_to_high_version();
180
181 }
182
183 // Add hook for initial activation.
184 if ( $is_make_activation ) {
185 add_action( 'plugins_loaded', array( $this, 'wpbm_activate_initial' ) );
186 }
187 }
188 }
189
190
191 /** Upgrade during bulk upgrade of plugins
192 *
193 * @param type $return
194 * @param type $hook_extra
195 * @return type
196 */
197 public function wpbm_install_in_bulk_upgrade( $return, $hook_extra ){
198
199 if ( is_wp_error( $return ) )
200 return $return;
201
202 if ( isset( $hook_extra ) )
203 if ( isset( $hook_extra['plugin'] ) ) {
204 $file_name = basename( WPBM_FILE );
205 $pos = strpos( $hook_extra['plugin'], trim( $file_name ) );
206 if ( $pos !== false ) {
207 $this->wpbm_activate();
208 }
209 }
210 return $return;
211 }
212
213
214 /** User clicked on "Activate" link at Plugins Menu.
215 *
216 * @return type
217 */
218 public function wpbm_activate_initial(){
219
220 // Activate the plugin
221 $this->wpbm_activate();
222
223 // Bail if this demo or activating from network, or bulk
224 if ( is_network_admin() || isset( $_GET['activate-multi'] ) || wpbm_is_this_demo() )
225 return;
226
227 // Add the transient to redirect - Showing Welcome screen
228 set_transient( $this->init_option['transient-wpbm_activation_redirect'], true, 30 );
229 }
230
231
232 ////////////////////////////////////////////////////////////////////////////
233
234
235 /** Run Activate */
236 public function wpbm_activate() {
237
238 if ( ( function_exists( 'set_time_limit' ) ) && // Try to extend script running to 15 minutes
239 ( ! in_array( ini_get( 'safe_mode' ), array( '1', 'On' ) ) ) // It's doesn't work, if PHP have SAFE MODE ON
240 ) set_time_limit( 900 );
241
242 ini_set('memory_limit','256M'); //FixIn:6.1.1.15
243
244 update_wpbm_option( $this->init_option['option-activation_process'], 'On' );
245
246 make_wpbm_action( 'wpbm_activation' ); // S T A R T
247
248 update_wpbm_option( $this->init_option['option-version_num'], WPBM_VERSION_NUM );
249
250 update_wpbm_option( $this->init_option['option-activation_process'], 'Off');
251 }
252
253
254 /** Run Deactivate */
255 public function wpbm_deactivate() {
256
257 if ( ( function_exists( 'set_time_limit' ) ) && // Try to extend script running to 15 minutes
258 ( ! in_array( ini_get( 'safe_mode' ), array( '1', 'On' ) ) ) // It's doesn't work, if PHP have SAFE MODE ON
259 ) set_time_limit( 900 );
260
261
262 $is_delete_if_deactive = get_wpbm_option( $this->init_option['option-is_delete_if_deactive'] ); // check
263
264 if ( $is_delete_if_deactive == 'On' ) {
265
266 make_wpbm_action( 'wpbm_deactivation' ); // F I N I S H
267
268 delete_wpbm_option( $this->init_option['option-version_num'] );
269
270 delete_wpbm_option( $this->init_option['option-activation_process'] );
271 }
272 }
273
274 }