Completed
Branch FET/Gutenberg/11400/block-mana... (1c7938)
by
unknown
13:59 queued 16s
created

ExitModal::modalContainer()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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