activation-tracker.php
4 years ago
display-options.php
4 years ago
field-type-settings.php
4 years ago
field.php
4 years ago
filed-validation.php
4 years ago
myaccount-edit-address.php
4 years ago
myaccount-field-processor.php
4 years ago
plugin.php
4 years ago
settings.php
4 years ago
tracker.php
4 years ago
user-meta-checkout.php
4 years ago
user-meta.php
4 years ago
user-profile.php
4 years ago
tracker.php
369 lines
| 1 | <?php |
| 2 | |
| 3 | if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
| 4 | |
| 5 | if ( ! class_exists( 'WPDesk_Flexible_Checkout_Fields_Tracker' ) ) { |
| 6 | class WPDesk_Flexible_Checkout_Fields_Tracker { |
| 7 | |
| 8 | public static $script_version = '11'; |
| 9 | |
| 10 | public function __construct() { |
| 11 | $this->hooks(); |
| 12 | } |
| 13 | |
| 14 | public function hooks() { |
| 15 | add_filter( 'wpdesk_tracker_data', array( $this, 'wpdesk_tracker_data' ), 11 ); |
| 16 | add_filter( 'wpdesk_tracker_notice_screens', array( $this, 'wpdesk_tracker_notice_screens' ) ); |
| 17 | |
| 18 | add_filter( 'plugin_action_links_flexible-checkout-fields/flexible-checkout-fields.php', array( $this, 'plugin_action_links' ) ); |
| 19 | add_action( 'activated_plugin', array( $this, 'activated_plugin' ), 10, 2 ); |
| 20 | } |
| 21 | |
| 22 | public function wpdesk_tracker_data( $data ) { |
| 23 | $sections = array( |
| 24 | 'billing', |
| 25 | 'shipping', |
| 26 | 'order', |
| 27 | 'before_customer_details', |
| 28 | 'after_customer_details', |
| 29 | 'before_checkout_billing_form', |
| 30 | 'after_checkout_billing_form', |
| 31 | 'before_checkout_shipping_form', |
| 32 | 'after_checkout_shipping_form', |
| 33 | 'before_checkout_registration_form', |
| 34 | 'after_checkout_registration_form', |
| 35 | 'before_order_notes', |
| 36 | 'after_order_notes', |
| 37 | 'review_order_before_submit', |
| 38 | 'review_order_after_submit', |
| 39 | ); |
| 40 | $settings_fields = get_option('inspire_checkout_fields_settings', array() ); |
| 41 | if ( ! is_array( $settings_fields ) ) { |
| 42 | $settings_fields = array(); |
| 43 | } |
| 44 | |
| 45 | $plugin_data = [ |
| 46 | 'sections' => $this->get_sections_data( $sections, $settings_fields ), |
| 47 | 'fields_names' => $this->get_fields_names( $settings_fields ), |
| 48 | 'options' => array( |
| 49 | 'css_disable' => get_option( 'inspire_checkout_fields_css_disable', '0' ) |
| 50 | ), |
| 51 | 'pro_version' => array( |
| 52 | 'is_active' => is_flexible_checkout_fields_pro_active() ? '1' : '0', |
| 53 | 'is_activated' => ( get_option( 'api_flexible-checkout-fields-pro_activated', '' ) === 'Activated' ) ? '1' : '0', |
| 54 | ), |
| 55 | ]; |
| 56 | |
| 57 | $data['flexible_checkout_fields'] = $plugin_data; |
| 58 | |
| 59 | return $data; |
| 60 | } |
| 61 | |
| 62 | private function get_fields_names( $settings_fields ) { |
| 63 | $items = array(); |
| 64 | foreach ( $settings_fields as $section_key => $fields ) { |
| 65 | foreach ( $fields as $field_name => $field ) { |
| 66 | $name = str_replace( $section_key . '_', '', $field_name ); |
| 67 | if ( !isset( $items[ $name ] ) ) { |
| 68 | $items[ $name ] = 0; |
| 69 | } |
| 70 | $items[ $name ]++; |
| 71 | } |
| 72 | } |
| 73 | return $items; |
| 74 | } |
| 75 | |
| 76 | private function get_sections_data( $sections, $settings_fields ) { |
| 77 | $settings_sections = get_option('inspire_checkout_fields_section_settings', array() ); |
| 78 | if ( ! is_array( $settings_sections ) ) { |
| 79 | $settings_sections = array(); |
| 80 | } |
| 81 | $default_data = array( |
| 82 | 'enabled' => 0, |
| 83 | 'has_title' => 0, |
| 84 | 'has_css' => 0, |
| 85 | 'fields' => array(), |
| 86 | 'fields_count' => 0, |
| 87 | ); |
| 88 | |
| 89 | $data = array(); |
| 90 | foreach ( $sections as $section ) { |
| 91 | $data[$section] = $default_data; |
| 92 | if ( in_array( $section, array( 'billing', 'shipping', 'order' ) ) |
| 93 | || get_option( 'inspire_checkout_fields_' . $section, '0' ) ) { |
| 94 | $data[$section]['enabled'] = '1'; |
| 95 | } |
| 96 | if ( isset( $settings_sections[ $section ] ) && ! empty( $settings_sections[ $section ]['section_title'] ) ) { |
| 97 | $data[$section]['has_title'] = '1'; |
| 98 | } |
| 99 | if ( isset( $settings_sections[ $section ] ) && ! empty( $settings_sections[ $section ]['section_css'] ) ) { |
| 100 | $data[$section]['has_css'] = '1'; |
| 101 | } |
| 102 | $data[$section]['fields'] = $this->get_fields_data( $section, $settings_fields ); |
| 103 | if ( isset( $settings_fields[ $section ] ) ) { |
| 104 | $data[$section]['fields_count'] = count( $settings_fields[ $section ] ); |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | return $data; |
| 109 | } |
| 110 | |
| 111 | private function get_fields_data( $section, $settings ) { |
| 112 | if ( ! isset( $settings[ $section ] ) ) { |
| 113 | return array(); |
| 114 | } |
| 115 | $default_data = array( |
| 116 | 'count' => 0, |
| 117 | 'enabled' => 0, |
| 118 | 'required' => 0, |
| 119 | 'validation' => array(), |
| 120 | 'default_value' => 0, |
| 121 | 'placeholder' => 0, |
| 122 | 'display_on' => array( |
| 123 | 'thank_you' => 0, |
| 124 | 'on_address' => 0, |
| 125 | 'on_order' => 0, |
| 126 | 'on_emails' => 0, |
| 127 | 'option_new_line_before' => 0, |
| 128 | 'option_show_label' => 0, |
| 129 | ), |
| 130 | 'conditional_logic' => array(), |
| 131 | 'pricing' => array( |
| 132 | 'enabled' => 0, |
| 133 | 'types' => array(), |
| 134 | 'values' => array(), |
| 135 | 'tax_classes' => array(), |
| 136 | ), |
| 137 | ); |
| 138 | |
| 139 | $data = array(); |
| 140 | foreach ( $settings[ $section ] as $field ) { |
| 141 | $field_type = ( isset( $field['type'] ) ) ? $field['type'] : '_null_'; |
| 142 | |
| 143 | if ( ! isset( $data[ $field_type ] ) ) { |
| 144 | $data[ $field_type ] = $default_data; |
| 145 | } |
| 146 | $data[ $field_type ]['count']++; |
| 147 | if ( isset( $field['visible'] ) && ! $field['visible'] ) { |
| 148 | $data[ $field_type ]['enabled']++; |
| 149 | } |
| 150 | if ( isset( $field['required'] ) && $field['required'] ) { |
| 151 | $data[ $field_type ]['required']++; |
| 152 | } |
| 153 | if ( isset( $field['validation'] ) && $field['validation'] ) { |
| 154 | if ( ! isset( $data[ $field_type ]['validation'][ $field['validation'] ] ) ) { |
| 155 | $data[ $field_type ]['validation'][ $field['validation'] ] = 0; |
| 156 | } |
| 157 | $data[ $field_type ]['validation'][ $field['validation'] ]++; |
| 158 | } |
| 159 | if ( isset( $field['default'] ) && $field['default'] ) { |
| 160 | $data[ $field_type ]['default_value']++; |
| 161 | } |
| 162 | if ( isset( $field['placeholder'] ) && $field['placeholder'] ) { |
| 163 | $data[ $field_type ]['placeholder']++; |
| 164 | } |
| 165 | if ( isset( $field['display_on_thank_you'] ) && $field['display_on_thank_you'] ) { |
| 166 | $data[ $field_type ]['display_on']['thank_you']++; |
| 167 | } |
| 168 | if ( isset( $field['display_on_address'] ) && $field['display_on_address'] ) { |
| 169 | $data[ $field_type ]['display_on']['on_address']++; |
| 170 | } |
| 171 | if ( isset( $field['display_on_order'] ) && $field['display_on_order'] ) { |
| 172 | $data[ $field_type ]['display_on']['on_order']++; |
| 173 | } |
| 174 | if ( isset( $field['display_on_emails'] ) && $field['display_on_emails'] ) { |
| 175 | $data[ $field_type ]['display_on']['on_emails']++; |
| 176 | } |
| 177 | if ( isset( $field['display_on_option_new_line_before'] ) && $field['display_on_option_new_line_before'] ) { |
| 178 | $data[ $field_type ]['display_on']['option_new_line_before']++; |
| 179 | } |
| 180 | if ( isset( $field['display_on_option_show_label'] ) && $field['display_on_option_show_label'] ) { |
| 181 | $data[ $field_type ]['display_on']['option_show_label']++; |
| 182 | } |
| 183 | if ( isset( $field['pricing_enabled'] ) && $field['pricing_enabled'] ) { |
| 184 | $data[ $field_type ]['pricing']['enabled']++; |
| 185 | } |
| 186 | if ( isset( $field['pricing_values'] ) && $field['pricing_values'] ) { |
| 187 | foreach ( $field['pricing_values'] as $pricing_value ) { |
| 188 | if ( ! isset( $data[ $field_type ]['pricing']['types'][ $pricing_value['type'] ] ) ) { |
| 189 | $data[ $field_type ]['pricing']['types'][ $pricing_value['type'] ] = 0; |
| 190 | } |
| 191 | $data[ $field_type ]['pricing']['types'][ $pricing_value['type'] ]++; |
| 192 | } |
| 193 | foreach ( $field['pricing_values'] as $pricing_value ) { |
| 194 | if ( ! isset( $data[ $field_type ]['pricing']['values'][ $pricing_value['value'] ] ) ) { |
| 195 | $data[ $field_type ]['pricing']['values'][ $pricing_value['value'] ] = 0; |
| 196 | } |
| 197 | $data[ $field_type ]['pricing']['values'][ $pricing_value['value'] ]++; |
| 198 | } |
| 199 | foreach ( $field['pricing_values'] as $pricing_value ) { |
| 200 | if ( ! isset( $data[ $field_type ]['pricing']['tax_classes'][ $pricing_value['tax_class'] ] ) ) { |
| 201 | $data[ $field_type ]['pricing']['tax_classes'][ $pricing_value['tax_class'] ] = 0; |
| 202 | } |
| 203 | $data[ $field_type ]['pricing']['tax_classes'][ $pricing_value['tax_class'] ]++; |
| 204 | } |
| 205 | } |
| 206 | $data[ $field_type ]['conditional_logic'] = $this->get_conditional_logic_data( |
| 207 | $field, |
| 208 | $data[ $field_type ]['conditional_logic'] |
| 209 | ); |
| 210 | } |
| 211 | |
| 212 | return $data; |
| 213 | } |
| 214 | |
| 215 | private function get_conditional_logic_data( $field, $current_data ) { |
| 216 | $default_data = array( |
| 217 | 'enabled' => 0, |
| 218 | 'action' => array(), |
| 219 | 'operator' => array(), |
| 220 | 'rule_options' => array(), |
| 221 | 'rule_operators' => array(), |
| 222 | ); |
| 223 | |
| 224 | $data = ( $current_data ) |
| 225 | ? $current_data |
| 226 | : array( |
| 227 | 'products' => $default_data, |
| 228 | 'fields' => $default_data, |
| 229 | 'shipping' => $default_data, |
| 230 | ) |
| 231 | ; |
| 232 | |
| 233 | if ( isset( $field['conditional_logic'] ) && $field['conditional_logic'] ) { |
| 234 | $data['products']['enabled']++; |
| 235 | } |
| 236 | if ( isset( $field['conditional_logic_action'] ) && $field['conditional_logic_action'] ) { |
| 237 | if ( ! isset( $data['products']['action'][ $field['conditional_logic_action'] ] ) ) { |
| 238 | $data['products']['action'][ $field['conditional_logic_action'] ] = 0; |
| 239 | } |
| 240 | $data['products']['action'][ $field['conditional_logic_action'] ]++; |
| 241 | } |
| 242 | if ( isset( $field['conditional_logic_operator'] ) && $field['conditional_logic_operator'] ) { |
| 243 | if ( ! isset( $data['products']['operator'][ $field['conditional_logic_operator'] ] ) ) { |
| 244 | $data['products']['operator'][ $field['conditional_logic_operator'] ] = 0; |
| 245 | } |
| 246 | $data['products']['operator'][ $field['conditional_logic_operator'] ]++; |
| 247 | } |
| 248 | if ( isset( $field['conditional_logic_rules'] ) && $field['conditional_logic_rules'] ) { |
| 249 | foreach ( $field['conditional_logic_rules'] as $rule ) { |
| 250 | if ( ! isset( $data['products']['rule_options'][ $rule['condition'] ] ) ) { |
| 251 | $data['products']['rule_options'][ $rule['condition'] ] = 0; |
| 252 | } |
| 253 | $data['products']['rule_options'][ $rule['condition'] ]++; |
| 254 | if ( ! isset( $data['products']['rule_operators'][ $rule['what'] ] ) ) { |
| 255 | $data['products']['rule_operators'][ $rule['what'] ] = 0; |
| 256 | } |
| 257 | $data['products']['rule_operators'][ $rule['what'] ]++; |
| 258 | } |
| 259 | } |
| 260 | |
| 261 | if ( isset( $field['conditional_logic_fields'] ) && $field['conditional_logic_fields'] ) { |
| 262 | $data['fields']['enabled']++; |
| 263 | } |
| 264 | if ( isset( $field['conditional_logic_fields_action'] ) && $field['conditional_logic_fields_action'] ) { |
| 265 | if ( ! isset( $data['fields']['action'][ $field['conditional_logic_fields_action'] ] ) ) { |
| 266 | $data['fields']['action'][ $field['conditional_logic_fields_action'] ] = 0; |
| 267 | } |
| 268 | $data['fields']['action'][ $field['conditional_logic_fields_action'] ]++; |
| 269 | } |
| 270 | if ( isset( $field['conditional_logic_fields_operator'] ) && $field['conditional_logic_fields_operator'] ) { |
| 271 | if ( ! isset( $data['fields']['operator'][ $field['conditional_logic_fields_operator'] ] ) ) { |
| 272 | $data['fields']['operator'][ $field['conditional_logic_fields_operator'] ] = 0; |
| 273 | } |
| 274 | $data['fields']['operator'][ $field['conditional_logic_fields_operator'] ]++; |
| 275 | } |
| 276 | if ( isset( $field['conditional_logic_fields_rules'] ) && $field['conditional_logic_fields_rules'] ) { |
| 277 | foreach ( $field['conditional_logic_fields_rules'] as $rule ) { |
| 278 | if ( ! isset( $data['fields']['rule_operators'][ $rule['condition'] ] ) ) { |
| 279 | $data['fields']['rule_operators'][ $rule['condition'] ] = 0; |
| 280 | } |
| 281 | $data['fields']['rule_operators'][ $rule['condition'] ]++; |
| 282 | } |
| 283 | } |
| 284 | |
| 285 | if ( isset( $field['conditional_logic_shipping_fields'] ) && $field['conditional_logic_shipping_fields'] ) { |
| 286 | $data['shipping']['enabled']++; |
| 287 | } |
| 288 | if ( isset( $field['conditional_logic_shipping_fields_action'] ) && $field['conditional_logic_shipping_fields_action'] ) { |
| 289 | if ( ! isset( $data['shipping']['action'][ $field['conditional_logic_shipping_fields_action'] ] ) ) { |
| 290 | $data['shipping']['action'][ $field['conditional_logic_shipping_fields_action'] ] = 0; |
| 291 | } |
| 292 | $data['shipping']['action'][ $field['conditional_logic_shipping_fields_action'] ]++; |
| 293 | } |
| 294 | if ( isset( $field['conditional_logic_shipping_fields_operator'] ) && $field['conditional_logic_shipping_fields_operator'] ) { |
| 295 | if ( ! isset( $data['shipping']['operator'][ $field['conditional_logic_shipping_fields_operator'] ] ) ) { |
| 296 | $data['shipping']['operator'][ $field['conditional_logic_shipping_fields_operator'] ] = 0; |
| 297 | } |
| 298 | $data['shipping']['operator'][ $field['conditional_logic_shipping_fields_operator'] ]++; |
| 299 | } |
| 300 | |
| 301 | return $data; |
| 302 | } |
| 303 | |
| 304 | public function wpdesk_tracker_notice_screens( $screens ) { |
| 305 | $current_screen = get_current_screen(); |
| 306 | if ( $current_screen->id == 'woocommerce_page_inspire_checkout_fields_settings' ) { |
| 307 | $screens[] = $current_screen->id; |
| 308 | } |
| 309 | return $screens; |
| 310 | } |
| 311 | |
| 312 | public function plugin_action_links( $links ) { |
| 313 | if ( !wpdesk_tracker_enabled() || apply_filters( 'wpdesk_tracker_do_not_ask', false ) ) { |
| 314 | return $links; |
| 315 | } |
| 316 | $options = get_option('wpdesk_helper_options', array() ); |
| 317 | if ( !is_array( $options )) { |
| 318 | $options = array(); |
| 319 | } |
| 320 | if ( empty( $options['wpdesk_tracker_agree'] ) ) { |
| 321 | $options['wpdesk_tracker_agree'] = '0'; |
| 322 | } |
| 323 | $plugin_links = array(); |
| 324 | if ( $options['wpdesk_tracker_agree'] == '0' ) { |
| 325 | $opt_in_link = admin_url( 'admin.php?page=wpdesk_tracker&plugin=flexible-checkout-fields/flexible-checkout-fields.php' ); |
| 326 | $plugin_links[] = '<a href="' . $opt_in_link . '">' . __( 'Opt-in', 'flexible-checkout-fields' ) . '</a>'; |
| 327 | } |
| 328 | else { |
| 329 | $opt_in_link = admin_url( 'plugins.php?wpdesk_tracker_opt_out=1&plugin=flexible-checkout-fields/flexible-checkout-fields.php' ); |
| 330 | $plugin_links[] = '<a href="' . $opt_in_link . '">' . __( 'Opt-out', 'flexible-checkout-fields' ) . '</a>'; |
| 331 | } |
| 332 | return array_merge( $plugin_links, $links ); |
| 333 | } |
| 334 | |
| 335 | public function activated_plugin( $plugin, $network_wide ) { |
| 336 | if ( $network_wide ) { |
| 337 | return; |
| 338 | } |
| 339 | if ( defined( 'WP_CLI' ) && WP_CLI ) { |
| 340 | return; |
| 341 | } |
| 342 | if ( !wpdesk_tracker_enabled() ) { |
| 343 | return; |
| 344 | } |
| 345 | if ( $plugin == 'flexible-checkout-fields/flexible-checkout-fields.php' ) { |
| 346 | $options = get_option('wpdesk_helper_options', array() ); |
| 347 | |
| 348 | if ( empty( $options ) ) { |
| 349 | $options = array(); |
| 350 | } |
| 351 | if ( empty( $options['wpdesk_tracker_agree'] ) ) { |
| 352 | $options['wpdesk_tracker_agree'] = '0'; |
| 353 | } |
| 354 | $wpdesk_tracker_skip_plugin = get_option( 'wpdesk_tracker_skip_flexible_checkout_fields', '0' ); |
| 355 | if ( $options['wpdesk_tracker_agree'] == '0' && $wpdesk_tracker_skip_plugin == '0' ) { |
| 356 | update_option( 'wpdesk_tracker_notice', '1' ); |
| 357 | update_option( 'wpdesk_tracker_skip_flexible_checkout_fields', '1' ); |
| 358 | if ( !apply_filters( 'wpdesk_tracker_do_not_ask', false ) ) { |
| 359 | wp_redirect( admin_url( 'admin.php?page=wpdesk_tracker&plugin=flexible-checkout-fields/flexible-checkout-fields.php' ) ); |
| 360 | exit; |
| 361 | } |
| 362 | } |
| 363 | } |
| 364 | } |
| 365 | |
| 366 | } |
| 367 | |
| 368 | } |
| 369 |