| @@ -1,219 +1,201 @@ | ||
| 1 | 1 | <?php |
| 2 | -/** | |
| 3 | - * Deactivation Action. | |
| 4 | - * | |
| 5 | - * @package ULTP\Notice | |
| 6 | - * @since v.1.1.0 | |
| 7 | - */ | |
| 8 | - | |
| 9 | 2 | namespace ULTP; |
| 10 | 3 | |
| 11 | -defined( 'ABSPATH' ) || exit; | |
| 4 | +defined('ABSPATH') || exit; | |
| 12 | 5 | |
| 13 | -/** | |
| 14 | - * Deactive class. | |
| 15 | - * | |
| 16 | - * Handles plugin deactivation logic for Ultimate Post. | |
| 17 | - * | |
| 18 | - * @package ULTP\Deactive | |
| 19 | - * @since 4.0.0 | |
| 20 | - */ | |
| 21 | -class Deactive { | |
| 6 | +class Deactive{ | |
| 22 | 7 | |
| 23 | - private $PLUGIN_NAME = 'PostX'; | |
| 24 | - private $PLUGIN_SLUG = 'ultimate-post'; | |
| 8 | + private $PLUGIN_NAME = 'PostX'; | |
| 9 | + private $PLUGIN_SLUG = 'ultimate-post'; | |
| 25 | 10 | private $PLUGIN_VERSION = ULTP_VER; |
| 26 | - private $API_ENDPOINT = 'https://inside.wpxpo.com'; | |
| 11 | + private $API_ENDPOINT = 'https://inside.wpxpo.com'; | |
| 12 | + | |
| 13 | + public function __construct() { | |
| 14 | + add_action( 'admin_footer', array( $this, 'get_source_data_callback' ) ); | |
| 27 | 15 | |
| 28 | - /** | |
| 29 | - * Setup class.s | |
| 30 | - * | |
| 31 | - * @since v.1.1.0 | |
| 32 | - */ | |
| 33 | - public function __construct() { | |
| 34 | - global $pagenow; | |
| 35 | - if ( $pagenow == 'plugins.php' ) { | |
| 36 | - add_action( 'admin_footer', array( $this, 'get_source_data_callback' ) ); | |
| 16 | + $is_collect = get_transient( 'wpxpo_data_collect' ); | |
| 17 | + if ( $is_collect != 'yes' && $is_collect != 'no' ) { | |
| 18 | + add_action( 'admin_notices', array( $this, 'data_collect_notice' ) ); | |
| 37 | 19 | } |
| 20 | + | |
| 21 | + $is_frequency = get_transient( 'wpxpo_data_collect_every' ); | |
| 22 | + if ( $is_frequency == false && $is_collect == 'yes') { | |
| 23 | + add_action( 'init', array( $this, 'send_frequency_plugin_data' ) ); | |
| 24 | + set_transient( 'wpxpo_data_collect_every', 'yes', 604800 ); // every 7 days | |
| 25 | + } | |
| 26 | + | |
| 27 | + add_action( 'wp_ajax_ultp_tracking', array( $this, 'ultp_tracking_callback' ) ); | |
| 38 | 28 | add_action( 'wp_ajax_ultp_deactive_plugin', array( $this, 'send_plugin_data' ) ); |
| 39 | 29 | } |
| 40 | 30 | |
| 41 | - /** | |
| 42 | - * Get plugin data response. | |
| 43 | - * | |
| 44 | - * @since v.1.0.0 | |
| 45 | - * @param STRING $type The type of deactivation. | |
| 46 | - * @param STRING $site The site type (optional). | |
| 47 | - * @return ARRAY Product return data. | |
| 48 | - */ | |
| 49 | - public function send_plugin_data( $type, $site = '' ) { | |
| 31 | + public function send_frequency_plugin_data(){ | |
| 32 | + $this->send_plugin_data( 'allow' ); | |
| 33 | + } | |
| 50 | 34 | |
| 35 | + public function ultp_tracking_callback(){ | |
| 36 | + if ( isset( $_POST['type'] ) ) { | |
| 37 | + if( $_POST['type'] == 'allow' ) { | |
| 38 | + set_transient( 'wpxpo_data_collect', 'yes', 157680000 ); // 5 years notice | |
| 39 | + $this->send_plugin_data( $_POST['type'] ); | |
| 40 | + } else { | |
| 41 | + set_transient( 'wpxpo_data_collect', 'no', 31536000 ); // 30 days notice | |
| 42 | + } | |
| 43 | + } | |
| 44 | + } | |
| 45 | + | |
| 46 | + public function data_collect_notice() { | |
| 47 | + echo '<div class="notice notice-success">'; | |
| 48 | + echo '<div class="wpxpo-btn-tracking-notice">'; | |
| 49 | + 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 ); | |
| 50 | + echo '<a href="#" class="button button-primary wpxpo-btn-tracking" data-type="allow">' . __( "Allow", "ultimate-post" ) . '</a> '; | |
| 51 | + echo '<a href="#" class="button-secondary button-large wpxpo-btn-tracking" data-type="notallow">' . __( "No Thanks", "ultimate-post" ) . '</a>'; | |
| 52 | + echo '</div>'; | |
| 53 | + echo '</div>'; | |
| 54 | + } | |
| 55 | + | |
| 56 | + public function is_local() { | |
| 57 | + return in_array( $_SERVER['REMOTE_ADDR'], array( '127.0.0.1', '::1' ) ); | |
| 58 | + } | |
| 59 | + | |
| 60 | + public function send_plugin_data( $type ) { | |
| 61 | + $data = $this->get_data(); | |
| 62 | + | |
| 63 | + $data['type'] = $type ? $type : 'deactive'; | |
| 64 | + $form_data = isset($_POST) ? $_POST : array(); | |
| 65 | + | |
| 51 | 66 | if ( current_user_can( 'administrator' ) ) { |
| 52 | - $data = $this->get_required_data(); | |
| 53 | - $data['site_type'] = $site ? $site : get_option( '__ultp_site_type', '' ); | |
| 54 | - $data['type'] = $type ? $type : 'deactive'; | |
| 55 | - $form_data = isset($_POST) ? ultimate_post()->ultp_rest_sanitize_params($_POST) : array(); //phpcs:Ignore | |
| 56 | - | |
| 57 | - if ( isset( $form_data['action'] ) ) { | |
| 67 | + if( isset( $form_data['action'] ) ){ | |
| 58 | 68 | unset( $form_data['action'] ); |
| 59 | 69 | } |
| 60 | - $response = wp_remote_post( | |
| 61 | - $this->API_ENDPOINT, | |
| 62 | - array( | |
| 63 | - 'method' => 'POST', | |
| 64 | - 'timeout' => 30, | |
| 65 | - 'redirection' => 5, | |
| 66 | - 'headers' => array( | |
| 67 | - 'user-agent' => 'wpxpo/' . md5( esc_url( home_url() ) ) . ';', | |
| 68 | - 'Accept' => 'application/json', | |
| 69 | - ), | |
| 70 | - 'blocking' => true, | |
| 71 | - 'httpversion' => '1.0', | |
| 72 | - 'body' => array_merge( $data, $form_data ), | |
| 73 | - ) | |
| 74 | - ); | |
| 75 | 70 | |
| 71 | + $response = wp_remote_post( $this->API_ENDPOINT, array( | |
| 72 | + 'method' => 'POST', | |
| 73 | + 'timeout' => 30, | |
| 74 | + 'redirection' => 5, | |
| 75 | + 'headers' => array( | |
| 76 | + 'user-agent' => 'wpxpo/' . md5( esc_url( home_url() ) ) . ';', | |
| 77 | + 'Accept' => 'application/json', | |
| 78 | + ), | |
| 79 | + 'blocking' => true, | |
| 80 | + 'httpversion' => '1.0', | |
| 81 | + 'body' => array_merge($data, $form_data), | |
| 82 | + ) ); | |
| 83 | + | |
| 76 | 84 | return $response; |
| 77 | - } | |
| 85 | + } | |
| 78 | 86 | } |
| 79 | - | |
| 80 | - /** | |
| 81 | - * Get deactivation form settings data. | |
| 82 | - * | |
| 83 | - * @since v.1.0.0 | |
| 84 | - * @return ARRAY Settings parameters. | |
| 85 | - */ | |
| 86 | - public function get_deactive_settings() { | |
| 87 | + | |
| 88 | + public function get_settings() { | |
| 87 | 89 | $attr = array( |
| 88 | 90 | array( |
| 89 | - 'id' => 'no-need', | |
| 90 | - 'input' => false, | |
| 91 | - 'text' => __( 'I no longer need the plugin.', 'ultimate-post' ), | |
| 91 | + 'id' => 'no-need', | |
| 92 | + 'input' => false, | |
| 93 | + 'text' => __( "I no longer need the plugin.", "ultimate-post" ) | |
| 92 | 94 | ), |
| 93 | 95 | array( |
| 94 | - 'id' => 'better-plugin', | |
| 95 | - 'input' => true, | |
| 96 | - 'text' => __( 'I found a better plugin.', 'ultimate-post' ), | |
| 97 | - 'placeholder' => __( 'Please share which plugin.', 'ultimate-post' ), | |
| 96 | + 'id' => 'better-plugin', | |
| 97 | + 'input' => true, | |
| 98 | + 'text' => __( "I found a better plugin.", "ultimate-post" ), | |
| 99 | + 'placeholder' => __( "Please share which plugin.", "ultimate-post" ), | |
| 98 | 100 | ), |
| 99 | 101 | array( |
| 100 | - 'id' => 'stop-working', | |
| 101 | - 'input' => true, | |
| 102 | - 'text' => __( 'The plugin suddenly stopped working.', 'ultimate-post' ), | |
| 103 | - 'placeholder' => __( 'Please share more details.', 'ultimate-post' ), | |
| 102 | + 'id' => 'stop-working', | |
| 103 | + 'input' => true, | |
| 104 | + 'text' => __( "The plugin suddenly stopped working.", "ultimate-post" ), | |
| 105 | + 'placeholder' => __( "Please share more details.", "ultimate-post" ), | |
| 104 | 106 | ), |
| 105 | 107 | array( |
| 106 | - 'id' => 'not-working', | |
| 107 | - 'input' => false, | |
| 108 | - 'text' => __( 'I could not get the plugin to work.', 'ultimate-post' ), | |
| 108 | + 'id' => 'not-working', | |
| 109 | + 'input' => false, | |
| 110 | + 'text' => __( "I could not get the plugin to work.", "ultimate-post" ) | |
| 109 | 111 | ), |
| 110 | 112 | array( |
| 111 | - 'id' => 'temporary-deactivation', | |
| 112 | - 'input' => false, | |
| 113 | - 'text' => __( "It's a temporary deactivation.", 'ultimate-post' ), | |
| 113 | + 'id' => 'temporary-deactivation', | |
| 114 | + 'input' => false, | |
| 115 | + 'text' => __( "It's a temporary deactivation.", "ultimate-post" ) | |
| 114 | 116 | ), |
| 115 | 117 | array( |
| 116 | - 'id' => 'other', | |
| 117 | - 'input' => true, | |
| 118 | - 'text' => __( 'Other.', 'ultimate-post' ), | |
| 119 | - 'placeholder' => __( 'Please share the reason.', 'ultimate-post' ), | |
| 118 | + 'id' => 'other', | |
| 119 | + 'input' => true, | |
| 120 | + 'text' => __( "Other.", "ultimate-post" ), | |
| 121 | + 'placeholder' => __( "Please share the reason.", "ultimate-post" ), | |
| 120 | 122 | ), |
| 121 | 123 | ); |
| 122 | 124 | return $attr; |
| 123 | 125 | } |
| 124 | 126 | |
| 125 | - /** | |
| 126 | - * Output deactivation HTML view. | |
| 127 | - * | |
| 128 | - * @since v.1.0.0 | |
| 129 | - * @return void No return value. | |
| 130 | - */ | |
| 131 | - public function get_source_data_callback() { | |
| 132 | - $this->deactive_html_container(); | |
| 133 | - $this->deactive_container_css(); | |
| 134 | - $this->deactive_container_js(); | |
| 127 | + public function get_source_data_callback(){ | |
| 128 | + global $pagenow; | |
| 129 | + if ( $pagenow == 'plugins.php' ) { | |
| 130 | + $this->deactive_html(); | |
| 131 | + } | |
| 132 | + $this->deactive_css(); | |
| 133 | + $this->deactive_js(); | |
| 135 | 134 | } |
| 136 | 135 | |
| 137 | - /** | |
| 138 | - * Outputs the HTML container for the deactivation process. | |
| 139 | - * | |
| 140 | - * This method is responsible for rendering the necessary HTML | |
| 141 | - * when the plugin is being deactivated. | |
| 142 | - * | |
| 143 | - * @return void | |
| 144 | - */ | |
| 145 | - public function deactive_html_container() { | |
| 146 | - ?> | |
| 147 | - <div class="ultp-modal" id="ultp-deactive-modal"> | |
| 148 | - <div class="ultp-modal-wrap"> | |
| 136 | + public function deactive_html() { ?> | |
| 137 | + <div class="ultp-modal" id="ultp-deactive-modal"> | |
| 138 | + <div class="ultp-modal-wrap"> | |
| 149 | 139 | |
| 150 | - <div class="ultp-modal-header"> | |
| 151 | - <h2><?php esc_html_e( 'Quick Feedback', 'ultimate-post' ); ?></h2> | |
| 152 | - <button class="ultp-modal-cancel"><span class="dashicons dashicons-no-alt"></span></button> | |
| 153 | - </div> | |
| 140 | + <div class="ultp-modal-header"> | |
| 141 | + <h2><?php _e( "Quick Feedback", "ultimate-post" ); ?></h2> | |
| 142 | + <button class="ultp-modal-cancel"><span class="dashicons dashicons-no-alt"></span></button> | |
| 143 | + </div> | |
| 154 | 144 | |
| 155 | - <div class="ultp-modal-body"> | |
| 156 | - <h3><?php esc_html_e( 'If you have a moment, please let us know why you are deactivating PostX:', 'ultimate-post' ); ?></h3> | |
| 157 | - <ul class="ultp-modal-input"> | |
| 158 | - <?php foreach ( $this->get_deactive_settings() as $key => $setting ) { ?> | |
| 145 | + <div class="ultp-modal-body"> | |
| 146 | + <h3><?php _e( "If you have a moment, please let us know why you are deactivating PostX:", "ultimate-post" ); ?></h3> | |
| 147 | + <ul class="ultp-modal-input"> | |
| 148 | + <?php foreach ($this->get_settings() as $key => $setting) { ?> | |
| 159 | 149 | <li> |
| 160 | 150 | <label> |
| 161 | - <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'] ); ?>"> | |
| 162 | - <div class="ultp-reason-text"><?php echo esc_html( $setting['text'] ); ?></div> | |
| 163 | - <?php if ( isset( $setting['input'] ) && $setting['input'] ) { ?> | |
| 164 | - <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> | |
| 151 | + <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']; ?>"> | |
| 152 | + <div class="ultp-reason-text"><?php echo $setting['text']; ?></div> | |
| 153 | + <?php if( isset($setting['input']) && $setting['input'] ) { ?> | |
| 154 | + <textarea placeholder="<?php echo $setting['placeholder']; ?>" class="ultp-reason-input <?php echo $key == 0 ? 'ultp-active' : ''; ?> <?php echo $setting['id']; ?>"></textarea> | |
| 165 | 155 | <?php } ?> |
| 166 | 156 | </label> |
| 167 | 157 | </li> |
| 168 | 158 | <?php } ?> |
| 169 | - </ul> | |
| 170 | - </div> | |
| 159 | + </ul> | |
| 160 | + </div> | |
| 171 | 161 | |
| 172 | - <div class="ultp-modal-footer"> | |
| 173 | - <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> | |
| 174 | - <a class="ultp-modal-deactive" href="#"><?php esc_html_e( 'Skip & Deactivate', 'ultimate-post' ); ?></a> | |
| 162 | + <div class="ultp-modal-footer"> | |
| 163 | + <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> | |
| 164 | + <a class="ultp-modal-deactive" href="#"><?php _e( "Skip & Deactivate", "ultimate-post" ); ?></a> | |
| 175 | 165 | </div> |
| 176 | 166 | |
| 177 | - </div> | |
| 178 | - </div> | |
| 179 | - <?php | |
| 180 | - } | |
| 167 | + </div> | |
| 168 | + </div> | |
| 169 | + <?php } | |
| 181 | 170 | |
| 182 | - /** | |
| 183 | - * Output deactivation forms CSS. | |
| 184 | - * | |
| 185 | - * @since v.1.0.0 | |
| 186 | - * @return void No return value. | |
| 187 | - */ | |
| 188 | - public function deactive_container_css() { | |
| 189 | - ?> | |
| 171 | + public function deactive_css() { ?> | |
| 190 | 172 | <style type="text/css"> |
| 191 | 173 | .ultp-modal { |
| 192 | - position: fixed; | |
| 193 | - z-index: 99999; | |
| 194 | - top: 0; | |
| 195 | - right: 0; | |
| 196 | - bottom: 0; | |
| 197 | - left: 0; | |
| 198 | - background: rgba(0,0,0,0.5); | |
| 199 | - display: none; | |
| 200 | - box-sizing: border-box; | |
| 201 | - overflow: scroll; | |
| 202 | - } | |
| 203 | - .ultp-modal * { | |
| 204 | - box-sizing: border-box; | |
| 205 | - } | |
| 206 | - .ultp-modal.modal-active { | |
| 207 | - display: block; | |
| 208 | - } | |
| 174 | + position: fixed; | |
| 175 | + z-index: 99999; | |
| 176 | + top: 0; | |
| 177 | + right: 0; | |
| 178 | + bottom: 0; | |
| 179 | + left: 0; | |
| 180 | + background: rgba(0,0,0,0.5); | |
| 181 | + display: none; | |
| 182 | + box-sizing: border-box; | |
| 183 | + overflow: scroll; | |
| 184 | + } | |
| 185 | + .ultp-modal * { | |
| 186 | + box-sizing: border-box; | |
| 187 | + } | |
| 188 | + .ultp-modal.modal-active { | |
| 189 | + display: block; | |
| 190 | + } | |
| 209 | 191 | .ultp-modal-wrap { |
| 210 | - max-width: 870px; | |
| 211 | - width: 100%; | |
| 212 | - position: relative; | |
| 213 | - margin: 10% auto; | |
| 214 | - background: #fff; | |
| 215 | - } | |
| 192 | + max-width: 870px; | |
| 193 | + width: 100%; | |
| 194 | + position: relative; | |
| 195 | + margin: 10% auto; | |
| 196 | + background: #fff; | |
| 197 | + } | |
| 216 | 198 | .ultp-reason-input{ |
| 217 | 199 | display: none; |
| 218 | 200 | } |
| 219 | 201 | .ultp-reason-input.ultp-active{ |
| @@ -336,11 +318,11 @@ | ||
| 336 | 318 | text-decoration: none; |
| 337 | 319 | } |
| 338 | 320 | .wpxpo-btn-tracking-notice { |
| 339 | 321 | display: flex; |
| 340 | - align-items: center; | |
| 341 | - flex-wrap: wrap; | |
| 342 | - padding: 5px 0; | |
| 322 | + align-items: center; | |
| 323 | + flex-wrap: wrap; | |
| 324 | + padding: 5px 0; | |
| 343 | 325 | } |
| 344 | 326 | .wpxpo-btn-tracking-notice .wpxpo-btn-tracking { |
| 345 | 327 | margin: 0 5px; |
| 346 | 328 | text-decoration: none; |
| @@ -345,20 +327,12 @@ | ||
| 345 | 327 | margin: 0 5px; |
| 346 | 328 | text-decoration: none; |
| 347 | 329 | } |
| 348 | 330 | </style> |
| 349 | - <?php | |
| 350 | - } | |
| 331 | + <?php } | |
| 351 | 332 | |
| 352 | - /** | |
| 353 | - * Output deactivation forms JS. | |
| 354 | - * | |
| 355 | - * @since v.1.0.0 | |
| 356 | - * @return void No return value. | |
| 357 | - */ | |
| 358 | - public function deactive_container_js() { | |
| 359 | - ?> | |
| 360 | - <script type="text/javascript"> | |
| 333 | + public function deactive_js() { ?> | |
| 334 | + <script type="text/javascript"> | |
| 361 | 335 | jQuery( document ).ready( function( $ ) { |
| 362 | 336 | 'use strict'; |
| 363 | 337 | |
| 364 | 338 | // Modal Radio Input Click Action |
| @@ -379,8 +353,26 @@ | ||
| 379 | 353 | $( '.ultp-modal-deactive' ).attr( 'href', $(this).attr('href') ); |
| 380 | 354 | $( '.ultp-modal-submit' ).attr( 'href', $(this).attr('href') ); |
| 381 | 355 | }); |
| 382 | 356 | |
| 357 | + // Checking Tracking | |
| 358 | + $( document ).on( 'click', '.wpxpo-btn-tracking', function(e) { | |
| 359 | + e.preventDefault(); | |
| 360 | + const that = $(this) | |
| 361 | + that.parents('.is-dismissible').hide("fast", function() { that.parents('.is-dismissible').remove(); }); | |
| 362 | + $.ajax({ | |
| 363 | + url: '<?php echo admin_url('admin-ajax.php'); ?>', | |
| 364 | + type: 'POST', | |
| 365 | + data: { | |
| 366 | + action: 'ultp_tracking', | |
| 367 | + type: that.data('type') | |
| 368 | + }, | |
| 369 | + success: function (data) { | |
| 370 | + that.closest('.notice').hide(); | |
| 371 | + } | |
| 372 | + }); | |
| 373 | + }); | |
| 374 | + | |
| 383 | 375 | // Submit to Remote Server |
| 384 | 376 | $( document ).on( 'click', '.ultp-modal-submit', function(e) { |
| 385 | 377 | e.preventDefault(); |
| 386 | 378 | |
| @@ -387,9 +379,9 @@ | ||
| 387 | 379 | $(this).addClass('loading'); |
| 388 | 380 | const url = $(this).attr('href') |
| 389 | 381 | |
| 390 | 382 | $.ajax({ |
| 391 | - url: '<?php echo esc_url( admin_url( 'admin-ajax.php' ) ); ?>', | |
| 383 | + url: '<?php echo admin_url('admin-ajax.php'); ?>', | |
| 392 | 384 | type: 'POST', |
| 393 | 385 | data: { |
| 394 | 386 | action: 'ultp_deactive_plugin', |
| 395 | 387 | cause_id: $('input[type=radio]:checked').attr('id'), |
| @@ -398,8 +390,9 @@ | ||
| 398 | 390 | }, |
| 399 | 391 | success: function (data) { |
| 400 | 392 | $( '#ultp-deactive-modal' ).removeClass( 'modal-active' ); |
| 401 | 393 | window.location.href = url; |
| 394 | + // that.parents('.wc-install').hide("slow", function() { that.parents('.wc-install').remove(); }); | |
| 402 | 395 | }, |
| 403 | 396 | error: function(xhr) { |
| 404 | 397 | console.log( 'Error occured. Please try again' + xhr.statusText + xhr.responseText ); |
| 405 | 398 | }, |
| @@ -408,135 +401,111 @@ | ||
| 408 | 401 | }); |
| 409 | 402 | |
| 410 | 403 | }); |
| 411 | 404 | </script> |
| 412 | - <?php | |
| 413 | - } | |
| 405 | + <?php } | |
| 414 | 406 | |
| 415 | 407 | |
| 416 | - /** | |
| 417 | - * Get all the installed plugin data. | |
| 418 | - * | |
| 419 | - * @since v.1.0.0 | |
| 420 | - * @return ARRAY Plugin information. | |
| 421 | - */ | |
| 422 | - public function get_installed_plugins() { | |
| 408 | + public function get_plugins(){ | |
| 423 | 409 | if ( ! function_exists( 'get_plugins' ) ) { |
| 424 | - include ABSPATH . '/wp-admin/includes/plugin.php'; | |
| 425 | - } | |
| 410 | + include ABSPATH . '/wp-admin/includes/plugin.php'; | |
| 411 | + } | |
| 426 | 412 | |
| 427 | - $active = array(); | |
| 428 | - $inactive = array(); | |
| 429 | - $all_plugins = get_plugins(); | |
| 430 | - $active_plugins = get_option( 'active_plugins', array() ); | |
| 431 | - if ( is_multisite() ) { | |
| 432 | - $active_plugins = array_merge( $active_plugins, array_keys( get_site_option( 'active_sitewide_plugins', array() ) ) ); | |
| 433 | - } | |
| 413 | + $active = array(); | |
| 414 | + $inactive = array(); | |
| 415 | + $all_plugins = get_plugins(); | |
| 416 | + $active_plugins = get_option( 'active_plugins', array() ); | |
| 434 | 417 | |
| 435 | - foreach ( $all_plugins as $key => $plugin ) { | |
| 418 | + foreach ( $all_plugins as $key => $plugin ) { | |
| 436 | 419 | $arr = array(); |
| 437 | - | |
| 438 | - $arr['name'] = isset( $plugin['Name'] ) ? $plugin['Name'] : ''; | |
| 439 | - $arr['url'] = isset( $plugin['PluginURI'] ) ? $plugin['PluginURI'] : ''; | |
| 440 | - $arr['author'] = isset( $plugin['Author'] ) ? $plugin['Author'] : ''; | |
| 420 | + | |
| 421 | + $arr['name'] = isset( $plugin['Name'] ) ? $plugin['Name'] : ''; | |
| 422 | + $arr['url'] = isset( $plugin['PluginURI'] ) ? $plugin['PluginURI'] : ''; | |
| 423 | + $arr['author'] = isset( $plugin['Author'] ) ? $plugin['Author'] : ''; | |
| 441 | 424 | $arr['version'] = isset( $plugin['Version'] ) ? $plugin['Version'] : ''; |
| 442 | 425 | |
| 443 | - if ( in_array( $key, $active_plugins ) ) { | |
| 444 | - $active[ $key ] = $arr; | |
| 426 | + if ( in_array( $key, $active_plugins ) ){ | |
| 427 | + $active[$key] = $arr; | |
| 445 | 428 | } else { |
| 446 | - $inactive[ $key ] = $arr; | |
| 429 | + $inactive[$key] = $arr; | |
| 447 | 430 | } |
| 448 | 431 | } |
| 449 | 432 | |
| 450 | - return array( | |
| 451 | - 'active' => $active, | |
| 452 | - 'inactive' => $inactive, | |
| 453 | - ); | |
| 433 | + return array( 'active' => $active, 'inactive' => $inactive ); | |
| 454 | 434 | } |
| 455 | 435 | |
| 456 | - /** | |
| 457 | - * Get all the installed themes. | |
| 458 | - * | |
| 459 | - * @since v.1.0.0 | |
| 460 | - * @return ARRAY Theme information. | |
| 461 | - */ | |
| 462 | - public function get_installed_themes() { | |
| 436 | + | |
| 437 | + public function get_themes() { | |
| 463 | 438 | $theme_data = array(); |
| 464 | - $all_themes = wp_get_themes(); | |
| 439 | + $all_themes = wp_get_themes(); | |
| 465 | 440 | |
| 466 | - if ( is_array( $all_themes ) ) { | |
| 467 | - foreach ( $all_themes as $key => $theme ) { | |
| 468 | - $attr = array(); | |
| 469 | - $attr['name'] = $theme->Name; | |
| 470 | - $attr['url'] = $theme->ThemeURI; | |
| 471 | - $attr['author'] = $theme->Author; | |
| 472 | - $attr['version'] = $theme->Version; | |
| 473 | - $theme_data[ $key ] = $attr; | |
| 441 | + if(is_array($all_themes)){ | |
| 442 | + foreach ($all_themes as $key => $theme) { | |
| 443 | + $attr = array(); | |
| 444 | + $attr['name'] = $theme->Name; | |
| 445 | + $attr['url'] = $theme->ThemeURI; | |
| 446 | + $attr['author'] = $theme->Author; | |
| 447 | + $attr['version'] = $theme->Version; | |
| 448 | + $theme_data[$key] = $attr; | |
| 474 | 449 | } |
| 475 | 450 | } |
| 451 | + | |
| 476 | 452 | return $theme_data; |
| 477 | 453 | } |
| 478 | 454 | |
| 479 | - /** | |
| 480 | - * Get current user IP address. | |
| 481 | - * | |
| 482 | - * @since v.1.0.0 | |
| 483 | - * @return STRING IP address. | |
| 484 | - */ | |
| 455 | + | |
| 485 | 456 | public function get_user_ip() { |
| 486 | 457 | $response = wp_remote_get( 'https://icanhazip.com/' ); |
| 487 | - if ( is_wp_error( $response ) ) { | |
| 488 | - return ''; | |
| 489 | - } else { | |
| 458 | + | |
| 459 | + if ( is_wp_error( $response ) ) { | |
| 460 | + return ''; | |
| 461 | + } else { | |
| 490 | 462 | $user_ip = trim( wp_remote_retrieve_body( $response ) ); |
| 491 | 463 | return filter_var( $user_ip, FILTER_VALIDATE_IP ) ? $user_ip : ''; |
| 492 | 464 | } |
| 493 | - } | |
| 465 | + } | |
| 494 | 466 | |
| 495 | - /** | |
| 496 | - * Get all the collected data for deactivation. | |
| 497 | - * | |
| 498 | - * @since v.1.0.0 | |
| 499 | - * @return ARRAY All send data. | |
| 500 | - */ | |
| 501 | - public function get_required_data() { | |
| 467 | + | |
| 468 | + public function get_data() { | |
| 502 | 469 | global $wpdb; |
| 503 | - $user = wp_get_current_user(); | |
| 504 | - $user_count = count_users(); | |
| 505 | - $plugins_data = $this->get_installed_plugins(); | |
| 470 | + $user = wp_get_current_user(); | |
| 471 | + $user_count = count_users(); | |
| 472 | + $plugins_data = $this->get_plugins(); | |
| 506 | 473 | |
| 507 | 474 | $data = array( |
| 508 | - 'name' => get_bloginfo( 'name' ), | |
| 509 | - 'home' => esc_url( home_url() ), | |
| 510 | - 'admin_email' => $user->user_email, | |
| 511 | - 'first_name' => isset( $user->user_firstname ) ? $user->user_firstname : '', | |
| 512 | - 'last_name' => isset( $user->user_lastname ) ? $user->user_lastname : '', | |
| 513 | - 'display_name' => $user->display_name, | |
| 514 | - 'wordpress' => get_bloginfo( 'version' ), | |
| 515 | - 'memory_limit' => WP_MEMORY_LIMIT, | |
| 516 | - 'debug_mode' => ( defined( 'WP_DEBUG' ) && WP_DEBUG ) ? 'Yes' : 'No', | |
| 517 | - 'locale' => get_locale(), | |
| 518 | - 'multisite' => is_multisite() ? 'Yes' : 'No', | |
| 475 | + 'name' => get_bloginfo( 'name' ), | |
| 476 | + 'home' => esc_url( home_url() ), | |
| 477 | + 'admin_email' => $user->user_email, | |
| 478 | + 'first_name' => isset($user->user_firstname) ? $user->user_firstname : '', | |
| 479 | + 'last_name' => isset($user->user_lastname) ? $user->user_lastname : '', | |
| 480 | + 'display_name' => $user->display_name, | |
| 481 | + 'wordpress' => get_bloginfo( 'version' ), | |
| 482 | + 'memory_limit' => WP_MEMORY_LIMIT, | |
| 483 | + 'debug_mode' => ( defined('WP_DEBUG') && WP_DEBUG ) ? 'Yes' : 'No', | |
| 484 | + 'locale' => get_locale(), | |
| 485 | + 'multisite' => is_multisite() ? 'Yes' : 'No', | |
| 519 | 486 | |
| 520 | - 'themes' => $this->get_installed_themes(), | |
| 521 | - 'active_theme' => get_stylesheet(), | |
| 522 | - 'users' => isset( $user_count['total_users'] ) ? $user_count['total_users'] : 0, | |
| 523 | - 'active_plugins' => $plugins_data['active'], | |
| 487 | + 'themes' => $this->get_themes(), | |
| 488 | + 'active_theme' => get_stylesheet(), | |
| 489 | + 'users' => isset($user_count['total_users']) ? $user_count['total_users'] : 0, | |
| 490 | + 'active_plugins' => $plugins_data['active'], | |
| 524 | 491 | 'inactive_plugins' => $plugins_data['inactive'], |
| 525 | - 'server' => isset( $_SERVER['SERVER_SOFTWARE'] ) ? sanitize_key( $_SERVER['SERVER_SOFTWARE'] ) : '', | |
| 492 | + 'server' => isset( $_SERVER['SERVER_SOFTWARE'] ) ? $_SERVER['SERVER_SOFTWARE'] : '', | |
| 493 | + | |
| 494 | + 'timezone' => date_default_timezone_get(), | |
| 495 | + 'php_curl' => function_exists( 'curl_init' ) ? 'Yes' : 'No', | |
| 496 | + 'php_version' => function_exists('phpversion') ? phpversion() : '', | |
| 497 | + 'upload_size' => size_format( wp_max_upload_size() ), | |
| 498 | + 'mysql_version' => $wpdb->db_version(), | |
| 499 | + 'php_fsockopen' => function_exists( 'fsockopen' ) ? 'Yes' : 'No', | |
| 526 | 500 | |
| 527 | - 'timezone' => date_default_timezone_get(), | |
| 528 | - 'php_curl' => function_exists( 'curl_init' ) ? 'Yes' : 'No', | |
| 529 | - 'php_version' => function_exists( 'phpversion' ) ? phpversion() : '', | |
| 530 | - 'upload_size' => size_format( wp_max_upload_size() ), | |
| 531 | - 'mysql_version' => $wpdb->db_version(), | |
| 532 | - 'php_fsockopen' => function_exists( 'fsockopen' ) ? 'Yes' : 'No', | |
| 533 | - | |
| 534 | - 'ip' => $this->get_user_ip(), | |
| 535 | - 'plugin_name' => $this->PLUGIN_NAME, | |
| 536 | - 'plugin_version' => $this->PLUGIN_VERSION, | |
| 537 | - 'plugin_slug' => $this->PLUGIN_SLUG, | |
| 501 | + 'ip' => $this->get_user_ip(), | |
| 502 | + 'plugin_name' => $this->PLUGIN_NAME, | |
| 503 | + 'plugin_version' => $this->PLUGIN_VERSION, | |
| 504 | + 'plugin_slug' => $this->PLUGIN_SLUG | |
| 538 | 505 | ); |
| 539 | 506 | |
| 540 | 507 | return $data; |
| 541 | 508 | } |
| 542 | -} | |
| 509 | + | |
| 510 | + | |
| 511 | +} | |