Completed
Branch BETA-4.9-messages-queue-fixed (941081)
by
unknown
17:38 queued 10s
created

EE_Addon::name()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 3
rs 10
cc 1
eloc 2
nc 1
nop 0
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 = NULL;
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
	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
	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;
0 ignored issues
show
Documentation Bug introduced by
It seems like $plugins_page_row can also be of type string. However, the property $_plugins_page_row is declared as type array. Maybe add an additional type check?

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 the id property of an instance of the Account 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.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
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 mixed
247
	 */
248 View Code Duplication
	public function new_install() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
249
250
		$classname = get_class($this);
251
		do_action("AHEE__{$classname}__new_install");
252
		do_action("AHEE__EE_Addon__new_install", $this);
253
		EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old();
254
		add_action( 'AHEE__EE_System__perform_activations_upgrades_and_migrations', array( $this, 'initialize_db_if_no_migrations_required' ) );
255
	}
256
257
258
259
	/**
260
	 * Called when EE core detects this addon has been reactivated. When this happens,
261
	 * it's good to just check that your data is still intact
262
	 * @return void
263
	 */
264 View Code Duplication
	public function reactivation() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
265
		$classname = get_class($this);
266
		do_action("AHEE__{$classname}__reactivation");
267
		do_action("AHEE__EE_Addon__reactivation", $this);
268
		EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old();
269
		add_action( 'AHEE__EE_System__perform_activations_upgrades_and_migrations', array( $this, 'initialize_db_if_no_migrations_required' ) );
270
	}
271
272
	public function deactivation(){
273
		$classname = get_class($this);
274
//		echo "Deactivating $classname";die;
275
		do_action("AHEE__{$classname}__deactivation");
276
		do_action("AHEE__EE_Addon__deactivation", $this);
277
		//check if the site no longer needs to be in maintenance mode
278
		EE_Register_Addon::deregister( $this->name() );
279
		EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old();
280
	}
281
282
283
284
	/**
285
	 * Takes care of double-checking that we're not in maintenance mode, and then
286
	 * initializing this addon's necessary initial data. This is called by default on new activations
287
	 * and reactivations
288
	 * @param boolean $verify_schema whether to verify the database's schema for this addon, or just its data.
289
	 * This is a resource-intensive job so we prefer to only do it when necessary
290
	 * @return void
291
	 */
292
	public function initialize_db_if_no_migrations_required( $verify_schema = true ) {
293
		if( $verify_schema === '' ) {
294
			//wp core bug imo: if no args are passed to `do_action('some_hook_name')` besides the hook's name
295
			//(ie, no 2nd or 3rd arguments), instead of calling the registered callbacks with no arguments, it
296
			//calls them with an argument of an empty string (ie ""), which evaluates to false
297
			//so we need to treat the empty string as if nothing had been passed, and should instead use the default
298
			$verify_schema = true;
299
		}
300
		if ( EE_Maintenance_Mode::instance()->level() != EE_Maintenance_Mode::level_2_complete_maintenance ) {
301
			if( $verify_schema ) {
302
				$this->initialize_db();
303
			}
304
			$this->initialize_default_data();
305
			//@todo: this will probably need to be adjusted in 4.4 as the array changed formats I believe
306
			EE_Data_Migration_Manager::instance()->update_current_database_state_to(array('slug' => $this->name(), 'version' => $this->version()));
307
			/* make sure core's data is a-ok
308
			 * (at the time of writing, we especially want to verify all the caps are present
309
			 * because payment method type capabilities are added dynamically, and it's
310
			 * possible this addon added a payment method. But it's also possible
311
			 * other data needs to be verified)
312
			 */
313
			EE_Registry::instance()->load_helper('Activation');
314
			EEH_Activation::initialize_db_content();
315
			update_option( 'ee_flush_rewrite_rules', TRUE );
316
			//in case there are lots of addons being activated at once, let's force garbage collection
317
			//to help avoid memory limit errors
318
			//EEH_Debug_Tools::instance()->measure_memory( 'db content initialized for ' . get_class( $this), true );
319
			gc_collect_cycles();
320
		}else{
321
			//ask the data migration manager to init this addon's data
322
			//when migrations are finished because we can't do it now
323
			EE_Data_Migration_Manager::instance()->enqueue_db_initialization_for( $this->name() );
324
		}
325
	}
