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