PluginProbe
Post Grid Gutenberg Blocks – PostX / 2.4.21
Post Grid Gutenberg Blocks – PostX v2.4.21
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 / classes / Deactive.php

Deactive.php in Post Grid Gutenberg Blocks – PostX 2.4.21, at classes/Deactive.php

614 lines 17.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Deactivation Action.
4 *
5 * @package ULTP\Notice
6 * @since v.1.1.0
7 */
8 namespace ULTP;
9
10 /**
11 * Deactive class.
12 */
13 defined('ABSPATH') || exit;
14
15 /**
16 * Deactive class.
17 */
18 class Deactive{
19
20 private $PLUGIN_NAME = 'PostX';
21 private $PLUGIN_SLUG = 'ultimate-post';
22 private $PLUGIN_VERSION = ULTP_VER;
23 private $API_ENDPOINT = 'https://inside.wpxpo.com';
24
25
26 /**
27 * Setup class.
28 *
29 * @since v.1.1.0
30 */
31 public function __construct() {
32 add_action( 'admin_footer', array( $this, 'get_source_data_callback' ) );
33
34 $is_collect = get_transient( 'wpxpo_data_collect' );
35 if ( $is_collect != 'yes' && $is_collect != 'no' ) {
36 add_action( 'admin_notices', array( $this, 'data_collect_notice' ) );
37 }
38
39 $is_frequency = get_transient( 'wpxpo_data_collect_every' );
40 if ( $is_frequency == false && $is_collect == 'yes') {
41 add_action( 'init', array( $this, 'send_frequency_plugin_data' ) );
42 set_transient( 'wpxpo_data_collect_every', 'yes', MONTH_IN_SECONDS ); // every 30 days
43 }
44
45 add_action( 'wp_ajax_ultp_tracking', array( $this, 'ultp_tracking_callback' ) );
46 add_action( 'wp_ajax_ultp_deactive_plugin', array( $this, 'send_plugin_data' ) );
47 }
48
49 public function send_frequency_plugin_data(){
50 $this->send_plugin_data( 'allow' );
51 }
52
53 public function ultp_tracking_callback(){
54 $type = isset( $_POST['type'] ) ? $_POST['type'] : 'notallow';
55 if( $type == 'allow' ) {
56 set_transient( 'wpxpo_data_collect', 'yes', 5 * YEAR_IN_SECONDS ); // 5 years notice
57 $this->send_plugin_data('allow');
58 } else {
59 set_transient( 'wpxpo_data_collect', 'no', 3 * MONTH_IN_SECONDS ); // 90 days notice
60 }
61 }
62
63
64 /**
65 * Data Collect Notice
66 *
67 * @since v.1.0.0
68 * @param NULL
69 * @return STRING | Message Shown in Admin Area
70 */
71 public function data_collect_notice() {
72 echo '<div class="notice notice-success">';
73 echo '<div class="wpxpo-btn-tracking-notice">';
74 printf( __( 'Want to help make <strong style="padding:0 5px;"> %1$s </strong> even more awesome? Allow %1$s to collect <a style="padding:0 5px;" href="https://www.wpxpo.com/data-collection-policy/" target="_blank">non-sensitive</a> diagnostic data and usage information.', 'ultimate-post' ), $this->PLUGIN_NAME );
75 echo '<a href="#" class="button button-primary wpxpo-btn-tracking" data-type="allow">' . __( "Allow", "ultimate-post" ) . '</a> ';
76 echo '<a href="#" class="button-secondary button-large wpxpo-btn-tracking" data-type="notallow">' . __( "No Thanks", "ultimate-post" ) . '</a>';
77 echo '</div>';
78 echo '</div>';
79 }
80
81
82 /**
83 * Check is Local or Not
84 *
85 * @since v.1.0.0
86 * @param NULL
87 * @return BOOLEAN | Is local or not
88 */
89 public function is_local() {
90 return in_array( $_SERVER['REMOTE_ADDR'], array( '127.0.0.1', '::1' ) );
91 }
92
93
94 /**
95 * Get Plugin Data Response
96 *
97 * @since v.1.0.0
98 * @param STRING
99 * @return ARRAY | Product return data
100 */
101 public function send_plugin_data( $type ) {
102 $data = $this->get_data();
103
104 $data['type'] = $type ? $type : 'deactive';
105 $form_data = isset($_POST) ? $_POST : array();
106
107 if ( current_user_can( 'administrator' ) ) {
108 if( isset( $form_data['action'] ) ){
109 unset( $form_data['action'] );
110 }
111
112 $response = wp_remote_post( $this->API_ENDPOINT, array(
113 'method' => 'POST',
114 'timeout' => 30,
115 'redirection' => 5,
116 'headers' => array(
117 'user-agent' => 'wpxpo/' . md5( esc_url( home_url() ) ) . ';',
118 'Accept' => 'application/json',
119 ),
120 'blocking' => true,
121 'httpversion' => '1.0',
122 'body' => array_merge($data, $form_data),
123 ) );
124
125 return $response;
126 }
127 }
128
129
130 /**
131 * Deactive Form Settings Data
132 *
133 * @since v.1.0.0
134 * @param NULL
135 * @return ARRAY | Settings Parameters
136 */
137 public function get_settings() {
138 $attr = array(
139 array(
140 'id' => 'no-need',
141 'input' => false,
142 'text' => __( "I no longer need the plugin.", "ultimate-post" )
143 ),
144 array(
145 'id' => 'better-plugin',
146 'input' => true,
147 'text' => __( "I found a better plugin.", "ultimate-post" ),
148 'placeholder' => __( "Please share which plugin.", "ultimate-post" ),
149 ),
150 array(
151 'id' => 'stop-working',
152 'input' => true,
153 'text' => __( "The plugin suddenly stopped working.", "ultimate-post" ),
154 'placeholder' => __( "Please share more details.", "ultimate-post" ),
155 ),
156 array(
157 'id' => 'not-working',
158 'input' => false,
159 'text' => __( "I could not get the plugin to work.", "ultimate-post" )
160 ),
161 array(
162 'id' => 'temporary-deactivation',
163 'input' => false,
164 'text' => __( "It's a temporary deactivation.", "ultimate-post" )
165 ),
166 array(
167 'id' => 'other',
168 'input' => true,
169 'text' => __( "Other.", "ultimate-post" ),
170 'placeholder' => __( "Please share the reason.", "ultimate-post" ),
171 ),
172 );
173 return $attr;
174 }
175
176
177 /**
178 * Deactive HTML View
179 *
180 * @since v.1.0.0
181 * @param NULL
182 * @return STRING | HTML Data
183 */
184 public function get_source_data_callback(){
185 global $pagenow;
186 if ( $pagenow == 'plugins.php' ) {
187 $this->deactive_html();
188 }
189 $this->deactive_css();
190 $this->deactive_js();
191 }
192
193 public function deactive_html() { ?>
194 <div class="ultp-modal" id="ultp-deactive-modal">
195 <div class="ultp-modal-wrap">
196
197 <div class="ultp-modal-header">
198 <h2><?php _e( "Quick Feedback", "ultimate-post" ); ?></h2>
199 <button class="ultp-modal-cancel"><span class="dashicons dashicons-no-alt"></span></button>
200 </div>
201
202 <div class="ultp-modal-body">
203 <h3><?php _e( "If you have a moment, please let us know why you are deactivating PostX:", "ultimate-post" ); ?></h3>
204 <ul class="ultp-modal-input">
205 <?php foreach ($this->get_settings() as $key => $setting) { ?>
206 <li>
207 <label>
208 <input type="radio" <?php echo $key == 0 ? 'checked="checked"' : ''; ?> id="<?php echo $setting['id']; ?>" name="<?php echo $this->PLUGIN_SLUG; ?>" value="<?php echo $setting['text']; ?>">
209 <div class="ultp-reason-text"><?php echo $setting['text']; ?></div>
210 <?php if( isset($setting['input']) && $setting['input'] ) { ?>
211 <textarea placeholder="<?php echo $setting['placeholder']; ?>" class="ultp-reason-input <?php echo $key == 0 ? 'ultp-active' : ''; ?> <?php echo $setting['id']; ?>"></textarea>
212 <?php } ?>
213 </label>
214 </li>
215 <?php } ?>
216 </ul>
217 </div>
218
219 <div class="ultp-modal-footer">
220 <a class="ultp-modal-submit ultp-btn ultp-btn-primary" href="#"><?php _e( "Submit & Deactivate", "ultimate-post" ); ?><span class="dashicons dashicons-update rotate"></span></a>
221 <a class="ultp-modal-deactive" href="#"><?php _e( "Skip & Deactivate", "ultimate-post" ); ?></a>
222 </div>
223
224 </div>
225 </div>
226 <?php }
227
228
229 /**
230 * Deactivation Forms CSS File
231 *
232 * @since v.1.0.0
233 * @param NULL
234 * @return STRING | CSS Code
235 */
236 public function deactive_css() { ?>
237 <style type="text/css">
238 .ultp-modal {
239 position: fixed;
240 z-index: 99999;
241 top: 0;
242 right: 0;
243 bottom: 0;
244 left: 0;
245 background: rgba(0,0,0,0.5);
246 display: none;
247 box-sizing: border-box;
248 overflow: scroll;
249 }
250 .ultp-modal * {
251 box-sizing: border-box;
252 }
253 .ultp-modal.modal-active {
254 display: block;
255 }
256 .ultp-modal-wrap {
257 max-width: 870px;
258 width: 100%;
259 position: relative;
260 margin: 10% auto;
261 background: #fff;
262 }
263 .ultp-reason-input{
264 display: none;
265 }
266 .ultp-reason-input.ultp-active{
267 display: block;
268 }
269 .rotate{
270 animation: rotate 1.5s linear infinite;
271 }
272 @keyframes rotate{
273 to{ transform: rotate(360deg); }
274 }
275 .ultp-popup-rotate{
276 animation: popupRotate 1s linear infinite;
277 }
278 @keyframes popupRotate{
279 to{ transform: rotate(360deg); }
280 }
281 #ultp-deactive-modal {
282 background: rgb(0 0 0 / 85%);
283 overflow: hidden;
284 }
285 #ultp-deactive-modal .ultp-modal-wrap {
286 max-width: 570px;
287 border-radius: 5px;
288 margin: 5% auto;
289 overflow: hidden
290 }
291 #ultp-deactive-modal .ultp-modal-header {
292 padding: 17px 30px;
293 border-bottom: 1px solid #ececec;
294 display: flex;
295 align-items: center;
296 background: #f5f5f5;
297 }
298 #ultp-deactive-modal .ultp-modal-header .ultp-modal-cancel {
299 padding: 0;
300 border-radius: 100px;
301 border: 1px solid #b9b9b9;
302 background: none;
303 color: #b9b9b9;
304 cursor: pointer;
305 transition: 400ms;
306 }
307 #ultp-deactive-modal .ultp-modal-header .ultp-modal-cancel:focus {
308 color: red;
309 border: 1px solid red;
310 outline: 0;
311 }
312 #ultp-deactive-modal .ultp-modal-header .ultp-modal-cancel:hover {
313 color: red;
314 border: 1px solid red;
315 }
316 #ultp-deactive-modal .ultp-modal-header h2 {
317 margin: 0;
318 padding: 0;
319 flex: 1;
320 line-height: 1;
321 font-size: 20px;
322 text-transform: uppercase;
323 color: #8e8d8d;
324 }
325 #ultp-deactive-modal .ultp-modal-body {
326 padding: 25px 30px;
327 }
328 #ultp-deactive-modal .ultp-modal-body h3{
329 padding: 0;
330 margin: 0;
331 line-height: 1.4;
332 font-size: 15px;
333 }
334 #ultp-deactive-modal .ultp-modal-body ul {
335 margin: 25px 0 10px;
336 }
337 #ultp-deactive-modal .ultp-modal-body ul li {
338 display: flex;
339 margin-bottom: 10px;
340 color: #807d7d;
341 }
342 #ultp-deactive-modal .ultp-modal-body ul li:last-child {
343 margin-bottom: 0;
344 }
345 #ultp-deactive-modal .ultp-modal-body ul li label {
346 align-items: center;
347 width: 100%;
348 }
349 #ultp-deactive-modal .ultp-modal-body ul li label input {
350 padding: 0 !important;
351 margin: 0;
352 display: inline-block;
353 }
354 #ultp-deactive-modal .ultp-modal-body ul li label textarea {
355 margin-top: 8px;
356 width: 350px;
357 }
358 #ultp-deactive-modal .ultp-modal-body ul li label .ultp-reason-text {
359 margin-left: 8px;
360 display: inline-block;
361 }
362 #ultp-deactive-modal .ultp-modal-footer {
363 padding: 0 30px 30px 30px;
364 display: flex;
365 align-items: center;
366 /* border-top: 1px solid #e5e5e5;
367 box-shadow: 0 0px 8px 0px rgb(0 0 0 / 12%); */
368 }
369 #ultp-deactive-modal .ultp-modal-footer .ultp-modal-submit {
370 display: flex;
371 align-items: center;
372 }
373 #ultp-deactive-modal .ultp-modal-footer .ultp-modal-submit span {
374 margin-left: 4px;
375 display: none;
376 }
377 #ultp-deactive-modal .ultp-modal-footer .ultp-modal-submit.loading span {
378 display: block;
379 }
380 #ultp-deactive-modal .ultp-modal-footer .ultp-modal-deactive {
381 margin-left: auto;
382 color: #c5c5c5;
383 text-decoration: none;
384 }
385 .wpxpo-btn-tracking-notice {
386 display: flex;
387 align-items: center;
388 flex-wrap: wrap;
389 padding: 5px 0;
390 }
391 .wpxpo-btn-tracking-notice .wpxpo-btn-tracking {
392 margin: 0 5px;
393 text-decoration: none;
394 }
395 </style>
396 <?php }
397
398
399 /**
400 * Deactivation Forms JS File
401 *
402 * @since v.1.0.0
403 * @param NULL
404 * @return STRING | JS Code
405 */
406 public function deactive_js() { ?>
407 <script type="text/javascript">
408 jQuery( document ).ready( function( $ ) {
409 'use strict';
410
411 // Modal Radio Input Click Action
412 $('.ultp-modal-input input[type=radio]').on( 'change', function(e) {
413 $('.ultp-reason-input').removeClass('ultp-active');
414 $('.ultp-modal-input').find( '.'+$(this).attr('id') ).addClass('ultp-active');
415 });
416
417 // Modal Cancel Click Action
418 $( document ).on( 'click', '.ultp-modal-cancel', function(e) {
419 $( '#ultp-deactive-modal' ).removeClass( 'modal-active' );
420 });
421
422 // Deactivate Button Click Action
423 $( document ).on( 'click', '#deactivate-ultimate-post', function(e) {
424 e.preventDefault();
425 $( '#ultp-deactive-modal' ).addClass( 'modal-active' );
426 $( '.ultp-modal-deactive' ).attr( 'href', $(this).attr('href') );
427 $( '.ultp-modal-submit' ).attr( 'href', $(this).attr('href') );
428 });
429
430 // Checking Tracking
431 $( document ).on( 'click', '.wpxpo-btn-tracking', function(e) {
432 e.preventDefault();
433 const that = $(this)
434 that.parents('.is-dismissible').hide("fast", function() { that.parents('.is-dismissible').remove(); });
435 $.ajax({
436 url: '<?php echo admin_url('admin-ajax.php'); ?>',
437 type: 'POST',
438 data: {
439 action: 'ultp_tracking',
440 type: that.data('type')
441 },
442 success: function (data) {
443 that.closest('.notice').hide();
444 }
445 });
446 });
447
448 // Submit to Remote Server
449 $( document ).on( 'click', '.ultp-modal-submit', function(e) {
450 e.preventDefault();
451
452 $(this).addClass('loading');
453 const url = $(this).attr('href')
454
455 $.ajax({
456 url: '<?php echo admin_url('admin-ajax.php'); ?>',
457 type: 'POST',
458 data: {
459 action: 'ultp_deactive_plugin',
460 cause_id: $('input[type=radio]:checked').attr('id'),
461 cause_title: $('.ultp-modal-input input[type=radio]:checked').val(),
462 cause_details: $('.ultp-reason-input.ultp-active').val()
463 },
464 success: function (data) {
465 $( '#ultp-deactive-modal' ).removeClass( 'modal-active' );
466 window.location.href = url;
467 // that.parents('.wc-install').hide("slow", function() { that.parents('.wc-install').remove(); });
468 },
469 error: function(xhr) {
470 console.log( 'Error occured. Please try again' + xhr.statusText + xhr.responseText );
471 },
472 });
473
474 });
475
476 });
477 </script>
478 <?php }
479
480
481 /**
482 * Get All the Installed Plugin Data
483 *
484 * @since v.1.0.0
485 * @param NULL
486 * @return ARRAY | Return Plugin Information
487 */
488 public function get_plugins(){
489 if ( ! function_exists( 'get_plugins' ) ) {
490 include ABSPATH . '/wp-admin/includes/plugin.php';
491 }
492
493 $active = array();
494 $inactive = array();
495 $all_plugins = get_plugins();
496 $active_plugins = get_option( 'active_plugins', array() );
497 if (is_multisite()) {
498 $active_plugins = array_merge($active_plugins, array_keys(get_site_option( 'active_sitewide_plugins', array() )));
499 }
500
501 foreach ( $all_plugins as $key => $plugin ) {
502 $arr = array();
503
504 $arr['name'] = isset( $plugin['Name'] ) ? $plugin['Name'] : '';
505 $arr['url'] = isset( $plugin['PluginURI'] ) ? $plugin['PluginURI'] : '';
506 $arr['author'] = isset( $plugin['Author'] ) ? $plugin['Author'] : '';
507 $arr['version'] = isset( $plugin['Version'] ) ? $plugin['Version'] : '';
508
509 if ( in_array( $key, $active_plugins ) ){
510 $active[$key] = $arr;
511 } else {
512 $inactive[$key] = $arr;
513 }
514 }
515
516 return array( 'active' => $active, 'inactive' => $inactive );
517 }
518
519
520 /**
521 * Get All the Theme Installed
522 *
523 * @since v.1.0.0
524 * @param NULL
525 * @return ARRAY | Return Theme Information
526 */
527 public function get_themes() {
528 $theme_data = array();
529 $all_themes = wp_get_themes();
530
531 if(is_array($all_themes)){
532 foreach ($all_themes as $key => $theme) {
533 $attr = array();
534 $attr['name'] = $theme->Name;
535 $attr['url'] = $theme->ThemeURI;
536 $attr['author'] = $theme->Author;
537 $attr['version'] = $theme->Version;
538 $theme_data[$key] = $attr;
539 }
540 }
541 return $theme_data;
542 }
543
544
545 /**
546 * Get Current User IP
547 *
548 * @since v.1.0.0
549 * @param NULL
550 * @return STRING | Return IP
551 */
552 public function get_user_ip() {
553 $response = wp_remote_get( 'https://icanhazip.com/' );
554
555 if ( is_wp_error( $response ) ) {
556 return '';
557 } else {
558 $user_ip = trim( wp_remote_retrieve_body( $response ) );
559 return filter_var( $user_ip, FILTER_VALIDATE_IP ) ? $user_ip : '';
560 }
561 }
562
563
564 /**
565 * Get All the Data Collected
566 *
567 * @since v.1.0.0
568 * @param NULL
569 * @return ARRAY | All Send Data
570 */
571 public function get_data() {
572 global $wpdb;
573 $user = wp_get_current_user();
574 $user_count = count_users();
575 $plugins_data = $this->get_plugins();
576
577 $data = array(
578 'name' => get_bloginfo( 'name' ),
579 'home' => esc_url( home_url() ),
580 'admin_email' => $user->user_email,
581 'first_name' => isset($user->user_firstname) ? $user->user_firstname : '',
582 'last_name' => isset($user->user_lastname) ? $user->user_lastname : '',
583 'display_name' => $user->display_name,
584 'wordpress' => get_bloginfo( 'version' ),
585 'memory_limit' => WP_MEMORY_LIMIT,
586 'debug_mode' => ( defined('WP_DEBUG') && WP_DEBUG ) ? 'Yes' : 'No',
587 'locale' => get_locale(),
588 'multisite' => is_multisite() ? 'Yes' : 'No',
589
590 'themes' => $this->get_themes(),
591 'active_theme' => get_stylesheet(),
592 'users' => isset($user_count['total_users']) ? $user_count['total_users'] : 0,
593 'active_plugins' => $plugins_data['active'],
594 'inactive_plugins' => $plugins_data['inactive'],
595 'server' => isset( $_SERVER['SERVER_SOFTWARE'] ) ? $_SERVER['SERVER_SOFTWARE'] : '',
596
597 'timezone' => date_default_timezone_get(),
598 'php_curl' => function_exists( 'curl_init' ) ? 'Yes' : 'No',
599 'php_version' => function_exists('phpversion') ? phpversion() : '',
600 'upload_size' => size_format( wp_max_upload_size() ),
601 'mysql_version' => $wpdb->db_version(),
602 'php_fsockopen' => function_exists( 'fsockopen' ) ? 'Yes' : 'No',
603
604 'ip' => $this->get_user_ip(),
605 'plugin_name' => $this->PLUGIN_NAME,
606 'plugin_version' => $this->PLUGIN_VERSION,
607 'plugin_slug' => $this->PLUGIN_SLUG
608 );
609
610 return $data;
611 }
612
613
614 }