326
327
328
329
	/**
330
	 * Used to setup this addon's database tables, but not necessarily any default
331
	 * data in them. The default is to actually use the most up-to-date data migration script
332
	 * for this addon, and just use its schema_changes_before_migration() and schema_changes_after_migration()
333
	 * methods to setup the db.
334
	 */
335
	public function initialize_db() {
336
		//find the migration script that sets the database to be compatible with the code
337
		$current_dms_name = EE_Data_Migration_Manager::instance()->get_most_up_to_date_dms( $this->name() );
338
		if( $current_dms_name ){
339
			$current_data_migration_script = EE_Registry::instance()->load_dms( $current_dms_name );
340
			$current_data_migration_script->set_migrating( FALSE );
0 ignored issues
show
Bug introduced by
The method set_migrating cannot be called on $current_data_migration_script (of type boolean).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
341
			$current_data_migration_script->schema_changes_before_migration();
0 ignored issues
show
Bug introduced by
The method schema_changes_before_migration cannot be called on $current_data_migration_script (of type boolean).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
342
			$current_data_migration_script->schema_changes_after_migration();
0 ignored issues
show
Bug introduced by
The method schema_changes_after_migration cannot be called on $current_data_migration_script (of type boolean).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
343
			if ( $current_data_migration_script->get_errors() ) {
0 ignored issues
show
Bug introduced by
The method get_errors cannot be called on $current_data_migration_script (of type boolean).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
344
				foreach( $current_data_migration_script->get_errors() as $error ) {
0 ignored issues
show
Bug introduced by
The method get_errors cannot be called on $current_data_migration_script (of type boolean).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
345
					EE_Error::add_error( $error, __FILE__, __FUNCTION__, __LINE__ );
346
				}
347
			}
348
		}
349
		//if not DMS was found that should be ok. This addon just doesn't require any database changes
350
		EE_Data_Migration_Manager::instance()->update_current_database_state_to( array( 'slug' => $this->name(), 'version' => $this->version() ) );
351
	}
352
353
354
355
	/**
356
	 * If you want to setup default data for the addon, override this method, and call
357
	 * parent::initialize_default_data() from within it. This is normally called
358
	 * from EE_Addon::initialize_db_if_no_migrations_required(), just after EE_Addon::initialize_db()
359
	 * and should verify default data is present (but this is also called
360
	 * on reactivations and just after migrations, so please verify you actually want
361
	 * to ADD default data, because it may already be present).
362
	 * However, please call this parent (currently it just fires a hook which other
363
	 * addons may be depending on)
364
	 */
365
	public function initialize_default_data() {
366
		/**
367
		 * Called when an addon is ensuring its default data is set (possibly called
368
		 * on a reactivation, so first check for the absence of other data before setting
369
		 * default data)
370
		 * @param EE_Addon $addon the addon that called this
371
		 */
372
		do_action( 'AHEE__EE_Addon__initialize_default_data__begin', $this );
373
		//override to insert default data. It is safe to use the models here
374
		//because the site should not be in maintenance mode
375
	}
376
377
378
379
	/**
380
	 * EE Core detected that this addon has been upgraded. We should check if there
381
	 * are any new migration scripts, and if so put the site into maintenance mode until
382
	 * they're ran
383
	 * @return mixed
384
	 */
385 View Code Duplication
	public function upgrade() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
386
		$classname = get_class($this);
387
		do_action("AHEE__{$classname}__upgrade");
388
		do_action("AHEE__EE_Addon__upgrade", $this);
389
		EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old();
390
		//also it's possible there is new default data that needs to be added
391
		add_action( 'AHEE__EE_System__perform_activations_upgrades_and_migrations', array( $this, 'initialize_db_if_no_migrations_required' ) );
392
	}
393
394
395
396
	/**
397
	 * If Core detects this addon has been downgraded, you may want to invoke some special logic here.
398
	 */
399
	public function downgrade() {
400
		$classname = get_class($this);
401
		do_action("AHEE__{$classname}__downgrade");
402
		do_action("AHEE__EE_Addon__downgrade", $this);
403
		//it's possible there's old default data that needs to be double-checked
404
		add_action( 'AHEE__EE_System__perform_activations_upgrades_and_migrations', array( $this, 'initialize_db_if_no_migrations_required' ) );
405
	}
