PluginProbe
PDF & Print by BestWebSoft – WordPress Posts and Pages PDF Generator Plugin / trunk
PDF & Print by BestWebSoft – WordPress Posts and Pages PDF Generator Plugin vtrunk
trunk 1.5 1.6 1.7 1.7.1 1.7.2 1.7.3 1.7.4 1.7.5 1.7.6 1.7.7 1.7.8 1.7.9 1.8.0 1.8.1 1.8.2 1.8.3 1.8.4 1.8.5 1.8.6 1.8.7 1.8.8 1.8.9 1.9.0 1.9.1 All 71 releases
pdf-print / bws_menu / deactivation-form.php

deactivation-form.php in PDF & Print by BestWebSoft – WordPress Posts and Pages PDF Generator Plugin trunk, at bws_menu/deactivation-form.php

434 lines 15.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Displays the content of the dialog box when the user clicks on the "Deactivate" link on the plugin settings page
4 *
5 * @package BestWebSoft
6 * @since 2.1.3
7 */
8
9 if ( ! defined( 'ABSPATH' ) ) {
10 exit;
11 }
12
13 if ( ! function_exists( 'bws_add_deactivation_feedback_dialog_box' ) ) {
14 /**
15 * Displays a confirmation and feedback dialog box when the user clicks on the "Deactivate" link on the plugins
16 * page.
17 *
18 * @since 2.1.3
19 */
20 function bws_add_deactivation_feedback_dialog_box() {
21 global $bstwbsftwppdtplgns_active_plugins;
22 if ( empty( $bstwbsftwppdtplgns_active_plugins ) ) {
23 return;
24 }
25
26 $contact_support_template = __( 'Need help? We are ready to answer your questions.', 'bestwebsoft' ) . ' <a href="https://support.bestwebsoft.com/hc/en-us/requests/new" target="_blank">' . __( 'Contact Support', 'bestwebsoft' ) . '</a>';
27
28 $reasons = array(
29 array(
30 'id' => 'NOT_WORKING',
31 'text' => __( 'The plugin is not working', 'bestwebsoft' ),
32 'input_type' => 'textarea',
33 'input_placeholder' => __( "Kindly share what didn't work so we can fix it in future updates...", 'bestwebsoft' ),
34 ),
35 array(
36 'id' => 'DIDNT_WORK_AS_EXPECTED',
37 'text' => __( "The plugin didn't work as expected", 'bestwebsoft' ),
38 'input_type' => 'textarea',
39 'input_placeholder' => __( 'What did you expect?', 'bestwebsoft' ),
40 ),
41 array(
42 'id' => 'SUDDENLY_STOPPED_WORKING',
43 'text' => __( 'The plugin suddenly stopped working', 'bestwebsoft' ),
44 'input_type' => '',
45 'input_placeholder' => '',
46 'internal_message' => $contact_support_template,
47 ),
48 array(
49 'id' => 'BROKE_MY_SITE',
50 'text' => __( 'The plugin broke my site', 'bestwebsoft' ),
51 'input_type' => '',
52 'input_placeholder' => '',
53 'internal_message' => $contact_support_template,
54 ),
55 array(
56 'id' => 'COULDNT_MAKE_IT_WORK',
57 'text' => __( "I couldn't understand how to get it work", 'bestwebsoft' ),
58 'input_type' => '',
59 'input_placeholder' => '',
60 'internal_message' => $contact_support_template,
61 ),
62 array(
63 'id' => 'FOUND_A_BETTER_PLUGIN',
64 'text' => __( 'I found a better plugin', 'bestwebsoft' ),
65 'input_type' => 'textfield',
66 'input_placeholder' => __( "What's the plugin name?", 'bestwebsoft' ),
67 ),
68 array(
69 'id' => 'GREAT_BUT_NEED_SPECIFIC_FEATURE',
70 'text' => __( "The plugin is great, but I need specific feature that you don't support", 'bestwebsoft' ),
71 'input_type' => 'textarea',
72 'input_placeholder' => __( 'What feature?', 'bestwebsoft' ),
73 ),
74 array(
75 'id' => 'NO_LONGER_NEEDED',
76 'text' => __( 'I no longer need the plugin', 'bestwebsoft' ),
77 'input_type' => '',
78 'input_placeholder' => '',
79 ),
80 array(
81 'id' => 'TEMPORARY_DEACTIVATION',
82 'text' => __( "It's a temporary deactivation, I'm just debugging an issue", 'bestwebsoft' ),
83 'input_type' => '',
84 'input_placeholder' => '',
85 ),
86 array(
87 'id' => 'OTHER',
88 'text' => __( 'Other', 'bestwebsoft' ),
89 'input_type' => 'textfield',
90 'input_placeholder' => '',
91 ),
92 );
93
94 $modal_html = '<div class="bws-modal bws-modal-deactivation-feedback">
95 <div class="bws-modal-dialog">
96 <div class="bws-modal-body">
97 <h2>' . __( 'Quick Feedback', 'bestwebsoft' ) . '</h2>
98 <div class="bws-modal-panel active">
99 <p>' . __( 'If you have a moment, please let us know why you are deactivating', 'bestwebsoft' ) . ':</p><ul>';
100
101 foreach ( $reasons as $reason ) {
102 $list_item_classes = 'bws-modal-reason' . ( ! empty( $reason['input_type'] ) ? ' has-input' : '' );
103
104 if ( ! empty( $reason['internal_message'] ) ) {
105 $list_item_classes .= ' has-internal-message';
106 $reason_internal_message = $reason['internal_message'];
107 } else {
108 $reason_internal_message = '';
109 }
110
111 $modal_html .= '<li class="' . $list_item_classes . '" data-input-type="' . $reason['input_type'] . '" data-input-placeholder="' . $reason['input_placeholder'] . '">
112 <label>
113 <span>
114 <input type="radio" name="selected-reason" value="' . $reason['id'] . '"/>
115 </span>
116 <span>' . $reason['text'] . '</span>
117 </label>
118 <div class="bws-modal-internal-message">' . $reason_internal_message . '</div>
119 </li>';
120 }
121 $modal_html .= '</ul>
122 <label class="bws-modal-anonymous-label">
123 <input type="checkbox" />' .
124 __( 'Send website data and allow to contact me back', 'bestwebsoft' ) .
125 '</label>
126 </div>
127 </div>
128 <div class="bws-modal-footer">
129 <a href="#" class="button button-primary bws-modal-button-deactivate disabled">' . __( 'Submit and Deactivate', 'bestwebsoft' ) . '</a>
130 <a href="#" class="bws-modal-skip-link">' . __( 'Skip and Deactivate', 'bestwebsoft' ) . '</a>
131 <span class="bws-modal-processing hidden">' . __( 'Processing', 'bestwebsoft' ) . '...</span>
132 <div class="clear"></div>
133 </div>
134 </div>
135 </div>';
136
137 $script = '';
138
139 foreach ( $bstwbsftwppdtplgns_active_plugins as $basename => $plugin_data ) {
140
141 $slug = dirname( $basename );
142 $plugin_id = sanitize_title( $plugin_data['Name'] );
143
144 $script .= "(function($) {
145 var modalHtml = " . wp_json_encode( $modal_html ) . ",
146 \$modal = $( modalHtml ),
147 \$deactivateLink = $( '#the-list .active[data-plugin=\"" . $basename . "\"] .deactivate a' ),
148 \$anonymousFeedback = \$modal.find( '.bws-modal-anonymous-label' ),
149 selectedReasonID = false;
150
151 /* WP added data-plugin attr after 4.5 version/ In prev version was id attr */
152 if ( 0 == \$deactivateLink.length )
153 \$deactivateLink = $( '#the-list .active#" . $plugin_id . " .deactivate a' );
154
155 \$modal.appendTo( $( 'body' ) );
156
157 BwsModalRegisterEventHandlers();
158
159 function BwsModalRegisterEventHandlers() {
160 \$deactivateLink.click( function( evt ) {
161 evt.preventDefault();
162
163 /* Display the dialog box.*/
164 BwsModalReset();
165 \$modal.addClass( 'active' );
166 $( 'body' ).addClass( 'has-bws-modal' );
167 });
168
169 \$modal.on( 'input propertychange', '.bws-modal-reason-input input', function() {
170 if ( ! BwsModalIsReasonSelected( 'OTHER' ) ) {
171 return;
172 }
173
174 var reason = $( this ).val().trim();
175
176 /* If reason is not empty, remove the error-message class of the message container to change the message color back to default. */
177 if ( reason.length > 0 ) {
178 \$modal.find( '.message' ).removeClass( 'error-message' );
179 BwsModalEnableDeactivateButton();
180 }
181 });
182
183 \$modal.on( 'blur', '.bws-modal-reason-input input', function() {
184 var \$userReason = $( this );
185
186 setTimeout( function() {
187 if ( ! BwsModalIsReasonSelected( 'OTHER' ) ) {
188 return;
189 }
190 }, 150 );
191 });
192
193 \$modal.on( 'click', '.bws-modal-footer .bws-modal-skip-link', function( evt ) {
194 evt.preventDefault();
195
196 /* If no selected reason, just deactivate the plugin. */
197 window.location.href = \$deactivateLink.attr( 'href' );
198 return;
199 });
200
201 \$modal.on( 'click', '.bws-modal-footer .button', function( evt ) {
202 evt.preventDefault();
203
204 if ( $( this ).hasClass( 'disabled' ) ) {
205 return;
206 }
207
208 var _parent = $( this ).parents( '.bws-modal:first' ),
209 _this = $( this );
210
211 var \$radio = \$modal.find( 'input[type=\"radio\"]:checked' );
212
213 if ( 0 === \$radio.length ) {
214 /* If no selected reason */
215 BwsModalDisableDeactivateButton();
216 return;
217 }
218
219 var \$selected_reason = \$radio.parents( 'li:first' ),
220 \$input = \$selected_reason.find( 'textarea, input[type=\"text\"]' ),
221 userReason = ( 0 !== \$input.length ) ? \$input.val().trim() : '';
222
223 var is_anonymous = ( \$anonymousFeedback.find( 'input' ).is( ':checked' ) ) ? 0 : 1;
224
225 $.ajax({
226 url : ajaxurl,
227 method : 'POST',
228 data : {
229 'action' : 'bws_submit_uninstall_reason_action',
230 'plugin' : '" . $basename . "',
231 'reason_id' : \$radio.val(),
232 'reason_info' : userReason,
233 'is_anonymous' : is_anonymous,
234 'bws_ajax_nonce' : '" . wp_create_nonce( 'bws_ajax_nonce' ) . "'
235 },
236 beforeSend: function() {
237 _parent.find( '.bws-modal-footer .button' ).hide();
238 _parent.find( '.bws-modal-footer .bws-modal-processing' ).show();
239 },
240 complete : function( message ) {
241 /* Do not show the dialog box, deactivate the plugin. */
242 window.location.href = \$deactivateLink.attr( 'href' );
243 }
244 });
245 });
246
247 \$modal.on( 'click', 'input[type=\"radio\"]', function() {
248 var \$selectedReasonOption = $( this );
249
250 /* If the selection has not changed, do not proceed. */
251 if ( selectedReasonID === \$selectedReasonOption.val() )
252 return;
253
254 selectedReasonID = \$selectedReasonOption.val();
255
256 \$anonymousFeedback.show();
257
258 var _parent = $( this ).parents( 'li:first' );
259
260 \$modal.find( '.bws-modal-reason-input' ).remove();
261 \$modal.find( '.bws-modal-internal-message' ).hide();
262
263 BwsModalEnableDeactivateButton();
264
265 if ( _parent.hasClass( 'has-internal-message' ) ) {
266 _parent.find( '.bws-modal-internal-message' ).show();
267 }
268
269 if (_parent.hasClass('has-input')) {
270 var reasonInputHtml = '<div class=\"bws-modal-reason-input\"><span class=\"message\"></span>' + ( ( 'textfield' === _parent.data( 'input-type' ) ) ? '<input type=\"text\" />' : '<textarea rows=\"5\" maxlength=\"200\"></textarea>' ) + '</div>';
271
272 _parent.append( $( reasonInputHtml ) );
273 _parent.find( 'input, textarea' ).attr( 'placeholder', _parent.data( 'input-placeholder' ) ).focus();
274
275 if ( BwsModalIsReasonSelected( 'OTHER' ) ) {
276 \$modal.find( '.message' ).text( '" . esc_html__( 'Please tell us the reason so we can improve it.', 'bestwebsoft' ) . "' ).show();
277 }
278 }
279 });
280
281 /* If the user has clicked outside the window, cancel it. */
282 \$modal.on( 'click', function( evt ) {
283 var \$target = $( evt.target );
284
285 /* If the user has clicked anywhere in the modal dialog, just return. */
286 if ( \$target.hasClass( 'bws-modal-body' ) || \$target.hasClass( 'bws-modal-footer' ) ) {
287 return;
288 }
289
290 /* If the user has not clicked the close button and the clicked element is inside the modal dialog, just return. */
291 if ( ! \$target.hasClass( 'bws-modal-button-close' ) && ( \$target.parents( '.bws-modal-body' ).length > 0 || \$target.parents( '.bws-modal-footer' ).length > 0 ) ) {
292 return;
293 }
294
295 /* Close the modal dialog */
296 \$modal.removeClass( 'active' );
297 $( 'body' ).removeClass( 'has-bws-modal' );
298
299 return false;
300 });
301 }
302
303 function BwsModalIsReasonSelected( reasonID ) {
304 /* Get the selected radio input element.*/
305 return ( reasonID == \$modal.find('input[type=\"radio\"]:checked').val() );
306 }
307
308 function BwsModalReset() {
309 selectedReasonID = false;
310
311 /* Uncheck all radio buttons.*/
312 \$modal.find( 'input[type=\"radio\"]' ).prop( 'checked', false );
313
314 /* Remove all input fields ( textfield, textarea ).*/
315 \$modal.find( '.bws-modal-reason-input' ).remove();
316
317 \$modal.find( '.message' ).hide();
318
319 /* Hide, since by default there is no selected reason.*/
320 \$anonymousFeedback.hide();
321
322 BwsModalDisableDeactivateButton();
323
324 BwsModalShowPanel();
325 }
326
327 function BwsModalEnableDeactivateButton() {
328 \$modal.find( '.bws-modal-button-deactivate' ).removeClass( 'disabled' ).show();
329 \$modal.find( '.bws-modal-processing' ).hide();
330 }
331
332 function BwsModalDisableDeactivateButton() {
333 \$modal.find( '.bws-modal-button-deactivate' ).addClass( 'disabled' );
334 }
335
336 function BwsModalShowPanel() {
337 \$modal.find( '.bws-modal-panel' ).addClass( 'active' );
338 }
339 })(jQuery);";
340 }
341
342 /* add script in FOOTER */
343 wp_register_script( 'bws-deactivation-feedback-dialog-boxes', '', array( 'jquery' ), false, true );
344 wp_enqueue_script( 'bws-deactivation-feedback-dialog-boxes' );
345 wp_add_inline_script( 'bws-deactivation-feedback-dialog-boxes', $script );
346 }
347 }
348
349 if ( ! function_exists( 'bws_submit_uninstall_reason_action' ) ) {
350 /**
351 * Called after the user has submitted his reason for deactivating the plugin.
352 *
353 * @since 2.1.3
354 */
355 function bws_submit_uninstall_reason_action() {
356 global $bstwbsftwppdtplgns_options, $wp_version, $bstwbsftwppdtplgns_active_plugins, $current_user;
357
358 if ( isset( $_REQUEST['bws_ajax_nonce'] ) ) {
359
360 check_ajax_referer( 'bws_ajax_nonce', sanitize_text_field( wp_unslash( $_REQUEST['bws_ajax_nonce'] ) ) );
361
362 $reason_id = isset( $_REQUEST['reason_id'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['reason_id'] ) ) : '';
363 $basename = isset( $_REQUEST['plugin'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['plugin'] ) ) : '';
364
365 if ( empty( $reason_id ) || empty( $basename ) ) {
366 exit;
367 }
368
369 $reason_info = isset( $_REQUEST['reason_info'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['reason_info'] ) ) : '';
370 if ( ! empty( $reason_info ) ) {
371 $reason_info = substr( $reason_info, 0, 255 );
372 }
373 $is_anonymous = isset( $_REQUEST['is_anonymous'] ) && 1 === intval( $_REQUEST['is_anonymous'] );
374
375 $options = array(
376 'product' => $basename,
377 'reason_id' => $reason_id,
378 'reason_info' => $reason_info,
379 );
380
381 if ( ! $is_anonymous ) {
382 if ( ! isset( $bstwbsftwppdtplgns_options ) ) {
383 $bstwbsftwppdtplgns_options = ( is_multisite() ) ? get_site_option( 'bstwbsftwppdtplgns_options' ) : get_option( 'bstwbsftwppdtplgns_options' );
384 }
385
386 if ( ! empty( $bstwbsftwppdtplgns_options['track_usage']['usage_id'] ) ) {
387 $options['usage_id'] = $bstwbsftwppdtplgns_options['track_usage']['usage_id'];
388 } else {
389 $options['usage_id'] = false;
390 $options['url'] = get_bloginfo( 'url' );
391 $options['wp_version'] = $wp_version;
392 $options['is_active'] = false;
393 $options['version'] = $bstwbsftwppdtplgns_active_plugins[ $basename ]['Version'];
394 }
395
396 $options['email'] = $current_user->data->user_email;
397 }
398
399 /* send data */
400 $raw_response = wp_remote_post(
401 'https://bestwebsoft.com/wp-content/plugins/products-statistics/deactivation-feedback/',
402 array(
403 'method' => 'POST',
404 'body' => $options,
405 'timeout' => 15,
406 )
407 );
408
409 if ( ! is_wp_error( $raw_response ) && 200 === intval( wp_remote_retrieve_response_code( $raw_response ) ) ) {
410 if ( ! $is_anonymous ) {
411 $response = maybe_unserialize( wp_remote_retrieve_body( $raw_response ) );
412
413 if ( is_array( $response ) && ! empty( $response['usage_id'] ) && $response['usage_id'] !== $options['usage_id'] ) {
414 $bstwbsftwppdtplgns_options['track_usage']['usage_id'] = $response['usage_id'];
415
416 if ( is_multisite() ) {
417 update_site_option( 'bstwbsftwppdtplgns_options', $bstwbsftwppdtplgns_options );
418 } else {
419 update_option( 'bstwbsftwppdtplgns_options', $bstwbsftwppdtplgns_options );
420 }
421 }
422 }
423
424 echo 'done';
425 } else {
426 echo wp_kses_data( $response->get_error_code() ) . ': ' . wp_kses_data( $response->get_error_message() );
427 }
428 }
429 exit;
430 }
431 }
432
433 add_action( 'wp_ajax_bws_submit_uninstall_reason_action', 'bws_submit_uninstall_reason_action' );
434