PluginProbe
Post Grid Gutenberg Blocks – PostX / 2.4.24
Post Grid Gutenberg Blocks – PostX v2.4.24
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.24, at classes/Deactive.php

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