406
407
408
409
	/**
410
	 * set_db_update_option_name
411
	 * Until we do something better, we'll just check for migration scripts upon
412
	 * plugin activation only. In the future, we'll want to do it on plugin updates too
413
	 * @return bool
414
	 */
415
	public function set_db_update_option_name(){
416
		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');
417
		//let's just handle this on the next request, ok? right now we're just not really ready
418
		return $this->set_activation_indicator_option();
419
	}
420
421
422
	/**
423
	 *
424
	 * Returns the name of the activation indicator option
425
	 * (an option which is set temporarily to indicate that this addon was just activated)
426
	 * @deprecated since version 4.3.0.alpha.016
427
	 * @return string
428
	 */
429
	public function get_db_update_option_name() {
430
		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');
431
		return $this->get_activation_indicator_option_name();
432
	}
433
434
435
436
	/**
437
	 * When the addon is activated, this should be called to set a wordpress option that
438
	 * indicates it was activated. This is especially useful for detecting reactivations.
439
	 * @return bool
440
	 */
441
	public function set_activation_indicator_option() {
442
		// let's just handle this on the next request, ok? right now we're just not really ready
443
		return update_option( $this->get_activation_indicator_option_name(), TRUE );
444
	}
445
446
447
	/**
448
	 * Gets the name of the wp option which is used to temporarily indicate that this addon was activated
449
	 * @return string
450
	 */
451
	public function get_activation_indicator_option_name(){
452
		return 'ee_activation_' . $this->name();
453
	}
454
455
456
457
458
	/**
459
	 * Used by EE_System to set the request type of this addon. Should not be used by addon developers
460
	 * @param int $req_type
461
	 */
462
	function set_req_type( $req_type ) {
463
		$this->_req_type = $req_type;
464
	}
465
466
467
468
	/**
469
	 * 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
470
	 * of addons
471
	 */
472
	function detect_req_type() {
473
		if( ! $this->_req_type ){
474
			$this->detect_activation_or_upgrade();
475
		}
476
		return $this->_req_type;
477
	}
478
479
480
481
	/**
482
	 * Detects the request type for this addon (whether it was just activated, upgrades, a normal request, etc.)
483
	 * Should only be called once per request
484
	 * @return void
485
	 */
486
	function detect_activation_or_upgrade(){
487
		$activation_history_for_addon = $this->get_activation_history();
488
//		d($activation_history_for_addon);
489
		$request_type = EE_System::detect_req_type_given_activation_history($activation_history_for_addon, $this->get_activation_indicator_option_name(), $this->version());
490
		$this->set_req_type($request_type);
491
		$classname = get_class($this);
492
		switch($request_type){
493
			case EE_System::req_type_new_activation:
494
				do_action( "AHEE__{$classname}__detect_activations_or_upgrades__new_activation" );
495
				do_action( "AHEE__EE_Addon__detect_activations_or_upgrades__new_activation", $this );
496
				$this->new_install();
497
				$this->update_list_of_installed_versions( $activation_history_for_addon );
498
				break;
499
			case EE_System::req_type_reactivation:
500
				do_action( "AHEE__{$classname}__detect_activations_or_upgrades__reactivation" );
501
				do_action( "AHEE__EE_Addon__detect_activations_or_upgrades__reactivation", $this );
502
				$this->reactivation();
503
				$this->update_list_of_installed_versions( $activation_history_for_addon );
504
				break;
505
			case EE_System::req_type_upgrade:
506
				do_action( "AHEE__{$classname}__detect_activations_or_upgrades__upgrade" );
507
				do_action( "AHEE__EE_Addon__detect_activations_or_upgrades__upgrade", $this );
508
				$this->upgrade();
509
				$this->update_list_of_installed_versions($activation_history_for_addon );
510
				break;
511
			case EE_System::req_type_downgrade:
512
				do_action( "AHEE__{$classname}__detect_activations_or_upgrades__downgrade" );
513
				do_action( "AHEE__EE_Addon__detect_activations_or_upgrades__downgrade", $this );
514
				$this->downgrade();
515
				$this->update_list_of_installed_versions($activation_history_for_addon );
516
				break;
517
			case EE_System::req_type_normal:
518
			default:
519
//				$this->_maybe_redirect_to_ee_about();
520
				break;
521
		}
522
523
		do_action( "AHEE__{$classname}__detect_if_activation_or_upgrade__complete" );
524
	}
