PluginProbe
Post Grid Gutenberg Blocks – PostX / 3.2.2
Post Grid Gutenberg Blocks – PostX v3.2.2
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 3.2.2, at classes/Deactive.php

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