From 864064fb936f1d6649031e6661d8f1107f4a68f0 Mon Sep 17 00:00:00 2001 From: mital Date: Tue, 7 Nov 2023 00:04:39 +0000 Subject: [PATCH] Fix #153 Deactivation survey v1 to v2... tracking survey v1 to v2 Fix #153 --- checkout-fees-for-woocommerce.php | 74 +++- includes/class-alg-wc-all-component.php | 95 +++++ includes/class-cf-tracking-functions.php | 159 ++++++++ .../class-tyche-plugin-deactivation.php | 25 +- .../class-tyche-plugin-tracking.php | 381 ++++++++++++++++++ includes/js/tyche-dismiss-tracking-notice.js | 34 ++ includes/js/tyche.js | 42 +- .../class-alg-wc-settings-checkout-fees.php | 40 +- 8 files changed, 815 insertions(+), 35 deletions(-) create mode 100644 includes/class-alg-wc-all-component.php create mode 100644 includes/class-cf-tracking-functions.php rename includes/{ => component/plugin-deactivation}/class-tyche-plugin-deactivation.php (83%) create mode 100644 includes/component/plugin-tracking/class-tyche-plugin-tracking.php create mode 100644 includes/js/tyche-dismiss-tracking-notice.js diff --git a/checkout-fees-for-woocommerce.php b/checkout-fees-for-woocommerce.php index 681094c..777b91d 100644 --- a/checkout-fees-for-woocommerce.php +++ b/checkout-fees-for-woocommerce.php @@ -123,6 +123,10 @@ public function __construct() { add_filter( 'woocommerce_get_settings_pages', array( $this, 'add_woocommerce_settings_tab' ) ); add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( $this, 'action_links' ) ); add_action( 'before_woocommerce_init', array( &$this, 'pgbf_lite_custom_order_tables_compatibility' ), 999 ); + add_action( 'admin_footer', array( $this, 'ts_admin_notices_scripts' ) ); + add_action( 'admin_init', array( $this, 'ts_reset_tracking_setting' ) ); + add_action( 'pgbf_lite_init_tracker_completed', array( $this, 'init_tracker_completed' ), 10, 2 ); + add_filter( 'ts_tracker_data', array( 'Cf_Tracking_Functions', 'cf_plugin_tracking_data' ), 10, 1 ); // Admin core. require_once 'includes/class-alg-wc-checkout-fees-admin.php'; // Settings. @@ -171,19 +175,73 @@ public function includes() { $this->core = require_once 'includes/class-alg-wc-checkout-fees.php'; $pgbf_plugin_url = plugins_url() . '/checkout-fees-for-woocommerce'; require_once 'includes/class-alg-wc-order-fees.php'; - // plugin deactivation. - require_once 'includes/class-tyche-plugin-deactivation.php'; - new Tyche_Plugin_Deactivation( + + // Data Tracking. + include_once 'includes/class-cf-tracking-functions.php'; + include_once 'includes/class-alg-wc-all-component.php'; + } + + + /** + * Added tracking dismiss notice js. + */ + public static function ts_admin_notices_scripts() { + wp_enqueue_script( + 'pgbf_lite_ts_dismiss_notice', + plugins_url() . '/checkout-fees-for-woocommerce/includes/js/tyche-dismiss-tracking-notice.js', + '', + '', + false + ); + + wp_localize_script( + 'pgbf_lite_ts_dismiss_notice', + 'pgbf_lite_ts_dismiss_notice', array( - 'plugin_name' => 'Payment Gateway Based Fees and Discounts for WooCommerce', - 'plugin_base' => 'checkout-fees-for-woocommerce/checkout-fees-for-woocommerce.php', - 'script_file' => $pgbf_plugin_url . '/includes/js/plugin-deactivation.js', - 'plugin_short_name' => 'pgbf_lite', - 'version' => $this->version, + 'ts_prefix_of_plugin' => 'pgbf_lite', + 'ts_admin_url' => admin_url( 'admin-ajax.php' ), ) ); } + + /** + * This function includes js files required for admin side. + * + * @hook admin_enqueue_scripts + * + * @since 2.9.0 + */ + function enqueue_script() { + wp_register_script( + 'tyche', + plugins_url() . '/checkout-fees-for-woocommerce/includes/js/tyche.js', + array( 'jquery' ), + $this->version, + true + ); + wp_enqueue_script( 'tyche' ); + } + + /** + * Remove query string to the admin url. + */ + public static function ts_reset_tracking_setting() { + if ( isset( $_GET ['ts_action'] ) && 'reset_tracking' == $_GET ['ts_action'] ) { + Tyche_Plugin_Tracking::reset_tracker_setting( 'pgbf_lite' ); + $ts_url = remove_query_arg( 'ts_action' ); + wp_safe_redirect( $ts_url ); + } + } + + /** + * Redirect page after tracking completed. + */ + public static function init_tracker_completed() { + header( 'Location: ' . admin_url( 'admin.php?page=wc-settings&tab=alg_checkout_fees' ) ); + exit; + } + /** * Add translations as per user language. * diff --git a/includes/class-alg-wc-all-component.php b/includes/class-alg-wc-all-component.php new file mode 100644 index 0000000..d7f9524 --- /dev/null +++ b/includes/class-alg-wc-all-component.php @@ -0,0 +1,95 @@ + $pgbf_plugin_name, + 'plugin_base' => $pgbf_file_name, + 'script_file' => $plugin_url . '/includes/js/plugin-deactivation.js', + 'plugin_short_name' => $pgbf_plugin_prefix, + 'version' => $pgbf_get_previous_version, + 'plugin_locale' => $pgbf_locale, + ) + ); + + require_once( "component/plugin-tracking/class-tyche-plugin-tracking.php" ); + new Tyche_Plugin_Tracking( + array( + 'plugin_name' => $pgbf_plugin_name, + 'plugin_locale' => $pgbf_locale, + 'plugin_short_name' => $pgbf_plugin_prefix, + 'version' => $pgbf_get_previous_version, + 'blog_link' => $pgbf_blog_post_link, + ) + ); + } + } + + /** + * It will retrun the plguin name. + * @return string $ts_plugin_name Name of the plugin + */ + public static function ts_get_plugin_name () { + $pgbf_plugin_dir = dirname ( dirname ( __FILE__ ) ); + $pgbf_plugin_dir .= '/checkout-fees-for-woocommerce.php'; + + $ts_plugin_name = ''; + $plugin_data = get_file_data( $pgbf_plugin_dir, array( 'name' => 'Plugin Name' ) ); + if ( ! empty( $plugin_data['name'] ) ) { + $ts_plugin_name = $plugin_data[ 'name' ]; + } + return $ts_plugin_name; + } + + /** + * It will retrun the Plugin text Domain + * @return string $ts_plugin_domain Name of the Plugin domain + */ + public static function ts_get_plugin_locale () { + $pgbf_plugin_dir = dirname ( dirname ( __FILE__ ) ); + $pgbf_plugin_dir .= '/checkout-fees-for-woocommerce.php'; + + $ts_plugin_domain = ''; + $plugin_data = get_file_data( $pgbf_plugin_dir, array( 'domain' => 'Text Domain' ) ); + if ( ! empty( $plugin_data['domain'] ) ) { + $ts_plugin_domain = $plugin_data[ 'domain' ]; + } + return $ts_plugin_domain; + } + } + $Alg_WC_All_Component = new Alg_WC_All_Component(); +} diff --git a/includes/class-cf-tracking-functions.php b/includes/class-cf-tracking-functions.php new file mode 100644 index 0000000..1726da7 --- /dev/null +++ b/includes/class-cf-tracking-functions.php @@ -0,0 +1,159 @@ + 'ts_tracking_pgbf_pro_meta_data', + 'ts_plugin_name' => 'Payment Gateway Based Fees and Discounts for WooCommerce', + 'global_settings' => self::cf_get_global_settings(), + 'enabled_payment_gateways' => self::cf_get_enabled_payment_gateways(), + ); + + $active_gateways = self::wc_payment_gateways(); + foreach ( $active_gateways as $key => $value ) { + $args = alg_wc_cf()->core->args_manager->get_the_args_global( $key ); + $plugin_data[ $key . 'settings' ] = $args; + } + + $active_gateways = WC()->payment_gateways->payment_gateways(); + foreach ( $active_gateways as $gateway => $gateway_data ) { + $count = self::cf_get_gateway_based_product_counts( $gateway ); + $plugin_data[ $gateway . '_product_count' ] = $count; + } + + $data['plugin_data'] = $plugin_data; + return $data; + } + + /** + * Send the global settings for tracking. + * Settings from the Genetral, Behavior & Advanced tabs are captured here. + * + * @since 2.6.3 + */ + public static function cf_get_global_settings() { + + $global_settings = array( + 'alg_woocommerce_checkout_fees_enabled' => get_option( 'alg_woocommerce_checkout_fees_enabled' ), + 'alg_woocommerce_checkout_fees_per_product_enabled' => get_option( 'alg_woocommerce_checkout_fees_per_product_enabled' ), + 'alg_woocommerce_checkout_fees_per_product_add_product_name' => get_option( 'alg_woocommerce_checkout_fees_per_product_add_product_name' ), + 'alg_woocommerce_checkout_fees_merge_all_fees' => get_option( 'alg_woocommerce_checkout_fees_merge_all_fees' ), + 'alg_woocommerce_checkout_fees_range_max_total_discounts' => get_option( 'alg_woocommerce_checkout_fees_range_max_total_discounts' ), + 'alg_woocommerce_checkout_fees_range_max_total_fees' => get_option( 'alg_woocommerce_checkout_fees_range_max_total_fees' ), + 'alg_woocommerce_checkout_fees_hide_on_cart' => get_option( 'alg_woocommerce_checkout_fees_hide_on_cart' ), + 'alg_woocommerce_checkout_fees_info_enabled' => get_option( 'alg_woocommerce_checkout_fees_info_enabled' ), + 'alg_woocommerce_checkout_fees_info_start_template' => get_option( 'alg_woocommerce_checkout_fees_info_start_template' ), + 'alg_woocommerce_checkout_fees_info_row_template' => get_option( 'alg_woocommerce_checkout_fees_info_row_template' ), + 'alg_woocommerce_checkout_fees_info_end_template' => get_option( 'alg_woocommerce_checkout_fees_info_end_template' ), + 'alg_woocommerce_checkout_fees_info_hook' => get_option( 'alg_woocommerce_checkout_fees_info_hook' ), + 'alg_woocommerce_checkout_fees_info_hook_priority' => get_option( 'alg_woocommerce_checkout_fees_info_hook_priority' ), + 'alg_woocommerce_checkout_fees_lowest_price_info_enabled' => get_option( 'alg_woocommerce_checkout_fees_lowest_price_info_enabled' ), + 'alg_woocommerce_checkout_fees_lowest_price_info_template' => get_option( 'alg_woocommerce_checkout_fees_lowest_price_info_template' ), + 'alg_woocommerce_checkout_fees_lowest_price_info_hook' => get_option( 'alg_woocommerce_checkout_fees_lowest_price_info_hook' ), + 'alg_woocommerce_checkout_fees_lowest_price_info_hook_priority' => get_option( 'alg_woocommerce_checkout_fees_lowest_price_info_hook_priority' ), + 'alg_woocommerce_checkout_fees_variable_info' => get_option( 'alg_woocommerce_checkout_fees_variable_info' ), + 'alg_woocommerce_checkout_fees_global_fee_enabled' => get_option( 'alg_woocommerce_checkout_fees_global_fee_enabled' ), + 'alg_woocommerce_checkout_fees_global_fee_as_extra_enabled' => get_option( 'alg_woocommerce_checkout_fees_global_fee_as_extra_enabled' ), + 'alg_woocommerce_checkout_fees_global_fee_gateways_excl' => get_option( 'alg_woocommerce_checkout_fees_global_fee_gateways_excl' ), + 'alg_woocommerce_checkout_fees_global_fee_title' => get_option( 'alg_woocommerce_checkout_fees_global_fee_title' ), + 'alg_woocommerce_checkout_fees_global_fee_value' => get_option( 'alg_woocommerce_checkout_fees_global_fee_value' ), + ); + + return $global_settings; + + } + + /** + * Enabled Payment Gateways Information + * + * @since 2.6.3 + */ + public static function cf_get_enabled_payment_gateways() { + + $active_gateways = self::wc_payment_gateways(); + + return $active_gateways; + } + + /** + * Fetch Enabled Payment Gateways Information + * + * @since 2.6.3 + */ + public static function wc_payment_gateways() { + + $active_gateways = array(); + $gateways = WC()->payment_gateways->payment_gateways(); + foreach ( $gateways as $id => $gateway ) { + if ( isset( $gateway->enabled ) && 'yes' === $gateway->enabled ) { + $active_gateways[ $id ] = array( + 'title' => $gateway->title, + 'supports' => $gateway->supports, + ); + } + } + + return $active_gateways; + } + + /** + * Returns the number of products for the given gateway. + * + * @param string $gateway - Gateway Code. + * @return int $count - Count of products. + * @since 2.6.3 + */ + public static function cf_get_gateway_based_product_counts( $gateway = '' ) { + + if ( '' !== $gateway ) { + + $gateway = '_alg_checkout_fees_enabled_' . $gateway; + + global $wpdb; + $count = $wpdb->get_var( $wpdb->prepare( "SELECT count(post_id) FROM `" . $wpdb->prefix . "postmeta` WHERE meta_key = %s AND meta_value = %s", $gateway, 'yes' ) ); // phpcs:ignore + + return $count; + } + + return 0; + } + } + +endif; + +$cf_tracking_functions = new Cf_Tracking_Functions(); diff --git a/includes/class-tyche-plugin-deactivation.php b/includes/component/plugin-deactivation/class-tyche-plugin-deactivation.php similarity index 83% rename from includes/class-tyche-plugin-deactivation.php rename to includes/component/plugin-deactivation/class-tyche-plugin-deactivation.php index 1079dd5..caaede7 100644 --- a/includes/class-tyche-plugin-deactivation.php +++ b/includes/component/plugin-deactivation/class-tyche-plugin-deactivation.php @@ -42,6 +42,13 @@ class Tyche_Plugin_Deactivation { */ private $plugin_name = ''; + /** + * Plugin Locale. + * + * @var string $plugin_locale + */ + private $plugin_locale = ''; + /** * Plugin Short Name. * @@ -93,7 +100,7 @@ public function init_vars( $options ) { return false; } - if ( ! isset( $options['plugin_name'] ) || ! isset( $options['plugin_base'] ) || ! isset( $options['script_file'] ) || ! isset( $options['plugin_short_name'] ) || ! isset( $options['version'] ) ) { + if ( ! isset( $options['plugin_name'] ) || ! isset( $options['plugin_base'] ) || ! isset( $options['script_file'] ) || ! isset( $options['plugin_short_name'] ) || ! isset( $options['version'] ) || ! isset( $options['plugin_locale'] ) ) { return false; } @@ -102,6 +109,7 @@ public function init_vars( $options ) { $this->script_file = $options['script_file']; $this->plugin_short_name = $options['plugin_short_name']; $this->version = $options['version']; + $this->plugin_locale = $options['plugin_locale']; return true; } @@ -117,7 +125,7 @@ public function init_vars( $options ) { public function plugin_action_links( $links ) { if ( isset( $links['deactivate'] ) ) { - $links['deactivate'] .= ''; + $links['deactivate'] .= ''; } return $links; @@ -161,9 +169,10 @@ public function enqueue_scripts() { 'tyche_plugin_deactivation_' . $this->plugin_short_name, 'tyche_plugin_deactivation_' . $this->plugin_short_name . '_js', array( - 'deactivation_data' => $data, - 'ajax_url' => admin_url( 'admin-ajax.php' ), - 'nonce' => wp_create_nonce( 'tyche_plugin_deactivation_submit_action' ), + 'deactivation_data' => $data, + 'ajax_url' => admin_url( 'admin-ajax.php' ), + 'nonce' => wp_create_nonce( 'tyche_plugin_deactivation_submit_action' ), + 'deactivation_req_msg' => __( 'Please select a reason for deactivation!', $this->plugin_locale ), ) ); @@ -177,7 +186,7 @@ public function enqueue_scripts() { */ public function tyche_plugin_deactivation_submit_action() { - if ( ! wp_verify_nonce( $_POST['nonce'], 'tyche_plugin_deactivation_submit_action' ) || ! isset( $_POST['reason_id'] ) || ! isset( $_POST['reason_text'] ) ) { // phpcs:ignore + if ( ! wp_verify_nonce( $_POST['nonce'], 'tyche_plugin_deactivation_submit_action' ) || ! isset( $_POST['reason_id'] ) || ! isset( $_POST['reason_text'] ) || ! isset( $_POST['plugin_short_name'] ) || ! isset( $_POST['plugin_name'] ) ) { // phpcs:ignore wp_send_json_error( 0 ); } @@ -193,10 +202,10 @@ public function tyche_plugin_deactivation_submit_action() { 'body' => wp_json_encode( array( 'action' => 'plugin-deactivation', - 'plugin_slug' => $this->plugin_short_name, + 'plugin_slug' => isset( $_POST['plugin_short_name'] ) ? sanitize_text_field( wp_unslash( $_POST['plugin_short_name'] ) ) : '', 'url' => home_url(), 'email' => apply_filters( 'ts_tracker_admin_email', get_option( 'admin_email' ) ), - 'plugin_name' => $this->plugin_name, + 'plugin_name' => isset( $_POST['plugin_name'] ) ? sanitize_text_field( wp_unslash( $_POST['plugin_name'] ) ) : '', 'reason_id' => isset( $_POST['reason_id'] ) ? sanitize_text_field( wp_unslash( $_POST['reason_id'] ) ) : '', 'reason_text' => isset( $_POST['reason_text'] ) ? sanitize_text_field( wp_unslash( $_POST['reason_text'] ) ) : '', 'reason_info' => isset( $_POST['reason_info'] ) ? sanitize_text_field( wp_unslash( $_POST['reason_info'] ) ) : '', diff --git a/includes/component/plugin-tracking/class-tyche-plugin-tracking.php b/includes/component/plugin-tracking/class-tyche-plugin-tracking.php new file mode 100644 index 0000000..c7a7fd6 --- /dev/null +++ b/includes/component/plugin-tracking/class-tyche-plugin-tracking.php @@ -0,0 +1,381 @@ +init_vars( $options ) ) { + return; + } + + add_action( $this->plugin_short_name . '_ts_tracker_send_event', array( &$this, 'send_tracking_data' ) ); + add_action( $this->plugin_short_name . '_init_tracker', array( &$this, 'init_tracker' ) ); + add_action( 'wp_ajax_' . $this->plugin_short_name . '_tracker_dismiss_notice', array( &$this, 'dismiss_notice' ) ); + add_action( 'admin_notices', array( &$this, 'display_tracker_html_template' ) ); + add_filter( 'cron_schedules', array( &$this, 'cron_schedule' ) ); + add_action( 'admin_init', array( &$this, 'init_tracker' ) ); + $this->schedule_cron_job(); + } + + /** + * Initialize variables from options array. + * + * @param array $options Options. + * + * @since 1.1 + */ + public function init_vars( $options ) { + + if ( ! is_array( $options ) ) { + return false; + } + + if ( empty( array_diff( array( 'plugin_name', 'plugin_locale', 'plugin_short_name', 'version', 'blog_link' ), $options ) ) ) { + return false; + } + + $this->plugin_name = $options['plugin_name']; + $this->plugin_locale = $options['plugin_locale']; + $this->plugin_short_name = $options['plugin_short_name']; + $this->version = $options['version']; + $this->blog_link = $options['blog_link']; + + return true; + } + + /** + * Adds a weekly cron job schedule. + * + * @param array $schedules Schedules. + */ + public function cron_schedule( $schedules ) { + $schedules['once_in_week'] = array( + 'interval' => 604800, // one week in seconds. + 'display' => __( 'Once in a Week', $this->plugin_locale ), // phpcs:ignore + ); + + return $schedules; + } + + /** + * Cron Job Scheduler. + */ + public function schedule_cron_job() { + if ( ! wp_next_scheduled( $this->plugin_short_name . '_ts_tracker_send_event' ) ) { + wp_schedule_event( time() + 604800, 'once_in_week', $this->plugin_short_name . '_ts_tracker_send_event' ); + } + } + + /** + * It will delete the tracking option from the database. + * + * @param string $plugin_short_name Plugin Short Name. + */ + public static function reset_tracker_setting( $plugin_short_name ) { + delete_option( $plugin_short_name . '_allow_tracking' ); + delete_option( 'ts_tracker_last_send' ); + } + + /** + * Called when the dismiss icon is clicked on the notice. + */ + public function dismiss_notice() { + update_option( $this->plugin_short_name . '_allow_tracking', 'dismissed' ); + $this->send_tracking_data(); + } + + /** + * Send the Tracking Data. + * + * @since 1.1 + */ + public function send_tracking_data() { + + $allow_tracking = get_option( $this->plugin_short_name . '_allow_tracking' . '' ); // phpcs:ignore + + if ( '' === $allow_tracking ) { + return; + } + + $last_sent_time = apply_filters( 'ts_tracker_last_send_time', get_option( 'ts_tracker_last_send', false ) ); + + // Send a maximum of once per week by default. + if ( $last_sent_time && $last_sent_time > apply_filters( 'ts_tracker_last_send_interval', strtotime( '-1 week' ) ) ) { + return; + } + + // Update time first before sending to ensure it is set. + update_option( 'ts_tracker_last_send', time() ); + + $params = array( + 'url' => home_url(), + 'plugin_name' => $this->plugin_name, + 'plugin_slug' => $this->plugin_short_name, + 'action' => 'tracking', + ); + + if ( 'yes' === $allow_tracking ) { + + // Make sure there is at least a 1 hour delay between override sends, we don't want duplicate calls due to double clicking links. + if ( $last_sent_time && $last_sent_time > strtotime( '-1 hours' ) ) { + return; + } + + $params = array_merge( + $params, + $this->tracking_data() + ); + } else { + $params['tracking_usage'] = 1; + $params = apply_filters( 'ts_tracker_opt_out_data', $params ); + } + + wp_safe_remote_post( + $this->api_url, + array( + 'method' => 'POST', + 'timeout' => 60, + 'redirection' => 5, + 'httpversion' => '1.0', + 'blocking' => false, + 'headers' => array( 'user-agent' => 'TSTracker/' . md5( esc_url( home_url( '/' ) ) ) . ';' ), + 'body' => wp_json_encode( $params ), + 'cookies' => array(), + ) + ); + } + + /** + * Initiates the tracker and sends plugin data to the tracking server. + */ + public function init_tracker() { + + if ( ! isset( $_GET[ $this->plugin_short_name . '_tracker_nonce' ] ) ) { + return; + } + + $tracker_option = isset( $_GET[ $this->plugin_short_name . '_tracker_optin' ] ) ? $this->plugin_short_name . '_tracker_optin' : ( isset( $_GET[ $this->plugin_short_name . '_tracker_optout' ] ) ? $this->plugin_short_name . '_tracker_optout' : '' ); // phpcs:ignore + + if ( '' === $tracker_option || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_GET[ $this->plugin_short_name . '_tracker_nonce' ] ) ), $tracker_option ) ) { + return; + } + + update_option( $this->plugin_short_name . '_allow_tracking', isset( $_GET[ $this->plugin_short_name . '_tracker_optin' ] ) ? 'yes' : 'no' ); // phpcs:ignore + $this->send_tracking_data(); + do_action( $this->plugin_short_name . '_init_tracker_completed' ); + } + + /** + * Displays the HTML template for displaying the prompt for enabling tracking. + */ + public function display_tracker_html_template() { + + $current_screen = get_current_screen(); + + if ( 'page' === get_post_type() || 'post' === get_post_type() || ( method_exists( $current_screen, 'is_block_editor' ) && $current_screen->is_block_editor() ) || ( function_exists( 'is_gutenberg_page' ) && is_gutenberg_page() ) || ! apply_filters( $this->plugin_short_name . '_ts_tracker_display_notice', true ) ) { + return; + } + + echo ''; + + if ( '' === get_option( $this->plugin_short_name . '_allow_tracking', '' ) ) { ?> +
+
+