525
526
	/**
527
	 * Updates the version history for this addon
528
	 * @param array $version_history
529
	 * @param string $current_version_to_add
530
	 * @return boolean success
531
	 */
532
	public function update_list_of_installed_versions($version_history = NULL,$current_version_to_add = NULL) {
533
		if( ! $version_history ) {
534
			$version_history = $this->get_activation_history();
535
		}
536
		if( $current_version_to_add == NULL){
0 ignored issues
show
Bug introduced by
It seems like you are loosely comparing $current_version_to_add of type string|null against null; this is ambiguous if the string can be empty. Consider using a strict comparison === instead.
Loading history...
537
			$current_version_to_add = $this->version();
538
		}
539
		$version_history[ $current_version_to_add ][] = date( 'Y-m-d H:i:s',time() );
540
		// resave
541
//		echo "updating list of installed versions:".$this->get_activation_history_option_name();d($version_history);
542
		return update_option( $this->get_activation_history_option_name(), $version_history );
543
	}
544
545
	/**
546
	 * Gets the name of the wp option that stores the activation history
547
	 * of this addon
548
	 * @return string
549
	 */
550
	function get_activation_history_option_name(){
551
		return self::ee_addon_version_history_option_prefix . $this->name();
552
	}
553
554
555
556
	/**
557
	 * Gets the wp option which stores the activation history for this addon
558
	 * @return array
559
	 */
560
	function get_activation_history(){
561
		return get_option($this->get_activation_history_option_name(), NULL);
562
	}
563
564
565
566
	/**
567
	 * @param string $config_section
568
	 */
569
	public function set_config_section( $config_section = '' ) {
570
		$this->_config_section = ! empty( $config_section ) ? $config_section : 'addons';
571
	}
572
	/**
573
	 *	filepath to the main file, which can be used for register_activation_hook, register_deactivation_hook, etc.
574
	 * @type string
575
	 */
576
	protected $_main_plugin_file;
577
578
	/**
579
	 *
580
	 * Sets the filepath to the main plugin file
581
	 * @param string $filepath
582
	 */
583
	public function set_main_plugin_file( $filepath ) {
584
		$this->_main_plugin_file = $filepath;
585
	}
586
	/**
587
	 * gets the filepath to teh main file
588
	 * @return string
589
	 */
590
	public function get_main_plugin_file(){
591
		return $this->_main_plugin_file;
592
	}
593
594
	/**
595
	 * Gets the filename (no path) of the main file (the main file loaded
596
	 * by WP)
597
	 * @return string
598
	 */
599
	public function get_main_plugin_file_basename() {
600
		return plugin_basename( $this->get_main_plugin_file() );
601
	}
602
603
	/**
604
	 * Gets the folder name which contains the main plugin file
605
	 * @return string
606
	 */
607
	public function get_main_plugin_file_dirname(){
608
		return dirname( $this->get_main_plugin_file() );
609
	}
610
611
612
	/**
613
	 * sets hooks used in the admin
614
	 *
615
*@return string
616
	 */
617
	public function admin_init(){
618
		// is admin and not in M-Mode ?
619
		if ( is_admin() && ! EE_Maintenance_Mode::instance()->level() ) {
620
			add_filter( 'plugin_action_links', array( $this, 'plugin_action_links' ), 10, 2 );
621
			add_filter( 'after_plugin_row_' . $this->_plugin_basename, array( $this, 'after_plugin_row' ), 10, 3 );
622
		}
623
	}
624
625
626
627
	/**
628
	 * plugin_actions
629
	 *
630
	 * Add a settings link to the Plugins page, so people can go straight from the plugin page to the settings page.
631
	 *
632
	 * @param $links
633
	 * @param $file
634
	 * @return array
635
	 */
636
	public function plugin_action_links( $links, $file ) {
637
		if ( $file == $this->plugin_basename() && $this->plugin_action_slug() != '' ) {
638
			// before other links
639
			array_unshift( $links, '<a href="admin.php?page=' . $this->plugin_action_slug() . '">' . __( 'Settings' ) . '</a>' );
640
		}
641
		return $links;
642
	}
