css
3 weeks ago
img
3 weeks ago
js
3 weeks ago
partials
3 weeks ago
class-accesscontrol.php
3 weeks ago
class-adv-order-filter.php
3 weeks ago
class-analytics.php
3 weeks ago
class-order-tip-promotion.php
3 weeks ago
class-pi-dtt-labels.php
3 weeks ago
class-pi-dtt-order-table.php
3 weeks ago
conflict-fixer.php
3 weeks ago
menu.php
3 weeks ago
options-accesscontrol.php
3 weeks ago
options-addons.php
3 weeks ago
options-date.php
3 weeks ago
options-limit.php
3 weeks ago
options-pickup.php
3 weeks ago
options-time-slot.php
3 weeks ago
options-time.php
3 weeks ago
options.php
3 weeks ago
class-analytics.php
259 lines
| 1 | <?php |
| 2 | /** |
| 3 | * v1.0.2 |
| 4 | */ |
| 5 | |
| 6 | |
| 7 | if ( ! defined( 'ABSPATH' ) ) exit; |
| 8 | |
| 9 | class Pi_Dtt_Analytics{ |
| 10 | |
| 11 | private $plugin_slug; |
| 12 | private $plugin_path; |
| 13 | private $version; |
| 14 | private $url; |
| 15 | private $plugin_name; |
| 16 | private $enable_tracking; |
| 17 | private $enable_tracking_action; |
| 18 | public function __construct($plugin_name, $plugin_path, $version) { |
| 19 | $this->plugin_name = $plugin_name; |
| 20 | $this->plugin_path = $plugin_path; |
| 21 | |
| 22 | $parts = explode('/', $this->plugin_path); |
| 23 | |
| 24 | $this->plugin_slug = $parts[0]; |
| 25 | |
| 26 | $this->enable_tracking = 'pisol_'.$this->plugin_slug; |
| 27 | $this->enable_tracking_action = 'pisol_'.$this->plugin_slug.'_action'; |
| 28 | |
| 29 | |
| 30 | $this->version = $version; |
| 31 | |
| 32 | $this->url = 'https://www.piwebsolution.com/plugin-tracker/'; |
| 33 | |
| 34 | add_action('admin_enqueue_scripts', array($this, 'enqueue_scripts')); |
| 35 | add_action( 'admin_footer-plugins.php', [ $this, 'print_deactivation_modal' ] ); |
| 36 | add_action('admin_post_pi_handle_deactivation_' . $this->plugin_slug, array($this, 'handle_deactivation_form')); |
| 37 | |
| 38 | add_action('admin_notices', array($this, 'show_tracker_notice')); |
| 39 | |
| 40 | add_action('admin_post_' . $this->enable_tracking_action, array($this, 'handle_tracker_action')); |
| 41 | |
| 42 | } |
| 43 | |
| 44 | public function show_tracker_notice() { |
| 45 | //delete_option($this->enable_tracking); |
| 46 | if (!empty(get_option($this->enable_tracking, ''))) { |
| 47 | return; |
| 48 | } |
| 49 | |
| 50 | $notice = '<div class="notice notice-error is-dismissible">'; |
| 51 | $notice .= '<h4>Help to Improve ' . esc_html($this->plugin_name) . ' plugin</h4>'; |
| 52 | $notice .= '<p>'.__("Hi, your support can make a big difference!", 'conditional-discount-rule-woocommerce').'</p>'; |
| 53 | $notice .= '<p>'.__("We collect only technical data — including the plugin version, WordPress version, WooCommerce version, and site url — solely to improve compatibility and enhance plugin features.", 'conditional-discount-rule-woocommerce').'</p>'; |
| 54 | |
| 55 | $notice .= '<p style="display: flex; justify-content: space-between; margin-top: 10px;">'; |
| 56 | |
| 57 | $notice .= sprintf( |
| 58 | '<a href="%s" class="button">%s</a>', |
| 59 | esc_url(admin_url('admin-post.php?enable=0&action=' . $this->enable_tracking_action)), |
| 60 | __('I Don\'t Help', 'conditional-discount-rule-woocommerce') |
| 61 | ); |
| 62 | $notice .= sprintf( |
| 63 | '<a href="%s" class="button button-primary" style="margin-right:20px; padding-left:30px; padding-right:30px;">%s</a>', |
| 64 | esc_url(admin_url('admin-post.php?enable=1&action=' . $this->enable_tracking_action)), |
| 65 | __('I Will Help', 'conditional-discount-rule-woocommerce') |
| 66 | ); |
| 67 | |
| 68 | $notice .= '</p>'; |
| 69 | $notice .= '</div>'; |
| 70 | //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 71 | echo $notice; |
| 72 | |
| 73 | } |
| 74 | |
| 75 | public function handle_tracker_action() { |
| 76 | if (isset($_GET['enable']) && in_array($_GET['enable'], array('1', '0'))) { |
| 77 | $enable = $_GET['enable'] === '1' ? 'enable' : 'disable'; |
| 78 | update_option($this->enable_tracking, $enable); |
| 79 | $redirect_url = isset($_SERVER['HTTP_REFERER']) ? esc_url_raw($_SERVER['HTTP_REFERER']) : admin_url(); |
| 80 | |
| 81 | if ($enable === 'enable') { |
| 82 | $this->send_activation_data('enable'); |
| 83 | } |
| 84 | |
| 85 | wp_safe_redirect($redirect_url); |
| 86 | exit; |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | public function send_activation_data($action, $message = '') { |
| 91 | |
| 92 | $data = array( |
| 93 | 'plugin_slug' => $this->plugin_slug, |
| 94 | 'version' => $this->version, |
| 95 | 'site_url' => get_site_url(), |
| 96 | 'wp_version' => get_bloginfo('version'), |
| 97 | 'wc_version' => function_exists('WC') ? WC()->version : '', |
| 98 | 'action' => $action, |
| 99 | 'message' => $message, |
| 100 | ); |
| 101 | |
| 102 | // Make the request non-blocking by setting 'blocking' => false |
| 103 | wp_remote_post($this->url, array( |
| 104 | 'body' => wp_json_encode($data), |
| 105 | 'headers' => array('Content-Type' => 'application/json'), |
| 106 | 'blocking' => false, |
| 107 | )); |
| 108 | } |
| 109 | |
| 110 | function enqueue_scripts($hook) { |
| 111 | if ($hook !== 'plugins.php') return; |
| 112 | |
| 113 | $js = ' |
| 114 | jQuery(document).ready(function($) { |
| 115 | var id = "deactivate-'.$this->plugin_slug.'"; |
| 116 | |
| 117 | jQuery(document).on("click", "#"+id, function(e) { |
| 118 | |
| 119 | var href = $(this).attr("href"); |
| 120 | var popup = "#pi-deactivation-reason-'.$this->plugin_slug.'"; |
| 121 | if ($(popup).length) { |
| 122 | e.preventDefault(); |
| 123 | $(popup).show(); |
| 124 | } |
| 125 | }); |
| 126 | |
| 127 | jQuery(document).on("click", "#pi-deactivator-close-'.$this->plugin_slug.'", function(e) { |
| 128 | |
| 129 | var popup = "#pi-deactivation-reason-'.$this->plugin_slug.'"; |
| 130 | if ($(popup).length) { |
| 131 | e.preventDefault(); |
| 132 | $(popup).hide(); |
| 133 | } |
| 134 | }); |
| 135 | |
| 136 | jQuery(document).on("change", "#pi-deact-form-'.esc_attr($this->plugin_slug).' input[name=\'reason_radio\']", function () { |
| 137 | if (jQuery(this).val() === "Other") { |
| 138 | jQuery("#pi-deact-form-'.esc_attr($this->plugin_slug).' textarea").show(); |
| 139 | } else { |
| 140 | jQuery("#pi-deact-form-'.esc_attr($this->plugin_slug).' textarea").hide(); |
| 141 | } |
| 142 | }); |
| 143 | }); |
| 144 | '; |
| 145 | |
| 146 | wp_add_inline_script('jquery', $js); |
| 147 | |
| 148 | // Add the deactivation modal CSS as inline style |
| 149 | $css = '.pi-deactivation-overlay-' . esc_attr($this->plugin_slug) . ' { |
| 150 | display: none; |
| 151 | position: fixed; |
| 152 | top: 0; left: 0; right: 0; bottom: 0; |
| 153 | width: 100%; |
| 154 | height: 100%; |
| 155 | background: rgba(0,0,0,0.5); |
| 156 | z-index: 9999; |
| 157 | } |
| 158 | |
| 159 | .pi-deact-close-' . esc_attr($this->plugin_slug) . ' { |
| 160 | color: #000; |
| 161 | text-decoration: none; |
| 162 | font-size: 20px; |
| 163 | font-weight: bold; |
| 164 | } |
| 165 | |
| 166 | .pi-deactivation-modal-' . esc_attr($this->plugin_slug) . ' { |
| 167 | position: fixed; |
| 168 | top: 50%; |
| 169 | left: 50%; |
| 170 | transform: translate(-50%, -50%); |
| 171 | background: #fff; |
| 172 | padding: 20px; |
| 173 | width: 400px; |
| 174 | max-width: 90%; |
| 175 | max-height: 90%; |
| 176 | overflow: auto; |
| 177 | box-shadow: 0 2px 10px rgba(0,0,0,0.3); |
| 178 | z-index: 10000; |
| 179 | }'; |
| 180 | wp_add_inline_style('wp-admin', $css); |
| 181 | } |
| 182 | |
| 183 | public function print_deactivation_modal() { |
| 184 | $nonce = wp_create_nonce('pi_deactivate_nonce_' . $this->plugin_slug); |
| 185 | ?> |
| 186 | <div id="pi-deactivation-reason-<?php echo esc_attr($this->plugin_slug); ?>" style="display:none;" class="pi-deactivation-overlay-<?php echo esc_attr($this->plugin_slug); ?>"> |
| 187 | <div class="pi-deactivation-modal-<?php echo esc_attr($this->plugin_slug); ?>"> |
| 188 | <a href="javascript:void(0);" id="pi-deactivator-close-<?php echo esc_attr($this->plugin_slug); ?>" class="pi-deact-close-<?php echo esc_attr($this->plugin_slug); ?>" style="position: absolute; top: 10px; right: 10px; z-index: 10001;">×</a> |
| 189 | <form id="pi-deact-form-<?php echo esc_attr($this->plugin_slug); ?>" method="post" action="<?php echo esc_url(admin_url('admin-post.php')); ?>"> |
| 190 | <h3>Help us to improve by giving reason for deactivation:</h3> |
| 191 | <div style="margin-bottom:10px;"> |
| 192 | <label style="margin-bottom:10px; display:block;"><input type="radio" name="reason_radio" value="Was looking for something else"> Was looking for something else</label> |
| 193 | <label style="margin-bottom:10px; display:block;"><input type="radio" name="reason_radio" value="I found a better plugin"> I found a better plugin</label> |
| 194 | <label style="margin-bottom:10px; display:block;"><input type="radio" name="reason_radio" value="The plugin broke my site"> The plugin broke my site</label> |
| 195 | <label style="margin-bottom:10px; display:block;"><input type="radio" name="reason_radio" value="The plugin is not working as expected"> The plugin is not working as expected</label> |
| 196 | <label style="margin-bottom:10px; display:block;"><input type="radio" name="reason_radio" value="Other"> Other (please specify below)</label> |
| 197 | </div> |
| 198 | <textarea id="pi-deact-reason-<?php echo esc_attr($this->plugin_slug); ?>" name="message" style="width:100%; display:none;" rows="4" placeholder="Let us know the reason for deactivation"></textarea> |
| 199 | <?php |
| 200 | // Hidden fields |
| 201 | echo '<input type="hidden" name="action" value="pi_handle_deactivation_' . esc_attr($this->plugin_slug) . '">'; |
| 202 | echo '<input type="hidden" name="plugin_slug" value="' . esc_attr($this->plugin_slug) . '">'; |
| 203 | echo '<input type="hidden" name="nonce" value="' . esc_attr($nonce) . '">'; |
| 204 | ?> |
| 205 | <p style="display: flex; justify-content: space-between; margin-top: 10px;"> |
| 206 | <button type="submit" name="action_type" class="pi-deact-skip button" value="skip">Skip</button> |
| 207 | <button type="submit" class="pi-deact-submit button button-primary" name="action_type" value="submit">Deactivate & Submit</button> |
| 208 | </p> |
| 209 | </form> |
| 210 | </div> |
| 211 | </div> |
| 212 | <?php |
| 213 | } |
| 214 | |
| 215 | public function handle_deactivation_form() { |
| 216 | if (!isset($_POST['nonce']) || !wp_verify_nonce($_POST['nonce'], 'pi_deactivate_nonce_' . $this->plugin_slug)) { |
| 217 | wp_die(esc_html__('Security check failed', 'pisol-dtt')); |
| 218 | } |
| 219 | |
| 220 | $plugin_slug = sanitize_text_field($_POST['plugin_slug'] ?? ''); |
| 221 | $message = sanitize_textarea_field($_POST['message'] ?? ''); |
| 222 | $reason = sanitize_text_field($_POST['reason_radio'] ?? ''); |
| 223 | // Combine reason and message, prioritizing reason if message is empty |
| 224 | if (!empty($reason) && !empty($message)) { |
| 225 | $message = $reason . ': ' . $message; |
| 226 | } elseif (!empty($reason)) { |
| 227 | $message = $reason; |
| 228 | } |
| 229 | |
| 230 | $action_type = sanitize_text_field($_POST['action_type'] ?? ''); |
| 231 | |
| 232 | if (is_multisite() && is_plugin_active_for_network($this->plugin_path)) { |
| 233 | if (is_super_admin()) { |
| 234 | deactivate_plugins($this->plugin_path, false, true); // network-wide |
| 235 | } else { |
| 236 | wp_die(esc_html__('You do not have permission to deactivate a network plugin.', 'pisol-dtt')); |
| 237 | } |
| 238 | } else { |
| 239 | deactivate_plugins($this->plugin_path); // normal |
| 240 | } |
| 241 | |
| 242 | if($action_type === 'submit'){ |
| 243 | $this->send_activation_data('disable', wp_strip_all_tags($message)); |
| 244 | } |
| 245 | |
| 246 | |
| 247 | // Redirect back to plugins page |
| 248 | wp_safe_redirect(admin_url('plugins.php')); |
| 249 | exit; |
| 250 | } |
| 251 | |
| 252 | |
| 253 | } |
| 254 | |
| 255 | new Pi_Dtt_Analytics( |
| 256 | 'WooCommerce Delivery Date & Time Plugin', |
| 257 | 'pi-woocommerce-order-date-time-and-type/pi-woocommerce-order-date-time-and-type.php', |
| 258 | PISOL_DTT_PLUGIN_VERSION |
| 259 | ); |