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

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