Completed
Branch FET/337/reserved-instance-inte... (8ac9b7)
by
unknown
73:19 queued 58:57
created

EE_Addon::__construct()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

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