author | ymh <ymh.work@gmail.com> |
Mon, 08 Sep 2025 19:44:41 +0200 | |
changeset 23 | 417f20492bf7 |
parent 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 |
*/ |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8 |
|
19 | 9 |
if ( ! defined( 'ABSPATH' ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
10 |
exit; |
19 | 11 |
} |
7
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 |
if ( ! function_exists( 'bws_add_deactivation_feedback_dialog_box' ) ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
14 |
/** |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
15 |
* Displays a confirmation and feedback dialog box when the user clicks on the "Deactivate" link on the plugins |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
16 |
* page. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
17 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
18 |
* @since 2.1.3 |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
19 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
20 |
function bws_add_deactivation_feedback_dialog_box() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
21 |
global $bstwbsftwppdtplgns_active_plugins; |
19 | 22 |
if ( empty( $bstwbsftwppdtplgns_active_plugins ) ) { |
23 |
return; |
|
24 |
} |
|
16 | 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', |
|
19 | 33 |
'input_placeholder' => __( "Kindly share what didn't work so we can fix it in future updates...", 'bestwebsoft' ), |
16 | 34 |
), |
35 |
array( |
|
36 |
'id' => 'DIDNT_WORK_AS_EXPECTED', |
|
37 |
'text' => __( "The plugin didn't work as expected", 'bestwebsoft' ), |
|
38 |
'input_type' => 'textarea', |
|
19 | 39 |
'input_placeholder' => __( 'What did you expect?', 'bestwebsoft' ), |
16 | 40 |
), |
41 |
array( |
|
42 |
'id' => 'SUDDENLY_STOPPED_WORKING', |
|
43 |
'text' => __( 'The plugin suddenly stopped working', 'bestwebsoft' ), |
|
44 |
'input_type' => '', |
|
45 |
'input_placeholder' => '', |
|
19 | 46 |
'internal_message' => $contact_support_template, |
16 | 47 |
), |
48 |
array( |
|
49 |
'id' => 'BROKE_MY_SITE', |
|
50 |
'text' => __( 'The plugin broke my site', 'bestwebsoft' ), |
|
51 |
'input_type' => '', |
|
52 |
'input_placeholder' => '', |
|
19 | 53 |
'internal_message' => $contact_support_template, |
16 | 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' => '', |
|
19 | 60 |
'internal_message' => $contact_support_template, |
16 | 61 |
), |
62 |
array( |
|
63 |
'id' => 'FOUND_A_BETTER_PLUGIN', |
|
64 |
'text' => __( 'I found a better plugin', 'bestwebsoft' ), |
|
65 |
'input_type' => 'textfield', |
|
19 | 66 |
'input_placeholder' => __( "What's the plugin name?", 'bestwebsoft' ), |
16 | 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', |
|
19 | 72 |
'input_placeholder' => __( 'What feature?', 'bestwebsoft' ), |
16 | 73 |
), |
74 |
array( |
|
75 |
'id' => 'NO_LONGER_NEEDED', |
|
76 |
'text' => __( 'I no longer need the plugin', 'bestwebsoft' ), |
|
77 |
'input_type' => '', |
|
19 | 78 |
'input_placeholder' => '', |
16 | 79 |
), |
80 |
array( |
|
81 |
'id' => 'TEMPORARY_DEACTIVATION', |
|
82 |
'text' => __( "It's a temporary deactivation, I'm just debugging an issue", 'bestwebsoft' ), |
|
83 |
'input_type' => '', |
|
19 | 84 |
'input_placeholder' => '', |
16 | 85 |
), |
86 |
array( |
|
87 |
'id' => 'OTHER', |
|
88 |
'text' => __( 'Other', 'bestwebsoft' ), |
|
89 |
'input_type' => 'textfield', |
|
19 | 90 |
'input_placeholder' => '', |
91 |
), |
|
16 | 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"> |
|
19 | 99 |
<p>' . __( 'If you have a moment, please let us know why you are deactivating', 'bestwebsoft' ) . ':</p><ul>'; |
16 | 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'] ) ) { |
|
19 | 105 |
$list_item_classes .= ' has-internal-message'; |
16 | 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 = ''; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
138 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
139 |
foreach ( $bstwbsftwppdtplgns_active_plugins as $basename => $plugin_data ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
140 |
|
19 | 141 |
$slug = dirname( $basename ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
142 |
$plugin_id = sanitize_title( $plugin_data['Name'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
143 |
|
16 | 144 |
$script .= "(function($) { |
19 | 145 |
var modalHtml = " . wp_json_encode( $modal_html ) . ", |
16 | 146 |
\$modal = $( modalHtml ), |
147 |
\$deactivateLink = $( '#the-list .active[data-plugin=\"" . $basename . "\"] .deactivate a' ), |
|
148 |
\$anonymousFeedback = \$modal.find( '.bws-modal-anonymous-label' ), |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
149 |
selectedReasonID = false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
150 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
151 |
/* WP added data-plugin attr after 4.5 version/ In prev version was id attr */ |
16 | 152 |
if ( 0 == \$deactivateLink.length ) |
153 |
\$deactivateLink = $( '#the-list .active#" . $plugin_id . " .deactivate a' ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
154 |
|
16 | 155 |
\$modal.appendTo( $( 'body' ) ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
156 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
157 |
BwsModalRegisterEventHandlers(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
158 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
159 |
function BwsModalRegisterEventHandlers() { |
16 | 160 |
\$deactivateLink.click( function( evt ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
161 |
evt.preventDefault(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
162 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
163 |
/* Display the dialog box.*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
164 |
BwsModalReset(); |
16 | 165 |
\$modal.addClass( 'active' ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
166 |
$( 'body' ).addClass( 'has-bws-modal' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
167 |
}); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
168 |
|
16 | 169 |
\$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
|
170 |
if ( ! BwsModalIsReasonSelected( 'OTHER' ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
171 |
return; |
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 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
174 |
var reason = $( this ).val().trim(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
175 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
176 |
/* 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
|
177 |
if ( reason.length > 0 ) { |
16 | 178 |
\$modal.find( '.message' ).removeClass( 'error-message' ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
179 |
BwsModalEnableDeactivateButton(); |
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 |
}); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
182 |
|
16 | 183 |
\$modal.on( 'blur', '.bws-modal-reason-input input', function() { |
184 |
var \$userReason = $( this ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
185 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
186 |
setTimeout( function() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
187 |
if ( ! BwsModalIsReasonSelected( 'OTHER' ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
188 |
return; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
189 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
190 |
}, 150 ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
191 |
}); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
192 |
|
16 | 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 ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
202 |
evt.preventDefault(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
203 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
204 |
if ( $( this ).hasClass( 'disabled' ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
205 |
return; |
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 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
208 |
var _parent = $( this ).parents( '.bws-modal:first' ), |
16 | 209 |
_this = $( this ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
210 |
|
16 | 211 |
var \$radio = \$modal.find( 'input[type=\"radio\"]:checked' ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
212 |
|
16 | 213 |
if ( 0 === \$radio.length ) { |
214 |
/* If no selected reason */ |
|
215 |
BwsModalDisableDeactivateButton(); |
|
216 |
return; |
|
217 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
218 |
|
16 | 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; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
224 |
|
16 | 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 |
}); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
245 |
}); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
246 |
|
16 | 247 |
\$modal.on( 'click', 'input[type=\"radio\"]', function() { |
248 |
var \$selectedReasonOption = $( this ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
249 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
250 |
/* If the selection has not changed, do not proceed. */ |
16 | 251 |
if ( selectedReasonID === \$selectedReasonOption.val() ) |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
252 |
return; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
253 |
|
16 | 254 |
selectedReasonID = \$selectedReasonOption.val(); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
255 |
|
16 | 256 |
\$anonymousFeedback.show(); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
257 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
258 |
var _parent = $( this ).parents( 'li:first' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
259 |
|
16 | 260 |
\$modal.find( '.bws-modal-reason-input' ).remove(); |
261 |
\$modal.find( '.bws-modal-internal-message' ).hide(); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
262 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
263 |
BwsModalEnableDeactivateButton(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
264 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
265 |
if ( _parent.hasClass( 'has-internal-message' ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
266 |
_parent.find( '.bws-modal-internal-message' ).show(); |
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 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
269 |
if (_parent.hasClass('has-input')) { |
16 | 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>'; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
271 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
272 |
_parent.append( $( reasonInputHtml ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
273 |
_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
|
274 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
275 |
if ( BwsModalIsReasonSelected( 'OTHER' ) ) { |
19 | 276 |
\$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
|
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 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
281 |
/* If the user has clicked outside the window, cancel it. */ |
16 | 282 |
\$modal.on( 'click', function( evt ) { |
283 |
var \$target = $( evt.target ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
284 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
285 |
/* If the user has clicked anywhere in the modal dialog, just return. */ |
16 | 286 |
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
|
287 |
return; |
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 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
290 |
/* If the user has not clicked the close button and the clicked element is inside the modal dialog, just return. */ |
16 | 291 |
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
|
292 |
return; |
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 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
295 |
/* Close the modal dialog */ |
16 | 296 |
\$modal.removeClass( 'active' ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
297 |
$( 'body' ).removeClass( 'has-bws-modal' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
298 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
299 |
return false; |
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 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
303 |
function BwsModalIsReasonSelected( reasonID ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
304 |
/* Get the selected radio input element.*/ |
16 | 305 |
return ( reasonID == \$modal.find('input[type=\"radio\"]:checked').val() ); |
7
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 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
308 |
function BwsModalReset() { |
16 | 309 |
selectedReasonID = false; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
310 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
311 |
/* Uncheck all radio buttons.*/ |
16 | 312 |
\$modal.find( 'input[type=\"radio\"]' ).prop( 'checked', false ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
313 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
314 |
/* Remove all input fields ( textfield, textarea ).*/ |
16 | 315 |
\$modal.find( '.bws-modal-reason-input' ).remove(); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
316 |
|
16 | 317 |
\$modal.find( '.message' ).hide(); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
318 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
319 |
/* Hide, since by default there is no selected reason.*/ |
16 | 320 |
\$anonymousFeedback.hide(); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
321 |
|
16 | 322 |
BwsModalDisableDeactivateButton(); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
323 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
324 |
BwsModalShowPanel(); |
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 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
327 |
function BwsModalEnableDeactivateButton() { |
16 | 328 |
\$modal.find( '.bws-modal-button-deactivate' ).removeClass( 'disabled' ).show(); |
329 |
\$modal.find( '.bws-modal-processing' ).hide(); |
|
7
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 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
332 |
function BwsModalDisableDeactivateButton() { |
16 | 333 |
\$modal.find( '.bws-modal-button-deactivate' ).addClass( 'disabled' ); |
7
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 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
336 |
function BwsModalShowPanel() { |
16 | 337 |
\$modal.find( '.bws-modal-panel' ).addClass( 'active' ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
338 |
} |
16 | 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' ); |
|
19 | 345 |
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
|
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 |
if ( ! function_exists( 'bws_submit_uninstall_reason_action' ) ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
350 |
/** |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
351 |
* Called after the user has submitted his reason for deactivating the plugin. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
352 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
353 |
* @since 2.1.3 |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
354 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
355 |
function bws_submit_uninstall_reason_action() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
356 |
global $bstwbsftwppdtplgns_options, $wp_version, $bstwbsftwppdtplgns_active_plugins, $current_user; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
357 |
|
19 | 358 |
if ( isset( $_REQUEST['bws_ajax_nonce'] ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
359 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
360 |
check_ajax_referer( 'bws_ajax_nonce', sanitize_text_field( wp_unslash( $_REQUEST['bws_ajax_nonce'] ) ) ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
361 |
|
19 | 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'] ) ) : ''; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
364 |
|
19 | 365 |
if ( empty( $reason_id ) || empty( $basename ) ) { |
366 |
exit; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
367 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
368 |
|
19 | 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 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
380 |
|
19 | 381 |
if ( ! $is_anonymous ) { |
382 |
if ( ! isset( $bstwbsftwppdtplgns_options ) ) { |
|
383 |
$bstwbsftwppdtplgns_options = ( is_multisite() ) ? get_site_option( 'bstwbsftwppdtplgns_options' ) : get_option( 'bstwbsftwppdtplgns_options' ); |
|
384 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
385 |
|
19 | 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 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
398 |
|
19 | 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 ) ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
412 |
|
19 | 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 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
422 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
423 |
|
19 | 424 |
echo 'done'; |
425 |
} else { |
|
426 |
echo wp_kses_data( $response->get_error_code() ) . ': ' . wp_kses_data( $response->get_error_message() ); |
|
427 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
428 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
429 |
exit; |
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 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
432 |
|
19 | 433 |
add_action( 'wp_ajax_bws_submit_uninstall_reason_action', 'bws_submit_uninstall_reason_action' ); |