PluginProbe
Post Grid Gutenberg Blocks – PostX / 5.1.1
Post Grid Gutenberg Blocks – PostX v5.1.1
5.1.1 5.1.0 5.0.41 5.0.39 5.0.38 5.0.37 5.0.36 5.0.35 5.0.34 5.0.33 5.0.32 5.0.31 5.0.30 5.0.29 5.0.28 5.0.27 5.0.26 5.0.25 5.0.23 5.0.24 5.0.22 5.0.21 5.0.20 5.0.19 5.0.18 All 240 releases
ultimate-post / includes / deactive / class-deactive.php

class-deactive.php in Post Grid Gutenberg Blocks – PostX 5.1.1, at includes/deactive/class-deactive.php

383 lines 10.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php //phpcs:ignore
2 /**
3 * Plugin Deactivation Handler.
4 *
5 * @since
6 */
7
8 namespace ULTP\Includes\Deactive;
9
10 use ULTP\Includes\Durbin\DurbinClient;
11
12 defined( 'ABSPATH' ) || exit;
13
14 /**
15 * Handles plugin deactivation feedback and reporting.
16 */
17 class Deactive {
18
19 private $plugin_slug = 'ultimate-post';
20
21 /**
22 * Constructor.
23 */
24 public function __construct() {
25 global $pagenow;
26
27 if ( 'plugins.php' === $pagenow ) {
28 add_action( 'admin_footer', array( $this, 'get_source_data_callback' ) );
29 }
30 add_action( 'wp_ajax_ultp_deactive_plugin', array( $this, 'send_plugin_data' ) );
31 }
32
33 /**
34 * Send plugin deactivation data to remote server.
35 *
36 * @param string|null $type Optional. Unused for now.
37 * @return void
38 */
39 public function send_plugin_data() {
40 if ( ! check_ajax_referer( 'ultp_deactive_plugin', 'wpnonce', false ) ) {
41 wp_die();
42 }
43 DurbinClient::send( DurbinClient::DEACTIVATE_ACTION );
44 }
45
46 /**
47 * Output deactivation modal markup, CSS, and JS.
48 *
49 * @return void
50 */
51 public function get_source_data_callback() {
52 $this->deactive_container_css();
53 $this->deactive_container_js();
54 $this->deactive_html_container();
55 }
56
57 /**
58 * Get deactivation reasons and field settings.
59 *
60 * @return array[] List of deactivation options.
61 */
62 public function get_deactive_settings() {
63 return array(
64 array(
65 'id' => 'not-working',
66 'input' => false,
67 'text' => __( 'The plugin isn’t working properly.', 'ultimate-post' ),
68 ),
69 array(
70 'id' => 'limited-features',
71 'input' => false,
72 'text' => __( 'Limited features on the free version.', 'ultimate-post' ),
73 ),
74 array(
75 'id' => 'better-plugin',
76 'input' => true,
77 'text' => __( 'I found a better plugin.', 'ultimate-post' ),
78 'placeholder' => __( 'Please share which plugin.', 'ultimate-post' ),
79 ),
80 array(
81 'id' => 'temporary-deactivation',
82 'input' => false,
83 'text' => __( "It's a temporary deactivation.", 'ultimate-post' ),
84 ),
85 array(
86 'id' => 'other',
87 'input' => true,
88 'text' => __( 'Other.', 'ultimate-post' ),
89 'placeholder' => __( 'Please share the reason.', 'ultimate-post' ),
90 ),
91 );
92 }
93
94 /**
95 * Output HTML for the deactivation modal.
96 *
97 * @return void
98 */
99 public function deactive_html_container() {
100 ?>
101 <div class="ultp-modal" id="ultp-deactive-modal">
102 <div class="ultp-modal-wrap">
103
104 <div class="ultp-modal-header">
105 <h2><?php esc_html_e( 'Quick Feedback', 'ultimate-post' ); ?></h2>
106 <button class="ultp-modal-cancel"><span class="dashicons dashicons-no-alt"></span></button>
107 </div>
108
109 <div class="ultp-modal-body">
110 <h3><?php esc_html_e( 'If you have a moment, please let us know why you are deactivating PostX:', 'ultimate-post' ); ?></h3>
111 <ul class="ultp-modal-input">
112 <?php foreach ( $this->get_deactive_settings() as $key => $setting ) { ?>
113 <li>
114 <label>
115 <input type="radio" <?php echo 0 == $key ? 'checked="checked"' : ''; ?> id="<?php echo esc_attr( $setting['id'] ); ?>" name="<?php echo esc_attr( $this->plugin_slug ); ?>" value="<?php echo esc_attr( $setting['text'] ); ?>">
116 <div class="ultp-reason-text"><?php echo esc_html( $setting['text'] ); ?></div>
117 <?php if ( isset( $setting['input'] ) && $setting['input'] ) { ?>
118 <textarea placeholder="<?php echo esc_attr( $setting['placeholder'] ); ?>" class="ultp-reason-input <?php echo esc_attr( 0 == $key ? 'ultp-active' : '' ); ?> <?php echo esc_attr( $setting['id'] ); ?>"></textarea>
119 <?php } ?>
120 </label>
121 </li>
122 <?php } ?>
123 </ul>
124 </div>
125
126 <div class="ultp-modal-footer">
127 <a class="ultp-modal-submit ultp-btn ultp-btn-primary" href="#"><?php esc_html_e( 'Submit & Deactivate', 'ultimate-post' ); ?><span class="dashicons dashicons-update rotate"></span></a>
128 <a class="ultp-modal-deactive" href="#"><?php esc_html_e( 'Skip & Deactivate', 'ultimate-post' ); ?></a>
129 </div>
130
131 </div>
132 </div>
133 <?php
134 }
135
136 /**
137 * Output inline CSS for the modal.
138 *
139 * @return void
140 */
141 public function deactive_container_css() {
142 ?>
143 <style type="text/css">
144 .ultp-modal {
145 position: fixed;
146 z-index: 99999;
147 top: 0;
148 right: 0;
149 bottom: 0;
150 left: 0;
151 background: rgba(0,0,0,0.5);
152 display: none;
153 box-sizing: border-box;
154 overflow: scroll;
155 }
156 .ultp-modal * {
157 box-sizing: border-box;
158 }
159 .ultp-modal.modal-active {
160 display: block;
161 }
162 .ultp-modal-wrap {
163 max-width: 870px;
164 width: 100%;
165 position: relative;
166 margin: 10% auto;
167 background: #fff;
168 }
169 .ultp-reason-input{
170 display: none;
171 }
172 .ultp-reason-input.ultp-active{
173 display: block;
174 }
175 .rotate{
176 animation: rotate 1.5s linear infinite;
177 }
178 @keyframes rotate{
179 to{ transform: rotate(360deg); }
180 }
181 .ultp-popup-rotate{
182 animation: popupRotate 1s linear infinite;
183 }
184 @keyframes popupRotate{
185 to{ transform: rotate(360deg); }
186 }
187 #ultp-deactive-modal {
188 background: rgb(0 0 0 / 85%);
189 overflow: hidden;
190 }
191 #ultp-deactive-modal .ultp-modal-wrap {
192 max-width: 570px;
193 border-radius: 5px;
194 margin: 5% auto;
195 overflow: hidden
196 }
197 #ultp-deactive-modal .ultp-modal-header {
198 padding: 17px 30px;
199 border-bottom: 1px solid #ececec;
200 display: flex;
201 align-items: center;
202 background: #f5f5f5;
203 }
204 #ultp-deactive-modal .ultp-modal-header .ultp-modal-cancel {
205 padding: 0;
206 border-radius: 100px;
207 border: 1px solid #b9b9b9;
208 background: none;
209 color: #b9b9b9;
210 cursor: pointer;
211 transition: 400ms;
212 }
213 #ultp-deactive-modal .ultp-modal-header .ultp-modal-cancel:focus {
214 color: red;
215 border: 1px solid red;
216 outline: 0;
217 }
218 #ultp-deactive-modal .ultp-modal-header .ultp-modal-cancel:hover {
219 color: red;
220 border: 1px solid red;
221 }
222 #ultp-deactive-modal .ultp-modal-header h2 {
223 margin: 0;
224 padding: 0;
225 flex: 1;
226 line-height: 1;
227 font-size: 20px;
228 text-transform: uppercase;
229 color: #8e8d8d;
230 }
231 #ultp-deactive-modal .ultp-modal-body {
232 padding: 25px 30px;
233 }
234 #ultp-deactive-modal .ultp-modal-body h3{
235 padding: 0;
236 margin: 0;
237 line-height: 1.4;
238 font-size: 15px;
239 }
240 #ultp-deactive-modal .ultp-modal-body ul {
241 margin: 25px 0 10px;
242 }
243 #ultp-deactive-modal .ultp-modal-body ul li {
244 display: flex;
245 margin-bottom: 10px;
246 color: #807d7d;
247 }
248 #ultp-deactive-modal .ultp-modal-body ul li:last-child {
249 margin-bottom: 0;
250 }
251 #ultp-deactive-modal .ultp-modal-body ul li label {
252 align-items: center;
253 width: 100%;
254 }
255 #ultp-deactive-modal .ultp-modal-body ul li label input {
256 padding: 0 !important;
257 margin: 0;
258 display: inline-block;
259 }
260 #ultp-deactive-modal .ultp-modal-body ul li label textarea {
261 margin-top: 8px;
262 width: 100% !important;
263 }
264 #ultp-deactive-modal .ultp-modal-body ul li label .ultp-reason-text {
265 margin-left: 8px;
266 display: inline-block;
267 }
268 #ultp-deactive-modal .ultp-modal-footer {
269 padding: 0 30px 30px 30px;
270 display: flex;
271 align-items: center;
272 }
273 #ultp-deactive-modal .ultp-modal-footer .ultp-modal-submit {
274 display: flex;
275 align-items: center;
276 padding: 12px 22px;
277 border-radius: 3px;
278 background: #037fff;
279 color: #fff;
280 font-size: 16px;
281 font-weight: 600;
282 text-decoration: none;
283 }
284 #ultp-deactive-modal .ultp-modal-footer .ultp-modal-submit span {
285 margin-left: 4px;
286 display: none;
287 }
288 #ultp-deactive-modal .ultp-modal-footer .ultp-modal-submit.loading span {
289 display: block;
290 }
291 #ultp-deactive-modal .ultp-modal-footer .ultp-modal-deactive {
292 margin-left: auto;
293 color: #c5c5c5;
294 text-decoration: none;
295 }
296 .wpxpo-btn-tracking-notice {
297 display: flex;
298 align-items: center;
299 flex-wrap: wrap;
300 padding: 5px 0;
301 }
302 .wpxpo-btn-tracking-notice .wpxpo-btn-tracking {
303 margin: 0 5px;
304 text-decoration: none;
305 }
306 </style>
307 <?php
308 }
309
310 /**
311 * Output inline JavaScript for the modal logic.
312 *
313 * @return void
314 */
315 public function deactive_container_js() {
316 ?>
317 <script type="text/javascript">
318 jQuery( document ).ready( function( $ ) {
319 'use strict';
320
321 // Modal Radio Input Click Action
322 $('.ultp-modal-input input[type=radio]').on( 'change', function(e) {
323 $('.ultp-reason-input').removeClass('ultp-active');
324 $('.ultp-modal-input').find( '.'+$(this).attr('id') ).addClass('ultp-active');
325 });
326
327 // Modal Cancel Click Action
328 $( document ).on( 'click', '.ultp-modal-cancel', function(e) {
329 $( '#ultp-deactive-modal' ).removeClass( 'modal-active' );
330 });
331
332 $(document).on('click', function(event) {
333 const $popup = $('#ultp-deactive-modal');
334 const $modalWrap = $popup.find('.ultp-modal-wrap');
335
336 if ( !$modalWrap.is(event.target) && $modalWrap.has(event.target).length === 0 && $popup.hasClass('modal-active')) {
337 $popup.removeClass('modal-active');
338 }
339 });
340
341 // Deactivate Button Click Action
342 $( document ).on( 'click', '#deactivate-ultimate-post', function(e) {
343 e.preventDefault();
344 e.stopPropagation();
345 $( '#ultp-deactive-modal' ).addClass( 'modal-active' );
346 $( '.ultp-modal-deactive' ).attr( 'href', $(this).attr('href') );
347 $( '.ultp-modal-submit' ).attr( 'href', $(this).attr('href') );
348 });
349
350 // Submit to Remote Server
351 $( document ).on( 'click', '.ultp-modal-submit', function(e) {
352 e.preventDefault();
353
354 $(this).addClass('loading');
355 const url = $(this).attr('href')
356
357 $.ajax({
358 url: '<?php echo esc_url( admin_url( 'admin-ajax.php' ) ); ?>',
359 type: 'POST',
360 data: {
361 action: 'ultp_deactive_plugin',
362 wpnonce: '<?php echo esc_js( wp_create_nonce( 'ultp_deactive_plugin' ) ); ?>',
363 cause_id: $('#ultp-deactive-modal input[type=radio]:checked').attr('id'),
364 cause_title: $('#ultp-deactive-modal .ultp-modal-input input[type=radio]:checked').val(),
365 cause_details: $('#ultp-deactive-modal .ultp-reason-input.ultp-active').val()
366 },
367 success: function (data) {
368 $( '#ultp-deactive-modal' ).removeClass( 'modal-active' );
369 window.location.href = url;
370 },
371 error: function(xhr) {
372 console.log( 'Error occured. Please try again' + xhr.statusText + xhr.responseText );
373 },
374 });
375
376 });
377
378 });
379 </script>
380 <?php
381 }
382 }
383