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