PluginProbe
Master Addons for Elementor – Elementor Addons, Widgets, Mega Menu Builder, Popup Builder, Widget Builder & Template Kits / trunk
Master Addons for Elementor – Elementor Addons, Widgets, Mega Menu Builder, Popup Builder, Widget Builder & Template Kits vtrunk
3.2.2 3.2.3 3.2.1 3.2.0 3.1.9 3.1.8 3.1.7 3.1.6 3.1.5 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 3.0.9 trunk 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 1.1.3 1.1.4 1.1.5 All 174 releases
master-addons / inc / classes / feedback.php

feedback.php in Master Addons for Elementor – Elementor Addons, Widgets, Mega Menu Builder, Popup Builder, Widget Builder & Template Kits trunk, at inc/classes/feedback.php

262 lines 10.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace MasterAddons\Inc\Classes;
4
5 use MasterAddons\Inc\Classes\Notifications\Base\User_Data;
6
7 // No, Direct access Sir !!!
8 if (!defined('ABSPATH')) {
9 exit;
10 }
11
12 // Load the User_Data trait with a case-exact path. The class autoloader
13 // lowercases namespace paths, which breaks on case-sensitive (Linux) servers
14 // if the folder casing ever differs. Requiring it here removes that dependency.
15 if (!trait_exists('MasterAddons\Inc\Classes\Notifications\Base\User_Data', false)) {
16 require_once __DIR__ . '/notifications/base/user-data.php';
17 }
18
19 /**
20 * Feedback
21 *
22 * @author Jewel Theme <support@jeweltheme.com>
23 */
24 if (!class_exists('MasterAddons\Inc\Classes\Feedback')) {
25 class Feedback
26 {
27
28 use User_Data;
29
30 /**
31 * Construct Method
32 *
33 * @return void
34 * @author Jewel Theme <support@jeweltheme.com>
35 */
36 public function __construct()
37 {
38 add_action('admin_enqueue_scripts', [$this, 'admin_suvery_scripts']);
39 add_action('admin_footer', [$this, 'deactivation_footer']);
40 add_action('wp_ajax_jltma_deactivation_survey', array($this, 'jltma_deactivation_survey'));
41 }
42
43
44 public function proceed()
45 {
46
47 global $current_screen;
48 if (
49 isset($current_screen->parent_file)
50 && $current_screen->parent_file == 'plugins.php'
51 && isset($current_screen->id)
52 && $current_screen->id == 'plugins'
53 ) {
54 return true;
55 }
56 return false;
57 }
58
59 public function admin_suvery_scripts($handle)
60 {
61 if ('plugins.php' === $handle) {
62 wp_enqueue_style('jltma-survey', JLTMA_ASSETS . 'css/plugin-survey.css', array(), JLTMA_VER);
63 }
64 }
65
66 /**
67 * Deactivation Survey
68 */
69 public function jltma_deactivation_survey()
70 {
71 check_ajax_referer('jltma_deactivation_nonce');
72
73 if ( ! current_user_can( 'deactivate_plugins' ) ) {
74 wp_send_json_error( [ 'message' => __( 'Insufficient permissions', 'master-addons' ) ] );
75 }
76
77 $deactivation_reason = !empty($_POST['deactivation_reason']) ? sanitize_text_field(wp_unslash($_POST['deactivation_reason'])) : '';
78
79 if (empty($deactivation_reason)) {
80 return;
81 }
82
83 $email = get_bloginfo('admin_email');
84 $author_obj = get_user_by('email', $email);
85 $user_id = $author_obj->ID;
86 $full_name = $author_obj->display_name;
87
88 $response = $this->get_collect_data($user_id, array(
89 'first_name' => $full_name,
90 'email' => $email,
91 'deactivation_reason' => $deactivation_reason,
92 ));
93
94 return $response;
95 }
96
97
98 public function get_survey_questions()
99 {
100
101 return [
102 'no_longer_needed' => [
103 'title' => esc_html__('I no longer need the plugin', 'master-addons'),
104 'input_placeholder' => '',
105 ],
106 'found_a_better_plugin' => [
107 'title' => esc_html__('I found a better plugin', 'master-addons'),
108 'input_placeholder' => esc_html__('Please share which plugin', 'master-addons'),
109 ],
110 'couldnt_get_the_plugin_to_work' => [
111 'title' => esc_html__('I couldn\'t get the plugin to work', 'master-addons'),
112 'input_placeholder' => '',
113 ],
114 'temporary_deactivation' => [
115 'title' => esc_html__('It\'s a temporary deactivation', 'master-addons'),
116 'input_placeholder' => '',
117 ],
118 'jltma_pro' => [
119 /* translators: %1$s: Plugin name (e.g. Master Addons). */
120 'title' => sprintf(esc_html__('I have %1$s Pro', 'master-addons'), JLTMA),
121 'input_placeholder' => '',
122 /* translators: %1$s: Plugin name (e.g. Master Addons). */
123 'alert' => sprintf(esc_html__('Wait! Don\'t deactivate %1$s. You have to activate both %1$s and %1$s Pro in order for the plugin to work.', 'master-addons'), JLTMA),
124 ],
125 'need_better_design' => [
126 'title' => esc_html__('I need better design and presets', 'master-addons'),
127 'input_placeholder' => esc_html__('Let us know your thoughts', 'master-addons'),
128 ],
129 'other' => [
130 'title' => esc_html__('Other', 'master-addons'),
131 'input_placeholder' => esc_html__('Please share the reason', 'master-addons'),
132 ],
133 ];
134 }
135
136
137 /**
138 * Deactivation Footer
139 */
140 public function deactivation_footer()
141 {
142
143 if (!$this->proceed()) {
144 return;
145 }
146
147 ?>
148 <div class="jltma-deactivate-survey-overlay" id="jltma-deactivate-survey-overlay"></div>
149 <div class="jltma-deactivate-survey-modal" id="jltma-deactivate-survey-modal">
150 <header>
151 <div class="jltma-deactivate-survey-header">
152 <img src="<?php echo esc_url(JLTMA_IMAGE_DIR . 'logo.png'); ?>" />
153 <h3><?php echo wp_sprintf('%1$s %2$s', esc_html(JLTMA), esc_html__('- Feedback', 'master-addons')); ?></h3>
154 </div>
155 </header>
156 <div class="jltma-deactivate-info">
157 <?php echo wp_sprintf('%1$s %2$s', esc_html__('If you have a moment, please share why you are deactivating', 'master-addons'), esc_html(JLTMA)); ?>
158 </div>
159 <div class="jltma-deactivate-content-wrapper">
160 <form action="#" class="jltma-deactivate-form-wrapper">
161 <?php foreach ($this->get_survey_questions() as $reason_key => $reason) { ?>
162 <div class="jltma-deactivate-input-wrapper">
163 <input id="jltma-deactivate-feedback-<?php echo esc_attr($reason_key); ?>" class="jltma-deactivate-feedback-dialog-input" type="radio" name="reason_key" value="<?php echo esc_attr($reason_key); ?>">
164 <label for="jltma-deactivate-feedback-<?php echo esc_attr($reason_key); ?>" class="jltma-deactivate-feedback-dialog-label"><?php echo esc_html($reason['title']); ?></label>
165 <?php if (!empty($reason['input_placeholder'])) : ?>
166 <input class="jltma-deactivate-feedback-text" type="text" name="reason_<?php echo esc_attr($reason_key); ?>" placeholder="<?php echo esc_attr($reason['input_placeholder']); ?>" />
167 <?php endif; ?>
168 </div>
169 <?php } ?>
170 <div class="jltma-deactivate-footer">
171 <button id="jltma-dialog-lightbox-submit" class="jltma-dialog-lightbox-submit"><?php echo esc_html__('Submit &amp; Deactivate', 'master-addons'); ?></button>
172 <button id="jltma-dialog-lightbox-skip" class="jltma-dialog-lightbox-skip"><?php echo esc_html__('Skip & Deactivate', 'master-addons'); ?></button>
173 </div>
174 </form>
175 </div>
176 </div>
177
178 <script>
179 var deactivate_url = '#';
180
181 jQuery(document).on('click', '#deactivate-master-addons', function(e) {
182 e.preventDefault();
183 deactivate_url = e.target.href;
184 jQuery('#jltma-deactivate-survey-overlay').addClass('jltma-deactivate-survey-is-visible');
185 jQuery('#jltma-deactivate-survey-modal').addClass('jltma-deactivate-survey-is-visible');
186 });
187
188 jQuery('#jltma-dialog-lightbox-skip').on('click', function(e) {
189 e.preventDefault();
190 window.location.replace(deactivate_url);
191 });
192
193
194 jQuery(document).on('click', '#jltma-dialog-lightbox-submit', async function(e) {
195 e.preventDefault();
196
197 jQuery('#jltma-dialog-lightbox-submit').addClass('jltma-loading');
198
199 var $dialogModal = jQuery('.jltma-deactivate-input-wrapper'),
200 radioSelector = '.jltma-deactivate-feedback-dialog-input';
201 $dialogModal.find(radioSelector).on('change', function() {
202 $dialogModal.attr('data-feedback-selected', jQuery(this).val());
203 });
204 $dialogModal.find(radioSelector + ':checked').trigger('change');
205
206
207 // Reasons for deactivation
208 var deactivation_reason = '';
209 var reasonData = jQuery('.jltma-deactivate-form-wrapper').serializeArray();
210
211 jQuery.each(reasonData, function(reason_index, reason_value) {
212 if ('reason_key' == reason_value.name && reason_value.value != '') {
213 const reason_input_id = '#jltma-deactivate-feedback-' + reason_value.value,
214 reason_title = jQuery(reason_input_id).siblings('label').text(),
215 reason_placeholder_input = jQuery(reason_input_id).siblings('input').val(),
216 format_title_with_key = reason_value.value + ' - ' + reason_placeholder_input,
217 format_title = reason_title + ' - ' + reason_placeholder_input;
218
219 deactivation_reason = reason_value.value;
220
221 if ('found_a_better_plugin' == reason_value.value) {
222 deactivation_reason = format_title_with_key;
223 }
224
225 if ('need_better_design' == reason_value.value) {
226 deactivation_reason = format_title_with_key;
227 }
228
229 if ('other' == reason_value.value) {
230 deactivation_reason = format_title_with_key;
231 }
232 }
233 });
234
235 await jQuery.ajax({
236 url: '<?php echo esc_url(admin_url('admin-ajax.php')); ?>',
237 method: 'POST',
238 // crossDomain: true,
239 async: true,
240 // dataType: 'jsonp',
241 data: {
242 action: 'jltma_deactivation_survey',
243 _wpnonce: '<?php echo esc_js(wp_create_nonce('jltma_deactivation_nonce')); ?>',
244 deactivation_reason: deactivation_reason
245 },
246 success: function(response) {
247 window.location.replace(deactivate_url);
248 }
249 });
250 return true;
251 });
252
253 jQuery('#jltma-deactivate-survey-overlay').on('click', function() {
254 jQuery('#jltma-deactivate-survey-overlay').removeClass('jltma-deactivate-survey-is-visible');
255 jQuery('#jltma-deactivate-survey-modal').removeClass('jltma-deactivate-survey-is-visible');
256 });
257 </script>
258 <?php
259 }
260 } // End class Feedback
261 } // End class_exists check
262