PluginProbe
Post Grid Gutenberg Blocks – PostX / trunk
Post Grid Gutenberg Blocks – PostX vtrunk
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 5.0.17 2.1.1 2.1.2 All 237 releases
ultimate-post / includes / deactive / class-deactive.php

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

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