1
|
|
|
<?php if ( !defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
2
|
|
|
exit( 'No direct script access allowed' ); |
3
|
|
|
} |
4
|
|
|
/** |
5
|
|
|
* |
6
|
|
|
* Event Espresso |
7
|
|
|
* |
8
|
|
|
* Event Registration and Ticketing Management Plugin for WordPress |
9
|
|
|
* |
10
|
|
|
* @ package Event Espresso |
11
|
|
|
* @ author Event Espresso |
12
|
|
|
* @ copyright (c) 2008-2014 Event Espresso All Rights Reserved. |
13
|
|
|
* @ license http://eventespresso.com/support/terms-conditions/ * see Plugin Licensing * |
14
|
|
|
* @ link http://www.eventespresso.com |
15
|
|
|
* @ since 4.3 |
16
|
|
|
* |
17
|
|
|
*/ |
18
|
|
|
|
19
|
|
|
|
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Class EE_Addon |
23
|
|
|
* |
24
|
|
|
* Abstract Parent class for all classes that want to function as EE Addons |
25
|
|
|
* |
26
|
|
|
* @package Event Espresso |
27
|
|
|
* @subpackage core |
28
|
|
|
* @author Michael Nelson, Brent Christensen |
29
|
|
|
*/ |
30
|
|
|
abstract class EE_Addon extends EE_Configurable { |
31
|
|
|
|
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* prefix to be added onto an addon's plugin slug to make a wp option name |
35
|
|
|
* which will be used to store the plugin's activation history |
36
|
|
|
*/ |
37
|
|
|
const ee_addon_version_history_option_prefix = 'ee_version_history_'; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @var $_version |
41
|
|
|
* @type string |
42
|
|
|
*/ |
43
|
|
|
protected $_version = ''; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @var $_min_core_version |
47
|
|
|
* @type string |
48
|
|
|
*/ |
49
|
|
|
protected $_min_core_version = ''; |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* derived from plugin 'main_file_path using plugin_basename() |
53
|
|
|
* |
54
|
|
|
* @type string $_plugin_basename |
55
|
|
|
*/ |
56
|
|
|
protected $_plugin_basename = ''; |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* A non-internationalized name to identify this addon for use in URLs, etc |
60
|
|
|
* |
61
|
|
|
* @type string $_plugin_slug |
62
|
|
|
*/ |
63
|
|
|
protected $_plugin_slug = ''; |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* A non-internationalized name to identify this addon. Eg 'Calendar','MailChimp',etc/ |
67
|
|
|
* @type string _addon_name |
68
|
|
|
*/ |
69
|
|
|
protected $_addon_name = ''; |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* one of the EE_System::req_type_* constants |
73
|
|
|
* @type int $_req_type |
74
|
|
|
*/ |
75
|
|
|
protected $_req_type; |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* page slug to be used when generating the "Settings" link on the WP plugin page |
79
|
|
|
* |
80
|
|
|
* @type string $_plugin_action_slug |
81
|
|
|
*/ |
82
|
|
|
protected $_plugin_action_slug = ''; |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* if not empty, inserts a new table row after this plugin's row on the WP Plugins page |
86
|
|
|
* that can be used for adding upgrading/marketing info |
87
|
|
|
* |
88
|
|
|
* @type array $_plugins_page_row |
89
|
|
|
*/ |
90
|
|
|
protected $_plugins_page_row = array(); |
91
|
|
|
|
92
|
|
|
|
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* class constructor |
96
|
|
|
*/ |
97
|
|
|
public function __construct() { |
98
|
|
|
add_action( 'AHEE__EE_System__load_controllers__load_admin_controllers', array( $this, 'admin_init' ) ); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
|
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* @param mixed $version |
105
|
|
|
*/ |
106
|
|
|
public function set_version( $version = NULL ) { |
107
|
|
|
$this->_version = $version; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* get__version |
113
|
|
|
* @return string |
114
|
|
|
*/ |
115
|
|
|
public function version() { |
116
|
|
|
return $this->_version; |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
|
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* @param mixed $min_core_version |
123
|
|
|
*/ |
124
|
|
|
public function set_min_core_version( $min_core_version = NULL ) { |
125
|
|
|
$this->_min_core_version = $min_core_version; |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
|
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* get__min_core_version |
132
|
|
|
* @return string |
133
|
|
|
*/ |
134
|
|
|
public function min_core_version() { |
135
|
|
|
return $this->_min_core_version; |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
|
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* Sets addon_name |
142
|
|
|
* @param string $addon_name |
143
|
|
|
* @return boolean |
144
|
|
|
*/ |
145
|
|
|
public function set_name( $addon_name ) { |
146
|
|
|
return $this->_addon_name = $addon_name; |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
|
150
|
|
|
/** |
151
|
|
|
* Gets addon_name |
152
|
|
|
* @return string |
153
|
|
|
*/ |
154
|
|
|
public function name() { |
155
|
|
|
return $this->_addon_name; |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
|
159
|
|
|
|
160
|
|
|
/** |
161
|
|
|
* @return string |
162
|
|
|
*/ |
163
|
|
|
public function plugin_basename() { |
164
|
|
|
|
165
|
|
|
return $this->_plugin_basename; |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
|
169
|
|
|
|
170
|
|
|
/** |
171
|
|
|
* @param string $plugin_basename |
172
|
|
|
*/ |
173
|
|
|
public function set_plugin_basename( $plugin_basename ) { |
174
|
|
|
|
175
|
|
|
$this->_plugin_basename = $plugin_basename; |
176
|
|
|
} |
177
|
|
|
|
178
|
|
|
|
179
|
|
|
|
180
|
|
|
/** |
181
|
|
|
* @return string |
182
|
|
|
*/ |
183
|
|
|
public function plugin_slug() { |
184
|
|
|
|
185
|
|
|
return $this->_plugin_slug; |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
|
189
|
|
|
|
190
|
|
|
/** |
191
|
|
|
* @param string $plugin_slug |
192
|
|
|
*/ |
193
|
|
|
public function set_plugin_slug( $plugin_slug ) { |
194
|
|
|
|
195
|
|
|
$this->_plugin_slug = $plugin_slug; |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
|
199
|
|
|
|
200
|
|
|
/** |
201
|
|
|
* @return string |
202
|
|
|
*/ |
203
|
|
|
public function plugin_action_slug() { |
204
|
|
|
|
205
|
|
|
return $this->_plugin_action_slug; |
206
|
|
|
} |
207
|
|
|
|
208
|
|
|
|
209
|
|
|
|
210
|
|
|
/** |
211
|
|
|
* @param string $plugin_action_slug |
212
|
|
|
*/ |
213
|
|
|
public function set_plugin_action_slug( $plugin_action_slug ) { |
214
|
|
|
|
215
|
|
|
$this->_plugin_action_slug = $plugin_action_slug; |
216
|
|
|
} |
217
|
|
|
|
218
|
|
|
|
219
|
|
|
|
220
|
|
|
/** |
221
|
|
|
* @return array |
222
|
|
|
*/ |
223
|
|
|
public function get_plugins_page_row() { |
224
|
|
|
|
225
|
|
|
return $this->_plugins_page_row; |
226
|
|
|
} |
227
|
|
|
|
228
|
|
|
|
229
|
|
|
|
230
|
|
|
/** |
231
|
|
|
* @param array $plugins_page_row |
232
|
|
|
*/ |
233
|
|
|
public function set_plugins_page_row( $plugins_page_row = array() ) { |
234
|
|
|
// sigh.... check for example content that I stupidly merged to master and remove it if found |
235
|
|
|
if ( ! is_array( $plugins_page_row ) && strpos( $plugins_page_row, '<h3>Promotions Addon Upsell Info</h3>' ) !== false ) { |
236
|
|
|
$plugins_page_row = ''; |
237
|
|
|
} |
238
|
|
|
$this->_plugins_page_row = $plugins_page_row; |
|
|
|
|
239
|
|
|
} |
240
|
|
|
|
241
|
|
|
|
242
|
|
|
|
243
|
|
|
/** |
244
|
|
|
* Called when EE core detects this addon has been activated for the first time. |
245
|
|
|
* If the site isn't in maintenance mode, should setup the addon's database |
246
|
|
|
* @return void |
247
|
|
|
*/ |
248
|
|
View Code Duplication |
public function new_install() { |
|
|
|
|
249
|
|
|
$classname = get_class($this); |
250
|
|
|
do_action("AHEE__{$classname}__new_install"); |
251
|
|
|
do_action('AHEE__EE_Addon__new_install', $this); |
252
|
|
|
EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old(); |
253
|
|
|
add_action( 'AHEE__EE_System__perform_activations_upgrades_and_migrations', array( $this, 'initialize_db_if_no_migrations_required' ) ); |
254
|
|
|
} |
255
|
|
|
|
256
|
|
|
|
257
|
|
|
|
258
|
|
|
/** |
259
|
|
|
* Called when EE core detects this addon has been reactivated. When this happens, |
260
|
|
|
* it's good to just check that your data is still intact |
261
|
|
|
* @return void |
262
|
|
|
*/ |
263
|
|
View Code Duplication |
public function reactivation() { |
|
|
|
|
264
|
|
|
$classname = get_class($this); |
265
|
|
|
do_action("AHEE__{$classname}__reactivation"); |
266
|
|
|
do_action('AHEE__EE_Addon__reactivation', $this); |
267
|
|
|
EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old(); |
268
|
|
|
add_action( 'AHEE__EE_System__perform_activations_upgrades_and_migrations', array( $this, 'initialize_db_if_no_migrations_required' ) ); |
269
|
|
|
} |
270
|
|
|
|
271
|
|
|
|
272
|
|
|
|
273
|
|
|
public function deactivation(){ |
274
|
|
|
$classname = get_class($this); |
275
|
|
|
// echo "Deactivating $classname";die; |
276
|
|
|
do_action("AHEE__{$classname}__deactivation"); |
277
|
|
|
do_action('AHEE__EE_Addon__deactivation', $this); |
278
|
|
|
//check if the site no longer needs to be in maintenance mode |
279
|
|
|
EE_Register_Addon::deregister( $this->name() ); |
280
|
|
|
EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old(); |
281
|
|
|
} |
282
|
|
|
|
283
|
|
|
|
284
|
|
|
|
285
|
|
|
/** |
286
|
|
|
* Takes care of double-checking that we're not in maintenance mode, and then |
287
|
|
|
* initializing this addon's necessary initial data. This is called by default on new activations |
288
|
|
|
* and reactivations |
289
|
|
|
* |
290
|
|
|
* @param boolean $verify_schema whether to verify the database's schema for this addon, or just its data. |
291
|
|
|
* This is a resource-intensive job so we prefer to only do it when necessary |
292
|
|
|
* @return void |
293
|
|
|
* @throws \EE_Error |
294
|
|
|
*/ |
295
|
|
|
public function initialize_db_if_no_migrations_required( $verify_schema = true ) { |
296
|
|
|
if( $verify_schema === '' ) { |
297
|
|
|
//wp core bug imo: if no args are passed to `do_action('some_hook_name')` besides the hook's name |
298
|
|
|
//(ie, no 2nd or 3rd arguments), instead of calling the registered callbacks with no arguments, it |
299
|
|
|
//calls them with an argument of an empty string (ie ""), which evaluates to false |
300
|
|
|
//so we need to treat the empty string as if nothing had been passed, and should instead use the default |
301
|
|
|
$verify_schema = true; |
302
|
|
|
} |
303
|
|
|
if ( EE_Maintenance_Mode::instance()->level() !== EE_Maintenance_Mode::level_2_complete_maintenance ) { |
304
|
|
|
if( $verify_schema ) { |
305
|
|
|
$this->initialize_db(); |
306
|
|
|
} |
307
|
|
|
$this->initialize_default_data(); |
308
|
|
|
//@todo: this will probably need to be adjusted in 4.4 as the array changed formats I believe |
309
|
|
|
EE_Data_Migration_Manager::instance()->update_current_database_state_to( |
310
|
|
|
array( |
311
|
|
|
'slug' => $this->name(), |
312
|
|
|
'version' => $this->version() |
313
|
|
|
) |
314
|
|
|
); |
315
|
|
|
/* make sure core's data is a-ok |
316
|
|
|
* (at the time of writing, we especially want to verify all the caps are present |
317
|
|
|
* because payment method type capabilities are added dynamically, and it's |
318
|
|
|
* possible this addon added a payment method. But it's also possible |
319
|
|
|
* other data needs to be verified) |
320
|
|
|
*/ |
321
|
|
|
EEH_Activation::initialize_db_content(); |
322
|
|
|
update_option( 'ee_flush_rewrite_rules', TRUE ); |
323
|
|
|
//in case there are lots of addons being activated at once, let's force garbage collection |
324
|
|
|
//to help avoid memory limit errors |
325
|
|
|
//EEH_Debug_Tools::instance()->measure_memory( 'db content initialized for ' . get_class( $this), true ); |
326
|
|
|
gc_collect_cycles(); |
327
|
|
|
}else{ |
328
|
|
|
//ask the data migration manager to init this addon's data |
329
|
|
|
//when migrations are finished because we can't do it now |
330
|
|
|
EE_Data_Migration_Manager::instance()->enqueue_db_initialization_for( $this->name() ); |
331
|
|
|
} |
332
|
|
|
} |
333
|
|
|
|
334
|
|
|
|
335
|
|
|
|
336
|
|
|
/** |
337
|
|
|
* Used to setup this addon's database tables, but not necessarily any default |
338
|
|
|
* data in them. The default is to actually use the most up-to-date data migration script |
339
|
|
|
* for this addon, and just use its schema_changes_before_migration() and schema_changes_after_migration() |
340
|
|
|
* methods to setup the db. |
341
|
|
|
*/ |
342
|
|
|
public function initialize_db() { |
343
|
|
|
//find the migration script that sets the database to be compatible with the code |
344
|
|
|
$current_dms_name = EE_Data_Migration_Manager::instance()->get_most_up_to_date_dms( $this->name() ); |
345
|
|
|
if( $current_dms_name ){ |
346
|
|
|
$current_data_migration_script = EE_Registry::instance()->load_dms( $current_dms_name ); |
347
|
|
|
$current_data_migration_script->set_migrating( FALSE ); |
348
|
|
|
$current_data_migration_script->schema_changes_before_migration(); |
349
|
|
|
$current_data_migration_script->schema_changes_after_migration(); |
350
|
|
|
if ( $current_data_migration_script->get_errors() ) { |
351
|
|
|
foreach( $current_data_migration_script->get_errors() as $error ) { |
352
|
|
|
EE_Error::add_error( $error, __FILE__, __FUNCTION__, __LINE__ ); |
353
|
|
|
} |
354
|
|
|
} |
355
|
|
|
} |
356
|
|
|
//if not DMS was found that should be ok. This addon just doesn't require any database changes |
357
|
|
|
EE_Data_Migration_Manager::instance()->update_current_database_state_to( |
358
|
|
|
array( |
359
|
|
|
'slug' => $this->name(), |
360
|
|
|
'version' => $this->version() |
361
|
|
|
) |
362
|
|
|
); |
363
|
|
|
} |
364
|
|
|
|
365
|
|
|
|
366
|
|
|
|
367
|
|
|
/** |
368
|
|
|
* If you want to setup default data for the addon, override this method, and call |
369
|
|
|
* parent::initialize_default_data() from within it. This is normally called |
370
|
|
|
* from EE_Addon::initialize_db_if_no_migrations_required(), just after EE_Addon::initialize_db() |
371
|
|
|
* and should verify default data is present (but this is also called |
372
|
|
|
* on reactivations and just after migrations, so please verify you actually want |
373
|
|
|
* to ADD default data, because it may already be present). |
374
|
|
|
* However, please call this parent (currently it just fires a hook which other |
375
|
|
|
* addons may be depending on) |
376
|
|
|
*/ |
377
|
|
|
public function initialize_default_data() { |
378
|
|
|
/** |
379
|
|
|
* Called when an addon is ensuring its default data is set (possibly called |
380
|
|
|
* on a reactivation, so first check for the absence of other data before setting |
381
|
|
|
* default data) |
382
|
|
|
* @param EE_Addon $addon the addon that called this |
383
|
|
|
*/ |
384
|
|
|
do_action( 'AHEE__EE_Addon__initialize_default_data__begin', $this ); |
385
|
|
|
//override to insert default data. It is safe to use the models here |
386
|
|
|
//because the site should not be in maintenance mode |
387
|
|
|
} |
388
|
|
|
|
389
|
|
|
|
390
|
|
|
|
391
|
|
|
/** |
392
|
|
|
* EE Core detected that this addon has been upgraded. We should check if there |
393
|
|
|
* are any new migration scripts, and if so put the site into maintenance mode until |
394
|
|
|
* they're ran |
395
|
|
|
* @return void |
396
|
|
|
*/ |
397
|
|
View Code Duplication |
public function upgrade() { |
|
|
|
|
398
|
|
|
$classname = get_class($this); |
399
|
|
|
do_action("AHEE__{$classname}__upgrade"); |
400
|
|
|
do_action('AHEE__EE_Addon__upgrade', $this); |
401
|
|
|
EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old(); |
402
|
|
|
//also it's possible there is new default data that needs to be added |
403
|
|
|
add_action( |
404
|
|
|
'AHEE__EE_System__perform_activations_upgrades_and_migrations', array( $this, 'initialize_db_if_no_migrations_required' ) |
405
|
|
|
); |
406
|
|
|
} |
407
|
|
|
|
408
|
|
|
|
409
|
|
|
|
410
|
|
|
/** |
411
|
|
|
* If Core detects this addon has been downgraded, you may want to invoke some special logic here. |
412
|
|
|
*/ |
413
|
|
|
public function downgrade() { |
414
|
|
|
$classname = get_class($this); |
415
|
|
|
do_action("AHEE__{$classname}__downgrade"); |
416
|
|
|
do_action('AHEE__EE_Addon__downgrade', $this); |
417
|
|
|
//it's possible there's old default data that needs to be double-checked |
418
|
|
|
add_action( 'AHEE__EE_System__perform_activations_upgrades_and_migrations', array( $this, 'initialize_db_if_no_migrations_required' ) ); |
419
|
|
|
} |
420
|
|
|
|
421
|
|
|
|
422
|
|
|
|
423
|
|
|
/** |
424
|
|
|
* set_db_update_option_name |
425
|
|
|
* Until we do something better, we'll just check for migration scripts upon |
426
|
|
|
* plugin activation only. In the future, we'll want to do it on plugin updates too |
427
|
|
|
* @return bool |
428
|
|
|
*/ |
429
|
|
|
public function set_db_update_option_name(){ |
430
|
|
|
EE_Error::doing_it_wrong(__FUNCTION__, __('EE_Addon::set_db_update_option_name was renamed to EE_Addon::set_activation_indicator_option', 'event_espresso'), '4.3.0.alpha.016'); |
431
|
|
|
//let's just handle this on the next request, ok? right now we're just not really ready |
432
|
|
|
return $this->set_activation_indicator_option(); |
433
|
|
|
} |
434
|
|
|
|
435
|
|
|
|
436
|
|
|
/** |
437
|
|
|
* |
438
|
|
|
* Returns the name of the activation indicator option |
439
|
|
|
* (an option which is set temporarily to indicate that this addon was just activated) |
440
|
|
|
* @deprecated since version 4.3.0.alpha.016 |
441
|
|
|
* @return string |
442
|
|
|
*/ |
443
|
|
|
public function get_db_update_option_name() { |
444
|
|
|
EE_Error::doing_it_wrong(__FUNCTION__, __('EE_Addon::get_db_update_option was renamed to EE_Addon::get_activation_indicator_option_name', 'event_espresso'), '4.3.0.alpha.016'); |
445
|
|
|
return $this->get_activation_indicator_option_name(); |
446
|
|
|
} |
447
|
|
|
|
448
|
|
|
|
449
|
|
|
|
450
|
|
|
/** |
451
|
|
|
* When the addon is activated, this should be called to set a wordpress option that |
452
|
|
|
* indicates it was activated. This is especially useful for detecting reactivations. |
453
|
|
|
* @return bool |
454
|
|
|
*/ |
455
|
|
|
public function set_activation_indicator_option() { |
456
|
|
|
// let's just handle this on the next request, ok? right now we're just not really ready |
457
|
|
|
return update_option( $this->get_activation_indicator_option_name(), TRUE ); |
458
|
|
|
} |
459
|
|
|
|
460
|
|
|
|
461
|
|
|
/** |
462
|
|
|
* Gets the name of the wp option which is used to temporarily indicate that this addon was activated |
463
|
|
|
* @return string |
464
|
|
|
*/ |
465
|
|
|
public function get_activation_indicator_option_name(){ |
466
|
|
|
return 'ee_activation_' . $this->name(); |
467
|
|
|
} |
468
|
|
|
|
469
|
|
|
|
470
|
|
|
|
471
|
|
|
|
472
|
|
|
/** |
473
|
|
|
* Used by EE_System to set the request type of this addon. Should not be used by addon developers |
474
|
|
|
* @param int $req_type |
475
|
|
|
*/ |
476
|
|
|
public function set_req_type( $req_type ) { |
477
|
|
|
$this->_req_type = $req_type; |
478
|
|
|
} |
479
|
|
|
|
480
|
|
|
|
481
|
|
|
|
482
|
|
|
/** |
483
|
|
|
* Returns the request type of this addon (ie, EE_System::req_type_normal, EE_System::req_type_new_activation, EE_System::req_type_reactivation, EE_System::req_type_upgrade, or EE_System::req_type_downgrade). This is set by EE_System when it is checking for new install or upgrades |
484
|
|
|
* of addons |
485
|
|
|
*/ |
486
|
|
|
public function detect_req_type() { |
487
|
|
|
if( ! $this->_req_type ){ |
488
|
|
|
$this->detect_activation_or_upgrade(); |
489
|
|
|
} |
490
|
|
|
return $this->_req_type; |
491
|
|
|
} |
492
|
|
|
|
493
|
|
|
|
494
|
|
|
|
495
|
|
|
/** |
496
|
|
|
* Detects the request type for this addon (whether it was just activated, upgrades, a normal request, etc.) |
497
|
|
|
* Should only be called once per request |
498
|
|
|
* @return void |
499
|
|
|
*/ |
500
|
|
|
public function detect_activation_or_upgrade(){ |
501
|
|
|
$activation_history_for_addon = $this->get_activation_history(); |
502
|
|
|
// d($activation_history_for_addon); |
503
|
|
|
$request_type = EE_System::detect_req_type_given_activation_history($activation_history_for_addon, $this->get_activation_indicator_option_name(), $this->version()); |
504
|
|
|
$this->set_req_type($request_type); |
505
|
|
|
$classname = get_class($this); |
506
|
|
|
switch($request_type){ |
507
|
|
|
case EE_System::req_type_new_activation: |
508
|
|
|
do_action( "AHEE__{$classname}__detect_activations_or_upgrades__new_activation" ); |
509
|
|
|
do_action( 'AHEE__EE_Addon__detect_activations_or_upgrades__new_activation', $this ); |
510
|
|
|
$this->new_install(); |
511
|
|
|
$this->update_list_of_installed_versions( $activation_history_for_addon ); |
512
|
|
|
break; |
513
|
|
|
case EE_System::req_type_reactivation: |
514
|
|
|
do_action( "AHEE__{$classname}__detect_activations_or_upgrades__reactivation" ); |
515
|
|
|
do_action( 'AHEE__EE_Addon__detect_activations_or_upgrades__reactivation', $this ); |
516
|
|
|
$this->reactivation(); |
517
|
|
|
$this->update_list_of_installed_versions( $activation_history_for_addon ); |
518
|
|
|
break; |
519
|
|
|
case EE_System::req_type_upgrade: |
520
|
|
|
do_action( "AHEE__{$classname}__detect_activations_or_upgrades__upgrade" ); |
521
|
|
|
do_action( 'AHEE__EE_Addon__detect_activations_or_upgrades__upgrade', $this ); |
522
|
|
|
$this->upgrade(); |
523
|
|
|
$this->update_list_of_installed_versions($activation_history_for_addon ); |
524
|
|
|
break; |
525
|
|
|
case EE_System::req_type_downgrade: |
526
|
|
|
do_action( "AHEE__{$classname}__detect_activations_or_upgrades__downgrade" ); |
527
|
|
|
do_action( 'AHEE__EE_Addon__detect_activations_or_upgrades__downgrade', $this ); |
528
|
|
|
$this->downgrade(); |
529
|
|
|
$this->update_list_of_installed_versions($activation_history_for_addon ); |
530
|
|
|
break; |
531
|
|
|
case EE_System::req_type_normal: |
532
|
|
|
default: |
533
|
|
|
// $this->_maybe_redirect_to_ee_about(); |
534
|
|
|
break; |
535
|
|
|
} |
536
|
|
|
|
537
|
|
|
do_action( "AHEE__{$classname}__detect_if_activation_or_upgrade__complete" ); |
538
|
|
|
} |
539
|
|
|
|
540
|
|
|
/** |
541
|
|
|
* Updates the version history for this addon |
542
|
|
|
* @param array $version_history |
543
|
|
|
* @param string $current_version_to_add |
544
|
|
|
* @return boolean success |
545
|
|
|
*/ |
546
|
|
|
public function update_list_of_installed_versions($version_history = NULL,$current_version_to_add = NULL) { |
547
|
|
|
if( ! $version_history ) { |
548
|
|
|
$version_history = $this->get_activation_history(); |
549
|
|
|
} |
550
|
|
|
if( $current_version_to_add === NULL){ |
551
|
|
|
$current_version_to_add = $this->version(); |
552
|
|
|
} |
553
|
|
|
$version_history[ $current_version_to_add ][] = date( 'Y-m-d H:i:s',time() ); |
554
|
|
|
// resave |
555
|
|
|
// echo "updating list of installed versions:".$this->get_activation_history_option_name();d($version_history); |
556
|
|
|
return update_option( $this->get_activation_history_option_name(), $version_history ); |
557
|
|
|
} |
558
|
|
|
|
559
|
|
|
/** |
560
|
|
|
* Gets the name of the wp option that stores the activation history |
561
|
|
|
* of this addon |
562
|
|
|
* @return string |
563
|
|
|
*/ |
564
|
|
|
public function get_activation_history_option_name(){ |
565
|
|
|
return self::ee_addon_version_history_option_prefix . $this->name(); |
566
|
|
|
} |
567
|
|
|
|
568
|
|
|
|
569
|
|
|
|
570
|
|
|
/** |
571
|
|
|
* Gets the wp option which stores the activation history for this addon |
572
|
|
|
* @return array |
573
|
|
|
*/ |
574
|
|
|
public function get_activation_history(){ |
575
|
|
|
return get_option($this->get_activation_history_option_name(), NULL); |
576
|
|
|
} |
577
|
|
|
|
578
|
|
|
|
579
|
|
|
|
580
|
|
|
/** |
581
|
|
|
* @param string $config_section |
582
|
|
|
*/ |
583
|
|
|
public function set_config_section( $config_section = '' ) { |
584
|
|
|
$this->_config_section = ! empty( $config_section ) ? $config_section : 'addons'; |
585
|
|
|
} |
586
|
|
|
/** |
587
|
|
|
* filepath to the main file, which can be used for register_activation_hook, register_deactivation_hook, etc. |
588
|
|
|
* @type string |
589
|
|
|
*/ |
590
|
|
|
protected $_main_plugin_file; |
591
|
|
|
|
592
|
|
|
/** |
593
|
|
|
* |
594
|
|
|
* Sets the filepath to the main plugin file |
595
|
|
|
* @param string $filepath |
596
|
|
|
*/ |
597
|
|
|
public function set_main_plugin_file( $filepath ) { |
598
|
|
|
$this->_main_plugin_file = $filepath; |
599
|
|
|
} |
600
|
|
|
/** |
601
|
|
|
* gets the filepath to teh main file |
602
|
|
|
* @return string |
603
|
|
|
*/ |
604
|
|
|
public function get_main_plugin_file(){ |
605
|
|
|
return $this->_main_plugin_file; |
606
|
|
|
} |
607
|
|
|
|
608
|
|
|
/** |
609
|
|
|
* Gets the filename (no path) of the main file (the main file loaded |
610
|
|
|
* by WP) |
611
|
|
|
* @return string |
612
|
|
|
*/ |
613
|
|
|
public function get_main_plugin_file_basename() { |
614
|
|
|
return plugin_basename( $this->get_main_plugin_file() ); |
615
|
|
|
} |
616
|
|
|
|
617
|
|
|
/** |
618
|
|
|
* Gets the folder name which contains the main plugin file |
619
|
|
|
* @return string |
620
|
|
|
*/ |
621
|
|
|
public function get_main_plugin_file_dirname(){ |
622
|
|
|
return dirname( $this->get_main_plugin_file() ); |
623
|
|
|
} |
624
|
|
|
|
625
|
|
|
|
626
|
|
|
/** |
627
|
|
|
* sets hooks used in the admin |
628
|
|
|
* |
629
|
|
|
* @return void |
630
|
|
|
*/ |
631
|
|
|
public function admin_init(){ |
632
|
|
|
// is admin and not in M-Mode ? |
633
|
|
|
if ( is_admin() && ! EE_Maintenance_Mode::instance()->level() ) { |
634
|
|
|
add_filter( 'plugin_action_links', array( $this, 'plugin_action_links' ), 10, 2 ); |
635
|
|
|
add_filter( 'after_plugin_row_' . $this->_plugin_basename, array( $this, 'after_plugin_row' ), 10, 3 ); |
636
|
|
|
} |
637
|
|
|
} |
638
|
|
|
|
639
|
|
|
|
640
|
|
|
|
641
|
|
|
/** |
642
|
|
|
* plugin_actions |
643
|
|
|
* |
644
|
|
|
* Add a settings link to the Plugins page, so people can go straight from the plugin page to the settings page. |
645
|
|
|
* |
646
|
|
|
* @param $links |
647
|
|
|
* @param $file |
648
|
|
|
* @return array |
649
|
|
|
*/ |
650
|
|
|
public function plugin_action_links( $links, $file ) { |
651
|
|
|
if ( $file === $this->plugin_basename() && $this->plugin_action_slug() !== '' ) { |
652
|
|
|
// before other links |
653
|
|
|
array_unshift( $links, '<a href="admin.php?page=' . $this->plugin_action_slug() . '">' . __( 'Settings' ) . '</a>' ); |
654
|
|
|
} |
655
|
|
|
return $links; |
656
|
|
|
} |
657
|
|
|
|
658
|
|
|
|
659
|
|
|
|
660
|
|
|
/** |
661
|
|
|
* after_plugin_row |
662
|
|
|
* |
663
|
|
|
* Add additional content to the plugins page plugin row |
664
|
|
|
* Inserts another row |
665
|
|
|
* |
666
|
|
|
* @param $plugin_file |
667
|
|
|
* @param $plugin_data |
668
|
|
|
* @param $status |
669
|
|
|
* @return void |
670
|
|
|
*/ |
671
|
|
|
public function after_plugin_row( $plugin_file, $plugin_data, $status ) { |
672
|
|
|
|
673
|
|
|
$after_plugin_row = ''; |
674
|
|
|
if ( $plugin_file === $this->plugin_basename() && $this->get_plugins_page_row() !== '' ) { |
675
|
|
|
$class = $status ? 'active' : 'inactive'; |
676
|
|
|
$plugins_page_row = $this->get_plugins_page_row(); |
677
|
|
|
$link_text = isset( $plugins_page_row[ 'link_text' ] ) ? $plugins_page_row[ 'link_text' ] : ''; |
678
|
|
|
$link_url = isset( $plugins_page_row[ 'link_url' ] ) ? $plugins_page_row[ 'link_url' ] : ''; |
679
|
|
|
$description = isset( $plugins_page_row[ 'description' ] ) ? $plugins_page_row[ 'description' ] : $plugins_page_row; |
680
|
|
|
if ( ! empty( $link_text ) && ! empty( $link_url ) && ! empty( $description )) { |
681
|
|
|
$after_plugin_row .= '<tr id="' . sanitize_title( $plugin_file ) . '-ee-addon" class="' . $class . '">'; |
682
|
|
|
$after_plugin_row .= '<th class="check-column" scope="row"></th>'; |
683
|
|
|
$after_plugin_row .= '<td class="ee-addon-upsell-info-title-td plugin-title column-primary">'; |
684
|
|
|
$after_plugin_row .= '<style> |
685
|
|
|
.ee-button, |
686
|
|
|
.ee-button:active, |
687
|
|
|
.ee-button:visited { |
688
|
|
|
box-sizing: border-box; |
689
|
|
|
display: inline-block; |
690
|
|
|
position: relative; |
691
|
|
|
top: -1px; |
692
|
|
|
padding:.5em 1em; |
693
|
|
|
margin: 0; |
694
|
|
|
background: #00B1CA -webkit-linear-gradient( #4EBFDE, #00B1CA ); /* For Safari 5.1 to 6.0 */ |
695
|
|
|
background: #00B1CA -o-linear-gradient( #4EBFDE, #00B1CA ); /* For Opera 11.1 to 12.0 */ |
696
|
|
|
background: #00B1CA -moz-linear-gradient( #4EBFDE, #00B1CA ); /* For Firefox 3.6 to 15 */ |
697
|
|
|
background: #00B1CA linear-gradient( #4EBFDE, #00B1CA ); /* Standard syntax */ |
698
|
|
|
border: 1px solid rgba(0,0,0,0.1) !important; |
699
|
|
|
border-top: 1px solid rgba(255,255,255,0.5) !important; |
700
|
|
|
border-bottom: 2px solid rgba(0,0,0,0.25) !important; |
701
|
|
|
font-weight: normal; |
702
|
|
|
cursor: pointer; |
703
|
|
|
color: #fff !important; |
704
|
|
|
text-decoration: none !important; |
705
|
|
|
text-align: center; |
706
|
|
|
line-height: 1em; |
707
|
|
|
/* line-height: 1;*/ |
708
|
|
|
-moz-border-radius: 3px; |
709
|
|
|
-webkit-border-radius: 3px; |
710
|
|
|
border-radius: 3px; |
711
|
|
|
-moz-box-shadow: none; |
712
|
|
|
-webkit-box-shadow: none; |
713
|
|
|
box-shadow: none; |
714
|
|
|
} |
715
|
|
|
.ee-button:hover { |
716
|
|
|
color: #fff !important; |
717
|
|
|
background: #4EBFDE; |
718
|
|
|
} |
719
|
|
|
.ee-button:active { top:0; } |
720
|
|
|
</style>'; |
721
|
|
|
$after_plugin_row .= ' |
722
|
|
|
<p class="ee-addon-upsell-info-dv"> |
723
|
|
|
<a class="ee-button" href="' . $link_url . '">' . $link_text . ' <span class="dashicons dashicons-arrow-right-alt2" style="margin:0;"></span></a> |
724
|
|
|
</p>'; |
725
|
|
|
$after_plugin_row .= '</td>'; |
726
|
|
|
$after_plugin_row .= '<td class="ee-addon-upsell-info-desc-td column-description desc">'; |
727
|
|
|
$after_plugin_row .= $description; |
728
|
|
|
$after_plugin_row .= '</td>'; |
729
|
|
|
$after_plugin_row .= '</tr>'; |
730
|
|
|
} else { |
731
|
|
|
$after_plugin_row .= $description; |
732
|
|
|
} |
733
|
|
|
} |
734
|
|
|
|
735
|
|
|
echo $after_plugin_row; |
736
|
|
|
} |
737
|
|
|
|
738
|
|
|
|
739
|
|
|
|
740
|
|
|
/** |
741
|
|
|
* a safe space for addons to add additional logic like setting hooks |
742
|
|
|
* that will run immediately after addon registration |
743
|
|
|
* making this a great place for code that needs to be "omnipresent" |
744
|
|
|
* |
745
|
|
|
* @since 4.9.26 |
746
|
|
|
*/ |
747
|
|
|
public function after_registration() |
748
|
|
|
{ |
749
|
|
|
// cricket chirp... cricket chirp... |
750
|
|
|
} |
751
|
|
|
|
752
|
|
|
|
753
|
|
|
} |
754
|
|
|
// End of file EE_Addon.core.php |
755
|
|
|
// Location: /core/EE_Addon.core.php |
756
|
|
|
|
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.
For example, imagine you have a variable
$accountId
that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to theid
property of an instance of theAccount
class. This class holds a proper account, so the id value must no longer be false.Either this assignment is in error or a type check should be added for that assignment.