+ plugin_name . ' even more awesome? Allow ' . $this->plugin_name . ' to collect non-sensitive diagnostic data and usage information and get 20% off on your next purchase. Find out more.', $this->plugin_locale ) ); //phpcs:ignore ?> +

+

+ plugin_locale ); //phpcs:ignore ?> + +

+
+ ( defined( 'WP_DEBUG' ) && WP_DEBUG ) ? 'Yes' : 'No', + 'locale' => get_locale(), + 'wp_version' => get_bloginfo( 'version' ), + 'multisite' => is_multisite() ? 'Yes' : 'No', + 'blogdescription' => get_option( 'blogdescription' ), + 'blogname' => get_option( 'blogname' ), + 'wc_city' => get_option( 'woocommerce_store_city' ), + 'wc_country' => get_option( 'woocommerce_default_country' ), + ); + + $memory = wc_let_to_num( WP_MEMORY_LIMIT ); + + if ( function_exists( 'memory_get_usage' ) ) { + $system_memory = wc_let_to_num( @ini_get( 'memory_limit' ) ); // phpcs:ignore + $memory = max( $memory, $system_memory ); + } + + $data['wp']['memory_limit'] = size_format( $memory ); + + // Theme Info. + $theme_data = wp_get_theme(); + $data['theme_info'] = array( + 'theme_name' => $theme_data->get( 'Name' ), + 'theme_version' => $theme_data->get( 'Version' ), + 'child_theme' => is_child_theme() ? 'Yes' : 'No', + ); + + // Server Info. + $data['server'] = array( + 'mysql_version' => $wpdb->db_version(), + 'php_max_upload_size' => size_format( wp_max_upload_size() ), + 'php_default_timezone' => date_default_timezone_get(), + 'php_soap' => class_exists( 'SoapClient' ) ? 'Yes' : 'No', + 'php_fsockopen' => function_exists( 'fsockopen' ) ? 'Yes' : 'No', + 'php_curl' => function_exists( 'curl_init' ) ? 'Yes' : 'No', + ); + + if ( isset( $_SERVER['SERVER_SOFTWARE'] ) && ! empty( $_SERVER['SERVER_SOFTWARE'] ) ) { + $data['server']['software'] = sanitize_text_field( wp_unslash( $_SERVER['SERVER_SOFTWARE'] ) ); + } + + if ( function_exists( 'phpversion' ) ) { + $data['server']['php_version'] = phpversion(); + } + + if ( function_exists( 'ini_get' ) ) { + $data['server']['php_post_max_size'] = size_format( wc_let_to_num( ini_get( 'post_max_size' ) ) ); + $data['server']['php_time_limt'] = ini_get( 'max_execution_time' ); + $data['server']['php_max_input_vars'] = ini_get( 'max_input_vars' ); + $data['server']['php_suhosin'] = extension_loaded( 'suhosin' ) ? 'Yes' : 'No'; + } + + // Plugin info. + if ( ! function_exists( 'get_plugins' ) ) { + include ABSPATH . '/wp-admin/includes/plugin.php'; // Ensure get_plugins function is loaded. + } + + $plugins = get_plugins(); + $active_plugins_keys = get_option( 'active_plugins', array() ); + $active_plugins = array(); + + foreach ( $plugins as $k => $v ) { + + // Take care of formatting the data how we want it. + $formatted = array(); + $formatted['name'] = wp_strip_all_tags( $v['Name'] ); + + if ( isset( $v['Version'] ) ) { + $formatted['version'] = wp_strip_all_tags( $v['Version'] ); + } + + if ( isset( $v['Author'] ) ) { + $formatted['author'] = wp_strip_all_tags( $v['Author'] ); + } + + if ( isset( $v['Network'] ) ) { + $formatted['network'] = wp_strip_all_tags( $v['Network'] ); + } + + if ( isset( $v['PluginURI'] ) ) { + $formatted['plugin_uri'] = wp_strip_all_tags( $v['PluginURI'] ); + } + + if ( in_array( $k, $active_plugins_keys, true ) ) { + // Remove active plugins from list so we can show active and inactive separately. + unset( $plugins[ $k ] ); + $active_plugins[ $k ] = $formatted; + } else { + $plugins[ $k ] = $formatted; + } + } + + $data['active_plugins'] = $active_plugins; + $data['inactive_plugins'] = $plugins; + + // WooCommerce version. + $data['wc_plugin_version'] = WC()->version; + + return apply_filters( 'ts_tracker_data', $data ); + } + } +} diff --git a/includes/js/tyche-dismiss-tracking-notice.js b/includes/js/tyche-dismiss-tracking-notice.js new file mode 100644 index 0000000..58f8404 --- /dev/null +++ b/includes/js/tyche-dismiss-tracking-notice.js @@ -0,0 +1,34 @@ +jQuery(document).ready( function() { + jQuery( '.notice.is-dismissible' ).each( function() { + var $this = jQuery( this ), + $button = jQuery( '' ), + btnText = wp.i18n.dismiss || ''; + + // Ensure plain text + $button.find( '.screen-reader-text' ).text( btnText ); + + $this.append( $button ); + + /** + * Event when close icon is clicked. + * @fires event:notice-dismiss + * @since 6.8 + */ + $button.on( 'click.notice-dismiss', function( event ) { + event.preventDefault(); + $this.fadeTo( 100 , 0, function() { + //alert(); + jQuery(this).slideUp( 100, function() { + jQuery(this).remove(); + jQuery.post( + pgbf_lite_ts_dismiss_notice.ts_admin_url, + { + action: pgbf_lite_ts_dismiss_notice.ts_prefix_of_plugin + "_tracker_dismiss_notice" + }, + function( response ) {} + ); + }); + }); + }); + }); +}); \ No newline at end of file diff --git a/includes/js/tyche.js b/includes/js/tyche.js index a30ab6c..4947913 100644 --- a/includes/js/tyche.js +++ b/includes/js/tyche.js @@ -1,7 +1,7 @@ "use strict"; var tyche = { - version: '1.1', // version of tyche constructor. + version: '1.1.3', // version of tyche constructor. constructor: tyche, extend: function() { let target = arguments[ 0 ] || {}, @@ -43,6 +43,7 @@ var tyche = { } } }, + wcap: {}, // Abandoned Cart Pro for WooCommerce. orddd: {}, // Order Delivery Date Pro for WooCommerce. bkap: {}, // Booking & Appointment Plugin for WooCommerce. ac: {}, // Abandoned Cart Pro for WooCommerce. @@ -82,12 +83,13 @@ var tyche = { }, modal: function( $plugin, $data ) { - if ( '' === tyche.plugin_deactivation.fn.return( $data, 'deactivation_data' ) || '' === tyche.plugin_deactivation.fn.return( $data, 'nonce' ) ) { + if ( '' === tyche.plugin_deactivation.fn.return( $data, 'deactivation_data' ) || '' === tyche.plugin_deactivation.fn.return( $data, 'nonce' ) || '' === tyche.plugin_deactivation.fn.return( $data, 'deactivation_req_msg' ) ) { return ''; } let data = $data.deactivation_data, - nonce = $data.nonce; + nonce = $data.nonce, + deactivation_req_msg = $data.deactivation_req_msg; if ( 'undefined' === typeof data.template || 'undefined' === typeof data.reasons ) { return ''; @@ -118,7 +120,7 @@ var tyche = { html += ``; - let modal = jQuery( template.replace( '{PLUGIN}', $plugin ).replace( '{HTML}', html ) ); + let modal = jQuery( template.replace( '{PLUGIN}', $plugin ).replace( '{HTML}', html ).replace( '{DEACTIVATION_REQ_MSG}', deactivation_req_msg ) ); modal.appendTo( jQuery( 'body' ) ); return modal; @@ -157,16 +159,18 @@ var tyche = { modal.on( 'click', '.button-deactivate', function( e ) { e.preventDefault(); + jQuery( '.ts-modal-footer p' ).hide(); tyche.plugin_deactivation.events.button_submit( this, data, plugin ); } ); modal.on( 'click', 'input[type="radio"]', function() { + jQuery( '.ts-modal-footer p' ).hide(); tyche.plugin_deactivation.events.button_option_selection( this, modal ); } ); // If the user has clicked outside the window, cancel it. modal.on( 'click', function( e ) { - tyche.plugin_deactivation.events.button_click_outside_window( e, modal ) + tyche.plugin_deactivation.events.button_click_outside_window( e, modal ); } ); }, @@ -179,21 +183,23 @@ var tyche = { let modal = jQuery( $this ).parents( `.${plugin}.ts-modal` ), option = jQuery( 'input[type="radio"]:checked' ), reason = option.parents( 'li:first' ), - response = reason.find( 'textarea, input[type="text"]' ), - nonce = jQuery( 'input[name="nonce"]' ).val(), - data = { - 'action': 'tyche_plugin_deactivation_submit_action', - 'reason_id': 0, - 'reason_text': 'Deactivated without any option', - nonce - }; - - if ( 0 !== option.length ) { - data.reason_id = option.val(); - data.reason_text = reason.text().trim(); - data.reason_info = 0 !== response.length ? response.val().trim() : ''; + response = reason.find( 'textarea, input[type="text"]' ); + + if ( 0 === option.length ) { + jQuery( '.ts-modal-footer p' ).css( 'display', 'inline-block' ); + return; } + let data = { + 'action': 'tyche_plugin_deactivation_submit_action', + 'reason_id': option.val(), + 'reason_text': reason.text().trim(), + 'reason_info': 0 !== response.length ? response.val().trim() : '', + 'plugin_short_name': plugin, + 'plugin_name': jQuery( `.${plugin}.ts-slug` ).attr( 'data-plugin' ), + 'nonce': jQuery( 'input[name="nonce"]' ).val() + }; + let ajax_url = tyche.plugin_deactivation.fn.return( $data, 'ajax_url' ), href = jQuery( `.${plugin}.ts-slug` ).prev().prop( 'href' ); diff --git a/includes/settings/class-alg-wc-settings-checkout-fees.php b/includes/settings/class-alg-wc-settings-checkout-fees.php index ce08461..1b92517 100644 --- a/includes/settings/class-alg-wc-settings-checkout-fees.php +++ b/includes/settings/class-alg-wc-settings-checkout-fees.php @@ -48,7 +48,7 @@ public function __construct() { add_action( 'woocommerce_update_options_' . $this->id, array( $this, 'maybe_reset_settings' ) ); add_filter( 'woocommerce_admin_settings_sanitize_option', array( $this, 'maybe_unclean_option' ), PHP_INT_MAX, 3 ); add_action( 'woocommerce_admin_field_alg_woocommerce_checkout_fees_custom_link', array( $this, 'output_custom_link' ) ); - + add_action( 'woocommerce_admin_field_link', array( $this, 'add_admin_field_reset_button' ) ); } /** @@ -73,6 +73,15 @@ public function get_settings() { 'default' => 'no', 'type' => 'checkbox', ), + array( + 'name' => __( 'Reset usage tracking', 'checkout-fees-for-woocommerce' ), + 'type' => 'link', + 'desc' => __( 'This will reset your usage tracking settings, causing it to show the opt-in banner again and not sending any data', 'checkout-fees-for-woocommerce' ), + 'button_text' => 'Reset', + 'desc_tip' => true, + 'class' => 'button-secondary reset_tracking', + 'id' => 'ts_reset_tracking', + ), array( 'type' => 'sectionend', 'id' => 'alg_woocommerce_checkout_fees_' . $current_section . '_reset_options', @@ -138,6 +147,35 @@ public function output_custom_link( $value ) { + + + + + + + + + +