643
644
645
646
	/**
647
	 * after_plugin_row
648
	 *
649
	 * Add additional content to the plugins page plugin row
650
	 * Inserts another row
651
	 *
652
	 * @param $plugin_file
653
	 * @param $plugin_data
654
	 * @param $status
655
	 * @return string
656
	 */
657
	public function after_plugin_row( $plugin_file, $plugin_data, $status ) {
658
659
		$after_plugin_row = '';
660
		if ( $plugin_file == $this->plugin_basename() && $this->get_plugins_page_row() != '' ) {
661
			$class = $status ? 'active' : 'inactive';
662
			$plugins_page_row = $this->get_plugins_page_row();
663
			$link_text = isset( $plugins_page_row[ 'link_text' ] ) ? $plugins_page_row[ 'link_text' ] : '';
664
			$link_url = isset( $plugins_page_row[ 'link_url' ] ) ? $plugins_page_row[ 'link_url' ] : '';
665
			$description = isset( $plugins_page_row[ 'description' ] ) ? $plugins_page_row[ 'description' ] : $plugins_page_row;
666
			if ( ! empty( $link_text ) && ! empty( $link_url ) && ! empty( $description )) {
667
				$after_plugin_row .= '<tr id="' . sanitize_title( $plugin_file ) . '-ee-addon" class="' . $class . '">';
668
				$after_plugin_row .= '<th class="check-column" scope="row"></th>';
669
				$after_plugin_row .= '<td class="ee-addon-upsell-info-title-td plugin-title column-primary">';
670
				$after_plugin_row .= '<style>
671
.ee-button,
672
.ee-button:active,
673
.ee-button:visited {
674
	box-sizing: border-box;
675
	display: inline-block;
676
	position: relative;
677
	top: -1px;
678
	padding:.5em 1em;
679
	margin: 0;
680
	background: #00B1CA -webkit-linear-gradient( #4EBFDE, #00B1CA ); /* For Safari 5.1 to 6.0 */
681
	background: #00B1CA -o-linear-gradient( #4EBFDE, #00B1CA ); /* For Opera 11.1 to 12.0 */
682
	background: #00B1CA -moz-linear-gradient( #4EBFDE, #00B1CA ); /* For Firefox 3.6 to 15 */
683
	background: #00B1CA linear-gradient( #4EBFDE, #00B1CA ); /* Standard syntax */
684
	border: 1px solid rgba(0,0,0,0.1) !important;
685
	border-top: 1px solid rgba(255,255,255,0.5) !important;
686
	border-bottom: 2px solid rgba(0,0,0,0.25) !important;
687
	font-weight: normal;
688
	cursor: pointer;
689
	color: #fff !important;
690
	text-decoration: none !important;
691
	text-align: center;
692
	line-height: 1em;
693
/*	line-height: 1;*/
694
	-moz-border-radius: 3px;
695
	-webkit-border-radius: 3px;
696
	border-radius: 3px;
697
	-moz-box-shadow: none;
698
	-webkit-box-shadow: none;
699
	box-shadow: none;
700
}
701
.ee-button:hover {
702
	color: #fff !important;
703
	background: #4EBFDE;
704
}
705
.ee-button:active { top:0; }
706
</style>';
707
				$after_plugin_row .= '
708
<p class="ee-addon-upsell-info-dv">
709
	<a class="ee-button" href="' . $link_url . '">' . $link_text . ' &nbsp;<span class="dashicons dashicons-arrow-right-alt2" style="margin:0;"></span></a>
710
</p>';
711
				$after_plugin_row .= '</td>';
712
				$after_plugin_row .= '<td class="ee-addon-upsell-info-desc-td column-description desc">';
713
				$after_plugin_row .= $description;
714
				$after_plugin_row .= '</td>';
715
				$after_plugin_row .= '</tr>';
716
			} else {
717
				$after_plugin_row .= $description;
718
			}
719
		}
720
721
		echo $after_plugin_row;
722
	}
723
724
725
726
727
}
728
// End of file EE_Addon.core.php
729
// Location: /core/EE_Addon.core.php
730