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