Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 93 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
DeactivationSurvey | |
0.00% |
0 / 93 |
|
0.00% |
0 / 3 |
12 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 61 |
|
0.00% |
0 / 1 |
2 | |||
deactivation_survey_assets | |
0.00% |
0 / 20 |
|
0.00% |
0 / 1 |
2 | |||
deactivation_survey_runtime | |
0.00% |
0 / 12 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | /** |
3 | * Brand plugins deactivation survey modal. |
4 | * |
5 | * @package NewfoldLabs\WP\Module\Deactivation |
6 | */ |
7 | |
8 | namespace NewfoldLabs\WP\Module\Deactivation; |
9 | |
10 | use NewfoldLabs\WP\ModuleLoader\Container; |
11 | use function NewfoldLabs\WP\ModuleLoader\container; |
12 | |
13 | /** |
14 | * Class DeactivationSurvey. |
15 | */ |
16 | class DeactivationSurvey { |
17 | |
18 | // public $container; |
19 | public $strings; |
20 | |
21 | /** |
22 | * DeactivationSurvey constructor. |
23 | */ |
24 | public function __construct() { |
25 | // $this->container = container(); |
26 | |
27 | $defaults = array( |
28 | 'surveyAriaTitle' => __( 'Plugin Deactivation Survey', 'wp-module-deactivation' ), |
29 | 'surveyTitle' => sprintf( |
30 | __( 'Thank you for using the %s plugin!', 'wp-module-deactivation' ), |
31 | ucwords( container()->plugin()->id ) |
32 | ), |
33 | 'surveyDesc' => __( 'Please take a moment to let us know why you\'re deactivating this plugin.', 'wp-module-deactivation' ), |
34 | 'formAriaLabel' => __( 'Plugin Deactivation Form', 'wp-module-deactivation' ), |
35 | 'label' => __( 'Why are you deactivating this plugin?', 'wp-module-deactivation' ), |
36 | 'placeholder' => __( 'Please share the reason here...', 'wp-module-deactivation' ), |
37 | 'submit' => __( 'Submit & Deactivate', 'wp-module-deactivation' ), |
38 | 'submitAriaLabel' => __( 'Submit and Deactivate Plugin', 'wp-module-deactivation' ), |
39 | 'cancel' => __( 'Cancel', 'wp-module-deactivation' ), |
40 | 'cancelAriaLabel' => __( 'Cancel Deactivation', 'wp-module-deactivation' ), |
41 | 'skip' => __( 'Skip & Deactivate', 'wp-module-deactivation' ), |
42 | 'skipAriaLabel' => __( 'Skip and Deactivate Plugin', 'wp-module-deactivation' ), |
43 | 'continue' => __( 'Continue', 'wp-module-deactivation' ), |
44 | 'continueAriaLabel' => __( 'Continue Deactivation', 'wp-module-deactivation' ), |
45 | 'sureTitle' => __( 'Are you sure you want to deactivate?', 'wp-module-deactivation' ), |
46 | 'deactivating' => __( 'Deactivating', 'wp-module-deactivation' ), |
47 | 'sureDesc' => sprintf( |
48 | __( 'If the %s plugin is deactivated, these features will no longer work:', 'wp-module-deactivation' ), |
49 | ucwords( container()->plugin()->id ) |
50 | ), |
51 | 'sureCards' => array( |
52 | array( |
53 | 'title' => sprintf( |
54 | __( '%s Caching', 'wp-module-deactivation' ), |
55 | ucwords( container()->plugin()->id ) |
56 | ), |
57 | 'desc' => __( 'Automatically clears the server page cache when your site updates', 'wp-module-deactivation' ), |
58 | 'condition' => 'window.NewfoldFeatures.features.performance', |
59 | ), |
60 | array( |
61 | 'title' => sprintf( |
62 | __( '%s Staging', 'wp-module-deactivation' ), |
63 | ucwords( container()->plugin()->id ) |
64 | ), |
65 | 'desc' => __( 'Create a staging copy of your site to safely test changes', 'wp-module-deactivation' ), |
66 | 'condition' => 'window.NewfoldFeatures.features.staging', |
67 | ), |
68 | array( |
69 | 'title' => __( 'WooCommerce Tools', 'wp-module-deactivation' ), |
70 | 'desc' => __( 'Run campaigns and promotions on your store', 'wp-module-deactivation' ), |
71 | 'condition' => 'window.NewfoldRuntime.isWoocommerceActive', |
72 | ), |
73 | array( |
74 | 'title' => __( 'Wonder Blocks & Patterns Library', 'wp-module-deactivation' ), |
75 | 'desc' => __( 'Dozens of beautiful block templates and patterns', 'wp-module-deactivation' ), |
76 | 'condition' => 'window.NewfoldFeatures.features.patterns', |
77 | ), |
78 | ), |
79 | 'sureHelp' => sprintf( |
80 | __( 'Need Help? Check the %1$shelp center%2$s for support.', 'wp-module-deactivation' ), |
81 | '<a href="/wp-admin/admin.php?page=' . container()->plugin()->id . '#/help">', |
82 | '</a>' |
83 | ), |
84 | ); |
85 | |
86 | // Merge defaults with container values from plugin |
87 | // $this->strings = wp_parse_args( |
88 | // $this->container->has( 'deactivation' ) ? |
89 | // $this->container['deactivation'] : |
90 | // array(), |
91 | // $defaults |
92 | // ); |
93 | $this->strings = $defaults; |
94 | |
95 | $this->deactivation_survey_assets(); |
96 | $this->deactivation_survey_runtime(); |
97 | } |
98 | |
99 | /** |
100 | * Enqueue deactivation survey assets. |
101 | */ |
102 | public function deactivation_survey_assets() { |
103 | $assets_dir = container()->plugin()->url . 'vendor/newfold-labs/wp-module-deactivation/static/'; |
104 | |
105 | // Accessible a11y dialog. |
106 | wp_register_script( |
107 | 'nfd-deactivation-a11y-dialog', |
108 | $assets_dir . 'js/a11y-dialog.min.js', |
109 | array(), |
110 | '8.0.4' |
111 | ); |
112 | |
113 | // Deactivation-survey.js. |
114 | wp_enqueue_script( |
115 | 'nfd-deactivation-survey', |
116 | $assets_dir . 'js/deactivation-survey.js', |
117 | array( 'newfold-features', 'nfd-deactivation-a11y-dialog' ), |
118 | container()->plugin()->version, |
119 | true |
120 | ); |
121 | |
122 | // Styles. |
123 | wp_enqueue_style( |
124 | 'nfd-deactivation-survey-style', |
125 | $assets_dir . 'css/deactivation-survey.css', |
126 | array(), |
127 | container()->plugin()->version |
128 | ); |
129 | } |
130 | |
131 | /** |
132 | * Localize deactivation survey runtime. |
133 | */ |
134 | public function deactivation_survey_runtime() { |
135 | $plugin_slug = explode( '/', container()->plugin()->basename )[0]; |
136 | |
137 | // Validate strings->cards via condition |
138 | |
139 | wp_localize_script( |
140 | 'nfd-deactivation-survey', |
141 | 'newfoldDeactivationSurvey', |
142 | array( |
143 | 'eventsEndpoint' => \esc_url_raw( \rest_url() . 'newfold-data/v1/events/' ), |
144 | 'restApiNonce' => wp_create_nonce( 'wp_rest' ), |
145 | 'brand' => container()->plugin()->id, |
146 | 'pluginSlug' => $plugin_slug, |
147 | 'strings' => $this->strings, |
148 | ) |
149 | ); |
150 | } |
151 | } |