PluginProbe
Post Grid Gutenberg Blocks – PostX / 2.4.6
Post Grid Gutenberg Blocks – PostX v2.4.6
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.6, at classes/Deactive.php

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