PluginProbe
Adminify – White Label, Admin Menu Editor, Login Customizer / 4.3.0
Adminify – White Label, Admin Menu Editor, Login Customizer v4.3.0
4.3.1 4.3.0 4.2.26 4.2.25 4.2.24 4.2.23 4.2.22 4.2.21 4.2.20 4.2.19 4.2.18 4.2.17 4.2.16 4.2.15 4.2.14 4.2.13 4.2.12 4.2.11 4.2.10 4.2.9 4.2.8 4.2.7 4.2.6 4.2.5 4.1.17 All 164 releases
adminify / Inc / Classes / Feedback.php

Feedback.php in Adminify – White Label, Admin Menu Editor, Login Customizer 4.3.0, at Inc/Classes/Feedback.php

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