Completed
Branch BUG/11475/decode-site-title-fo... (bbd86e)
by
unknown
13:39 queued 25s
created

ExitModal   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 94
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 94
rs 10
wmc 4
lcom 1
cbo 1

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A modalContainer() 0 4 1
A isModalActive() 0 10 1
B enqueues() 0 42 1
1
<?php
2
namespace EventEspresso\core\domain\services\admin;
3
4
use EventEspresso\core\services\assets\Registry;
5
use InvalidArgumentException;
6
use WP_User;
7
8
/**
9
 * ExitModal
10
 * Sets up server side logic etc for the exit modal survey triggered when deactivating EE core.
11
 *
12
 * DEVELOPERS: this is a in progress api, do not use this class or rely on its api to remain consistent.
13
 *
14
 * @package EventEspresso\core\domain\services\admin
15
 * @author  Darren Ethier
16
 * @since   $VID:$
17
 */
18
class ExitModal
19
{
20
21
    /**
22
     * @var Registry
23
     */
24
    private $assets_registry;
25
26
    /**
27
     * ExitModal constructor.
28
     *
29
     * @param Registry $assets_registry
30
     */
31
    public function __construct(Registry $assets_registry)
32
    {
33
        $this->assets_registry = $assets_registry;
34
        add_action('in_admin_footer', array($this, 'modalContainer'));
35
        add_action('admin_enqueue_scripts', array($this, 'enqueues'));
36
    }
37
38
39
    /**
40
     * Callback on in_admin_footer that is used to output the exit modal container.
41
     */
42
    public function modalContainer()
43
    {
44
        echo '<div id="ee-exit-survey-modal"></div>';
45
    }
46
47
48
    /**
49
     * Callback for `admin_enqueue_scripts` to take care of enqueueing scripts and styles specific to the modal.
50
     *
51
     * @throws InvalidArgumentException
52
     */
53
    public function enqueues()
54
    {
55
        $current_user = new WP_User(get_current_user_id());
56
        $this->assets_registry->addData(
57
            'exitModali18n',
58
            array(
59
                'introText' => htmlspecialchars(
60
                    __(
61
                        'Do you have a moment to share why you are deactivating Event Espresso?',
62
                        'event_espresso'
63
                    ),
64
                    ENT_NOQUOTES
65
                ),
66
                'doSurveyButtonText' => htmlspecialchars(
67
                    __(
68
                        'Sure I\'ll help',
69
                        'event_espresso'
70
                    ),
71
                    ENT_NOQUOTES
72
                ),
73
                'skipButtonText' => htmlspecialchars(
74
                    __(
75
                        'Skip',
76
                        'event_espresso'
77
                    ),
78
                    ENT_NOQUOTES
79
                )
80
            )
81
        );
82
        $this->assets_registry->addData(
83
            'exitModalInfo',
84
            array(
85
                'firstname' => htmlspecialchars($current_user->user_firstname),
86
                'emailaddress' => htmlspecialchars($current_user->user_email),
87
                'website' => htmlspecialchars(site_url()),
88
                'isModalActive' => $this->isModalActive()
89
            )
90
        );
91
92
        wp_enqueue_script('ee-wp-plugins-page');
93
        wp_enqueue_style('ee-wp-plugins-page');
94
    }
95
96
97
    /**
98
     * Exposes a filter switch for turning off the enqueueing of the modal script.
99
     * @return bool
100
     */
101
    private function isModalActive()
102
    {
103
        return filter_var(
104
            apply_filters(
105
                'FHEE__EventEspresso_core_domain_services_admin_ExitModal__isModalActive',
106
                true
107
            ),
108
            FILTER_VALIDATE_BOOLEAN
109
        );
110
    }
111
}