views
6 years ago
activation-tracker.php
6 years ago
class-flexible-checkout-fields-plugin.php
6 years ago
display-options.php
6 years ago
field-options.php
6 years ago
field.php
6 years ago
filed-validation.php
6 years ago
index.php
6 years ago
myaccount-edit-address.php
6 years ago
myaccount-filed-processor.php
6 years ago
settings.php
6 years ago
tracker.php
6 years ago
user-profile.php
6 years ago
tracker.php
235 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 | add_filter( 'wpdesk_track_plugin_deactivation', array( $this, 'wpdesk_track_plugin_deactivation' ) ); |
| 18 | |
| 19 | add_filter( 'plugin_action_links_flexible-checkout-fields/flexible-checkout-fields.php', array( $this, 'plugin_action_links' ) ); |
| 20 | add_action( 'activated_plugin', array( $this, 'activated_plugin' ), 10, 2 ); |
| 21 | } |
| 22 | |
| 23 | public function wpdesk_track_plugin_deactivation( $plugins ) { |
| 24 | $plugins['flexible-checkout-fields/flexible-checkout-fields.php'] = 'flexible-checkout-fields/flexible-checkout-fields.php'; |
| 25 | return $plugins; |
| 26 | } |
| 27 | |
| 28 | public function wpdesk_tracker_data( $data ) { |
| 29 | $plugin_data = array( |
| 30 | 'fields' => array(), |
| 31 | 'custom_sections' => array(), |
| 32 | 'validation' => array(), |
| 33 | 'display_on_unchecked' => 0, |
| 34 | 'conditional_logic_for_fields' => 0, |
| 35 | 'conditional_logic_fields_action' => array(), |
| 36 | 'conditional_logic_fields_operator' => array(), |
| 37 | 'conditional_logic_for_fields_rules' => 0, |
| 38 | 'conditional_logic' => 0, |
| 39 | 'conditional_logic_what' => array(), |
| 40 | 'conditional_logic_action' => array(), |
| 41 | 'conditional_logic_operator' => array(), |
| 42 | 'conditional_logic_rules' => 0, |
| 43 | ); |
| 44 | |
| 45 | if ( is_flexible_checkout_fields_pro_active() ) { |
| 46 | $plugin_data['pro'] = 'yes'; |
| 47 | } |
| 48 | else { |
| 49 | $plugin_data['pro'] = 'no'; |
| 50 | } |
| 51 | |
| 52 | $settings = get_option('inspire_checkout_fields_settings', array() ); |
| 53 | if ( !is_array( $settings )) { |
| 54 | $settings = array(); |
| 55 | } |
| 56 | foreach ( $settings as $section => $fields ) { |
| 57 | if ( !is_array( $fields ) ) { |
| 58 | continue; |
| 59 | } |
| 60 | foreach ( $fields as $field ) { |
| 61 | if ( isset( $field['conditional_logic_fields'] ) ) { |
| 62 | $plugin_data['conditional_logic_for_fields']++; |
| 63 | if ( empty( $plugin_data['conditional_logic_fields_action'][$field['conditional_logic_fields_action']] ) ) { |
| 64 | $plugin_data['conditional_logic_fields_action'][$field['conditional_logic_fields_action']] = 0; |
| 65 | } |
| 66 | $plugin_data['conditional_logic_fields_action'][$field['conditional_logic_fields_action']]++; |
| 67 | if ( empty( $plugin_data['conditional_logic_fields_operator'][$field['conditional_logic_fields_operator']] ) ) { |
| 68 | $plugin_data['conditional_logic_fields_operator'][$field['conditional_logic_fields_operator']] = 0; |
| 69 | } |
| 70 | $plugin_data['conditional_logic_fields_operator'][$field['conditional_logic_fields_operator']]++; |
| 71 | if ( isset( $field['conditional_logic_fields_rules'] ) ) { |
| 72 | $plugin_data['conditional_logic_for_fields_rules'] = $plugin_data['conditional_logic_for_fields_rules'] + count( $field['conditional_logic_fields_rules'] ); |
| 73 | } |
| 74 | } |
| 75 | if ( isset( $field['conditional_logic'] ) ) { |
| 76 | $plugin_data['conditional_logic']++; |
| 77 | if ( empty( $plugin_data['conditional_logic_action'][$field['conditional_logic_action']] ) ) { |
| 78 | $plugin_data['conditional_logic_action'][$field['conditional_logic_action']] = 0; |
| 79 | } |
| 80 | $plugin_data['conditional_logic_action'][$field['conditional_logic_action']]++; |
| 81 | if ( empty( $plugin_data['conditional_logic_operator'][$field['conditional_logic_operator']] ) ) { |
| 82 | $plugin_data['conditional_logic_operator'][$field['conditional_logic_operator']] = 0; |
| 83 | } |
| 84 | $plugin_data['conditional_logic_operator'][$field['conditional_logic_operator']]++; |
| 85 | if ( isset( $field['conditional_logic_rules'] ) ) { |
| 86 | $plugin_data['conditional_logic_rules'] = $plugin_data['conditional_logic_rules'] + count( $field['conditional_logic_rules'] ); |
| 87 | foreach ( $field['conditional_logic_rules'] as $rule ) { |
| 88 | if ( !isset( $plugin_data['conditional_logic_what'][$rule['what']] ) ) { |
| 89 | $plugin_data['conditional_logic_what'][$rule['what']] = 0; |
| 90 | } |
| 91 | $plugin_data['conditional_logic_what'][$rule['what']]++; |
| 92 | } |
| 93 | } |
| 94 | } |
| 95 | if ( isset( $field['custom_field'] ) && $field['custom_field'] == '1' ) { |
| 96 | if ( isset( $field['type'] ) ) { |
| 97 | if ( empty( $plugin_data['fields'][$field['type']] ) ) { |
| 98 | $plugin_data['fields'][$field['type']] = 0; |
| 99 | } |
| 100 | $plugin_data['fields'][$field['type']]++; |
| 101 | } |
| 102 | } |
| 103 | if ( isset( $field['display_on_thank_you'] ) && $field['display_on_thank_you'] == '0' ) { |
| 104 | $plugin_data['display_on_unchecked']++; |
| 105 | } |
| 106 | if ( isset( $field['display_on_address'] ) && $field['display_on_address'] == '0' ) { |
| 107 | $plugin_data['display_on_unchecked']++; |
| 108 | } |
| 109 | if ( isset( $field['display_on_order'] ) && $field['display_on_order'] == '0' ) { |
| 110 | $plugin_data['display_on_unchecked']++; |
| 111 | } |
| 112 | if ( isset( $field['display_on_emails'] ) && $field['display_on_emails'] == '0' ) { |
| 113 | $plugin_data['display_on_unchecked']++; |
| 114 | } |
| 115 | if ( isset( $field['validation'] ) && $field['validation'] != '' ) { |
| 116 | if ( !isset( $plugin_data['validation'][$field['validation']] ) ) { |
| 117 | $plugin_data['validation'][$field['validation']] = 0; |
| 118 | } |
| 119 | $plugin_data['validation'][$field['validation']]++; |
| 120 | } |
| 121 | } |
| 122 | } |
| 123 | |
| 124 | $plugin_data['inspire_checkout_fields_css_disable'] = get_option( 'inspire_checkout_fields_css_disable', '0' ); |
| 125 | |
| 126 | $plugin_data['custom_sections']['before_customer_details'] = get_option( 'inspire_checkout_fields_before_customer_details', '0' ); |
| 127 | $plugin_data['custom_sections']['after_customer_details'] = get_option( 'inspire_checkout_fields_after_customer_details', '0' ); |
| 128 | $plugin_data['custom_sections']['before_checkout_billing_form'] = get_option( 'inspire_checkout_fields_before_checkout_billing_form', '0' ); |
| 129 | $plugin_data['custom_sections']['after_checkout_billing_form'] = get_option( 'inspire_checkout_fields_after_checkout_billing_form', '0' ); |
| 130 | $plugin_data['custom_sections']['before_checkout_shipping_form'] = get_option( 'inspire_checkout_fields_before_checkout_shipping_form', '0' ); |
| 131 | $plugin_data['custom_sections']['after_checkout_shipping_form'] = get_option( 'inspire_checkout_fields_after_checkout_shipping_form', '0' ); |
| 132 | $plugin_data['custom_sections']['before_checkout_registration_form'] = get_option( 'inspire_checkout_fields_before_checkout_registration_form', '0' ); |
| 133 | $plugin_data['custom_sections']['after_checkout_registration_form'] = get_option( 'inspire_checkout_fields_after_checkout_registration_form', '0' ); |
| 134 | $plugin_data['custom_sections']['before_order_notes'] = get_option( 'inspire_checkout_fields_before_order_notes', '0' ); |
| 135 | $plugin_data['custom_sections']['after_order_notes'] = get_option( 'inspire_checkout_fields_after_order_notes', '0' ); |
| 136 | $plugin_data['custom_sections']['review_order_before_submit'] = get_option( 'inspire_checkout_fields_review_order_before_submit', '0' ); |
| 137 | $plugin_data['custom_sections']['review_order_after_submit'] = get_option( 'inspire_checkout_fields_review_order_after_submit', '0' ); |
| 138 | |
| 139 | $data['flexible_checkout_fields'] = $plugin_data; |
| 140 | |
| 141 | return $data; |
| 142 | } |
| 143 | |
| 144 | public function wpdesk_tracker_notice_screens( $screens ) { |
| 145 | $current_screen = get_current_screen(); |
| 146 | if ( $current_screen->id == 'woocommerce_page_inspire_checkout_fields_settings' ) { |
| 147 | $screens[] = $current_screen->id; |
| 148 | } |
| 149 | return $screens; |
| 150 | } |
| 151 | |
| 152 | public function plugin_action_links( $links ) { |
| 153 | if ( !wpdesk_tracker_enabled() || apply_filters( 'wpdesk_tracker_do_not_ask', false ) ) { |
| 154 | return $links; |
| 155 | } |
| 156 | $options = get_option('wpdesk_helper_options', array() ); |
| 157 | if ( !is_array( $options )) { |
| 158 | $options = array(); |
| 159 | } |
| 160 | if ( empty( $options['wpdesk_tracker_agree'] ) ) { |
| 161 | $options['wpdesk_tracker_agree'] = '0'; |
| 162 | } |
| 163 | $plugin_links = array(); |
| 164 | if ( $options['wpdesk_tracker_agree'] == '0' ) { |
| 165 | $opt_in_link = admin_url( 'admin.php?page=wpdesk_tracker&plugin=flexible-checkout-fields/flexible-checkout-fields.php' ); |
| 166 | $plugin_links[] = '<a href="' . $opt_in_link . '">' . __( 'Opt-in', 'flexible-checkout-fields' ) . '</a>'; |
| 167 | } |
| 168 | else { |
| 169 | $opt_in_link = admin_url( 'plugins.php?wpdesk_tracker_opt_out=1&plugin=flexible-checkout-fields/flexible-checkout-fields.php' ); |
| 170 | $plugin_links[] = '<a href="' . $opt_in_link . '">' . __( 'Opt-out', 'flexible-checkout-fields' ) . '</a>'; |
| 171 | } |
| 172 | return array_merge( $plugin_links, $links ); |
| 173 | } |
| 174 | |
| 175 | public function activated_plugin( $plugin, $network_wide ) { |
| 176 | if ( $network_wide ) { |
| 177 | return; |
| 178 | } |
| 179 | if ( defined( 'WP_CLI' ) && WP_CLI ) { |
| 180 | return; |
| 181 | } |
| 182 | if ( !wpdesk_tracker_enabled() ) { |
| 183 | return; |
| 184 | } |
| 185 | if ( $plugin == 'flexible-checkout-fields/flexible-checkout-fields.php' ) { |
| 186 | $options = get_option('wpdesk_helper_options', array() ); |
| 187 | |
| 188 | if ( empty( $options ) ) { |
| 189 | $options = array(); |
| 190 | } |
| 191 | if ( empty( $options['wpdesk_tracker_agree'] ) ) { |
| 192 | $options['wpdesk_tracker_agree'] = '0'; |
| 193 | } |
| 194 | $wpdesk_tracker_skip_plugin = get_option( 'wpdesk_tracker_skip_flexible_checkout_fields', '0' ); |
| 195 | if ( $options['wpdesk_tracker_agree'] == '0' && $wpdesk_tracker_skip_plugin == '0' ) { |
| 196 | update_option( 'wpdesk_tracker_notice', '1' ); |
| 197 | update_option( 'wpdesk_tracker_skip_flexible_checkout_fields', '1' ); |
| 198 | if ( !apply_filters( 'wpdesk_tracker_do_not_ask', false ) ) { |
| 199 | wp_redirect( admin_url( 'admin.php?page=wpdesk_tracker&plugin=flexible-checkout-fields/flexible-checkout-fields.php' ) ); |
| 200 | exit; |
| 201 | } |
| 202 | } |
| 203 | } |
| 204 | } |
| 205 | |
| 206 | } |
| 207 | |
| 208 | new WPDesk_Flexible_Checkout_Fields_Tracker(); |
| 209 | |
| 210 | } |
| 211 | |
| 212 | if ( !function_exists( 'wpdesk_activated_plugin_activation_date' ) ) { |
| 213 | function wpdesk_activated_plugin_activation_date( $plugin, $network_wide ) { |
| 214 | $option_name = 'plugin_activation_' . $plugin; |
| 215 | $activation_date = get_option( $option_name, '' ); |
| 216 | if ( $activation_date == '' ) { |
| 217 | $activation_date = current_time( 'mysql' ); |
| 218 | update_option( $option_name, $activation_date ); |
| 219 | } |
| 220 | } |
| 221 | add_action( 'activated_plugin', 'wpdesk_activated_plugin_activation_date', 10, 2 ); |
| 222 | } |
| 223 | |
| 224 | if ( !function_exists( 'wpdesk_tracker_enabled' ) ) { |
| 225 | function wpdesk_tracker_enabled() { |
| 226 | $tracker_enabled = true; |
| 227 | if ( !empty( $_SERVER['SERVER_ADDR'] ) && $_SERVER['SERVER_ADDR'] == '127.0.0.1' ) { |
| 228 | $tracker_enabled = false; |
| 229 | } |
| 230 | return apply_filters( 'wpdesk_tracker_enabled', $tracker_enabled ); |
| 231 | // add_filter( 'wpdesk_tracker_enabled', '__return_true' ); |
| 232 | // add_filter( 'wpdesk_tracker_do_not_ask', '__return_true' ); |
| 233 | } |
| 234 | } |
| 235 |