client = $client; } } /** * Don't show the notice * * @return Insights */ public function hide_notice() { $this->show_notice = false; return $this; } /** * Add extra data if needed * * @param array $data Extra data. * * @return Insights */ public function add_extra( $data = [] ) { $this->extra_data = $data; return $this; } /** * Set custom notice text * * @param string $text Admin Notice Test. * * @return Insights */ public function notice( $text ) { $this->notice = $text; return $this; } /** * Initialize insights * * @return void */ public function init() { if ( $this->did_init ) { return; } // Env Setup. $slug = $this->client->getSlug(); /** * Support Page URL * @param string $supportURL */ $supportURL = apply_filters( "absp_service_api_{$slug}_Support_Page_URL" , false ); if ( FALSE !== $supportURL ) { $supportURL = esc_url_raw( $supportURL, [ 'http', 'https' ] ); if ( ! empty( $supportURL ) ) { $this->supportURL = $supportURL; } } /** * Set Ticket Recipient Email * @param string $ticketRecipient */ $ticketRecipient = apply_filters( "absp_service_api_{$slug}_Support_Ticket_Recipient_Email" , false ); if ( FALSE !== $ticketRecipient && is_email( $ticketRecipient ) ) { $this->ticketRecipient = sanitize_email( $ticketRecipient ); } /** * Set Support Ticket Template For sending the email query. * @param string $ticketTemplate */ $ticketTemplate = apply_filters( "absp_service_api_{$slug}_Support_Ticket_Email_Template", false ); if ( FALSE !== $ticketTemplate ) { $this->ticketTemplate = $ticketTemplate; } // Initialize. $fn = 'init_' . $this->client->getType(); $this->{$fn}(); // init_(plugin/theme) $this->did_init = true; } /** * Initialize theme hooks * * @return void */ private function init_theme() { $this->init_common(); add_action( 'switch_theme', [ $this, 'deactivation_cleanup' ] ); add_action( 'switch_theme', [ $this, 'theme_deactivated' ], 12, 3 ); } /** * Initialize plugin hooks * * @return void */ private function init_plugin() { // Plugin deactivate popup. if ( ! $this->client->is_local_request() ) { add_action( 'admin_footer', [ $this, 'deactivate_scripts' ] ); add_action( 'plugin_action_links_' . $this->client->getBasename(), [ $this, 'plugin_action_links' ] ); } $this->init_common(); register_activation_hook( $this->client->getFile(), [ $this, 'activate_plugin' ] ); register_deactivation_hook( $this->client->getFile(), [ $this, 'deactivation_cleanup' ] ); } /** * Initialize common hooks * * @return void */ protected function init_common() { if ( $this->show_notice ) { // Tracking notice. add_action( 'admin_notices', [ $this, 'admin_notice' ] ); } add_action( 'admin_init', [ $this, 'handle_optIn_optOut' ] ); add_action( 'removable_query_args', [ $this, 'add_removable_query_args' ] ); // uninstall reason. add_action( 'wp_ajax_' . $this->client->getSlug() . '_submit-uninstall-reason', [ $this, 'uninstall_reason_submission' ] ); add_action( 'wp_ajax_' . $this->client->getSlug() . '_submit-support-ticket', [ $this, 'support_ticket_submission' ] ); // cron events. add_filter( 'cron_schedules', [ $this, 'add_weekly_schedule' ] ); add_action( $this->client->getSlug() . '_tracker_send_event', [ $this, 'send_tracking_data' ] ); } /** * Send tracking data to absp_service_api server * * @param boolean $override override current settings. * * @return void */ public function send_tracking_data( $override = false ) { // Skip on AJAX Requests. if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) { return; } if ( ! $this->is_tracking_allowed() && ! $override ) { return; } // Send a maximum of once per week. $last_send = $this->__get_last_send(); /** * Tracking interval * * @param string $interval A valid date/time string */ $trackingInterval = apply_filters( $this->client->getSlug() . '_tracking_interval', '-1 week' ); try { $intervalCheck = strtotime( $trackingInterval ); } catch ( Exception $e ) { // fallback to default 1 week if filter returned unusable data. $intervalCheck = strtotime( '-1 week' ); } if ( $last_send && $last_send > $intervalCheck && ! $override ) { return; } $this->client->request( [ 'body' => $this->get_tracking_data(), 'route' => 'track' ] ); update_option( $this->client->getSlug() . '_tracking_last_send', time(), false ); } /** * Get the tracking data points * * @return array */ protected function get_tracking_data() { $all_plugins = $this->__get_all_plugins(); $admin_user = $this->__get_admin(); $admin_emails = [ get_option( 'admin_email' ), $admin_user->user_email ]; $admin_emails = array_filter( $admin_emails ); $admin_emails = array_unique( $admin_emails ); $data = [ 'url' => esc_url( home_url() ), 'site' => $this->__get_site_name(), 'admin_email' => implode( ',', $admin_emails ), 'first_name' => isset( $admin_user->first_name ) && $admin_user->first_name ? $admin_user->first_name : $admin_user->display_name, 'last_name' => $admin_user->last_name, 'server' => $this->__get_server_info(), 'wp' => $this->__get_wp_info(), 'active_plugins' => $all_plugins['active_plugins'], 'inactive_plugins' => $all_plugins['inactive_plugins'], 'ip_address' => $this->__get_server_ip_address(), 'theme' => get_stylesheet(), 'extra' => [ 'admin_email' => implode( ',', $admin_emails ), ] ]; // for child classes. $extra = $this->get_extra_data(); if ( ! empty( $extra ) ) { $data['extra'] = $data['extra'] + $extra; } return apply_filters( $this->client->getSlug() . '_tracker_data', $data ); } /** * If a child class wants to send extra data * * @return array */ protected function get_extra_data() { return $this->extra_data; } /** * Explain the user which data we collect * * @return array */ protected function data_we_collect() { $data = [ esc_html__( 'Server environment details (MySQL version, MySQL version, Server software & version, etc.).', 'absolute-addons' ), esc_html__( 'WordPress installation details (version, debug mode, max upload size).', 'absolute-addons' ), esc_html__( 'WordPress settings (site language, active and inactive plugins & themes).', 'absolute-addons' ), esc_html__( 'Site Name & URL.', 'absolute-addons' ), esc_html__( 'Admin Name & Email.', 'absolute-addons' ), ]; return apply_filters( $this->client->getSlug() . '_what_tracked', $data ); } /** * Get the message array of what data being collected * @return array */ public function get_data_we_collect() { return $this->data_we_collect(); } /** * Get Site SuperAdmin * Returns Empty WP_User instance if fails * @return WP_User */ private function __get_admin() { $admins = get_users( [ 'role' => 'administrator', 'orderby' => 'ID', 'order' => 'ASC', 'number' => 1, 'paged' => 1, ] ); return ( is_array( $admins ) && ! empty( $admins ) ) ? $admins[0] : new WP_User(); } /** * Check if the user has opted into tracking * * @return bool */ public function is_tracking_allowed() { // If hide_notice is set (optIn notice is hidden by default), then tracking is also disable. // But uninstallation tracking is active. if ( ! $this->show_notice ) { return false; } return 'yes' == get_option( $this->client->getSlug() . '_allow_tracking', 'no' ); } /** * Get the last time a tracking was sent * * @return false|int */ private function __get_last_send() { return get_option( $this->client->getSlug() . '_tracking_last_send', false ); } /** * Check if the notice has been dismissed or enabled * * @return boolean */ private function __notice_dismissed() { $hide_notice = get_option( $this->client->getSlug() . '_tracking_notice', 'no' ); if ( 'hide' == $hide_notice ) { return true; } return false; } /** * Schedule the event weekly * * @return void */ private function __schedule_event() { $hook_name = $this->client->getSlug() . '_tracker_send_event'; if ( ! wp_next_scheduled( $hook_name ) ) { wp_schedule_event( time(), 'weekly', $hook_name ); } } /** * Clear any scheduled hook * * @return void */ private function __clear_schedule_event() { wp_clear_scheduled_hook( $this->client->getSlug() . '_tracker_send_event' ); } /** * Display the admin notice to users that have not opted-in or out * * @return void */ public function admin_notice() { if ( $this->client->is_local_request() ) { return; } if ( $this->__notice_dismissed() ) { return; } if ( $this->is_tracking_allowed() ) { return; } if ( ! current_user_can( 'manage_options' ) ) { return; } $what_tracked = $this->data_we_collect(); // Don't show tracking if a local server. if ( ! empty( $what_tracked ) ) { $trigger = $this->client->getSlug() . '-insights-data-we-collect'; $terms = esc_url_raw( apply_filters( $this->client->getSlug() . '_terms_url', '' ) ); $privacy_policy = esc_url_raw( apply_filters( $this->client->getSlug() . '_privacy_policy_url', '' ) ); $what_we_collect = sprintf( '%s', esc_attr( $trigger ), esc_html__( 'what we collect', 'absolute-addons' ) ); $terms_policy_text = ''; if ( $privacy_policy ) { $privacy_policy = sprintf( '%s', $privacy_policy, esc_html__( 'Privacy Policy', 'absolute-addons' ) ); } if ( $terms ) { $terms = sprintf( '%s', $terms, esc_html__( 'Terms of Services', 'absolute-addons' ) ); } if ( $terms || $privacy_policy ) { if ( $terms && $privacy_policy ) { /* translators: 1: Privacy Policy Link, 2: Terms Links */ $terms_policy_text = sprintf( __( 'Please read our %1$s and %2$s', 'absolute-addons' ), $privacy_policy, $terms ); } else { /* translators: 1: Privacy Policy or Terms Link */ $terms_policy_text = sprintf( __( 'Please read our %1$s', 'absolute-addons' ), $privacy_policy || $terms ); } } if ( empty( $this->notice ) ) { /* translators: 1: plugin name, 2: what we collect button. */ $this->notice = __( '

Want to help make %1$s even more awesome? Allow %1$s to collect non-sensitive diagnostic data and usage information. No sensitive data is tracked (%2$s).

', 'absolute-addons' ); $this->notice = apply_filters( $this->client->getSlug() . '_default_tracking_notice', $this->notice ); } $this->notice = sprintf( $this->notice, '' . esc_html( $this->client->getName() ) . '', $what_we_collect ); ?>
notice ) ); ?>

client->getSlug() . '_tracker_optIn' => 'true', '_wpnonce' => wp_create_nonce( $this->client->getSlug() . '_insight_action' ), ] ); } /** * Tracking Opt Out URL * @return string */ public function get_opt_out_url() { return add_query_arg( [ $this->client->getSlug() . '_tracker_optOut' => 'true', '_wpnonce' => wp_create_nonce( $this->client->getSlug() . '_insight_action' ), ] ); } /** * handle the optIn/optOut * * @return void */ public function handle_optIn_optOut() { if ( isset( $_REQUEST['_wpnonce'] ) && ( isset( $_GET[ $this->client->getSlug() . '_tracker_optIn' ] ) || isset( $_GET[ $this->client->getSlug() . '_tracker_optOut' ] ) ) ) { check_admin_referer( $this->client->getSlug() . '_insight_action' ); if ( isset( $_GET[ $this->client->getSlug() . '_tracker_optIn' ] ) && 'true' == $_GET[ $this->client->getSlug() . '_tracker_optIn' ] ) { $this->optIn(); wp_safe_redirect( remove_query_arg( $this->client->getSlug() . '_tracker_optIn' ) ); exit; } if ( isset( $_GET[ $this->client->getSlug() . '_tracker_optOut' ] ) && 'true' == $_GET[ $this->client->getSlug() . '_tracker_optOut' ] ) { $this->optOut(); wp_safe_redirect( remove_query_arg( $this->client->getSlug() . '_tracker_optOut' ) ); exit; } } } /** * Add query vars to removable query args array * * @param array $removable_query_args array of removable args. * * @return array */ public function add_removable_query_args( $removable_query_args ) { return array_merge( $removable_query_args, [ $this->client->getSlug() . '_tracker_optIn', $this->client->getSlug() . '_tracker_optOut', '_wpnonce' ] ); } /** * Tracking optIn * * @param bool $override_last_send optional. set send tracking data override setting, ignore last send datetime setting if true. * * @return void * @see Insights::send_tracking_data() */ public function optIn( $override_last_send = false ) { update_option( $this->client->getSlug() . '_allow_tracking', 'yes', false ); update_option( $this->client->getSlug() . '_tracking_notice', 'hide', false ); $this->__clear_schedule_event(); $this->__schedule_event(); $this->send_tracking_data( $override_last_send ); } /** * optOut from tracking * * @return void */ public function optOut() { update_option( $this->client->getSlug() . '_allow_tracking', 'no', false ); update_option( $this->client->getSlug() . '_tracking_notice', 'hide', false ); $this->__clear_schedule_event(); } /** * Get the number of post counts * * @param string $post_type PostType name to get count for. * * @return integer */ public function get_post_count( $post_type ) { global $wpdb; // phpcs:disable return (int) $wpdb->get_var( $wpdb->prepare( "SELECT count(ID) FROM $wpdb->posts WHERE post_type = %s and post_status = 'publish'", $post_type ) ); // phpcs:enable } /** * Get server related info. * * @return array */ private function __get_server_info() { global $wpdb; return [ 'software' => ( isset( $_SERVER['SERVER_SOFTWARE'] ) && ! empty( $_SERVER['SERVER_SOFTWARE'] ) ) ? sanitize_text_field( $_SERVER['SERVER_SOFTWARE'] ) : 'N/A', 'php_version' => ( function_exists( 'phpversion' ) ) ? phpversion() : 'N/A', 'mysql_version' => $wpdb->db_version(), 'php_execution_time' => @ini_get( 'max_execution_time' ), // phpcs:ignore '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', 'php_ftp' => function_exists( 'ftp_connect' ) ? 'Yes' : 'No', 'php_sftp' => function_exists( 'ssh2_connect' ) ? 'Yes' : 'No', ]; } /** * Get WordPress related data. * * @return array */ private function __get_wp_info() { return [ 'memory_limit' => WP_MEMORY_LIMIT, 'debug_mode' => ( defined( 'WP_DEBUG' ) && WP_DEBUG ) ? 'Yes' : 'No', 'locale' => get_locale(), 'version' => get_bloginfo( 'version' ), 'multisite' => is_multisite() ? 'Yes' : 'No', ]; } /** * Get the list of active and inactive plugins * @return array */ private function __get_all_plugins() { if ( ! function_exists( 'get_plugins' ) ) { include ABSPATH . '/wp-admin/includes/plugin.php'; } $plugins = get_plugins(); $active_plugins = []; $active_plugins_keys = get_option( 'active_plugins', [] ); foreach ( $plugins as $k => $v ) { // Take care of formatting the data how we want it. $formatted = [ 'name' => isset( $v['Name'] ) ? wp_strip_all_tags( $v['Name'] ) : '', 'version' => isset( $v['Version'] ) ? wp_strip_all_tags( $v['Version'] ) : 'N/A', 'author' => isset( $v['Author'] ) ? wp_strip_all_tags( $v['Author'] ) : 'N/A', 'network' => isset( $v['Network'] ) ? wp_strip_all_tags( $v['Network'] ) : 'N/A', 'plugin_uri' => isset( $v['PluginURI'] ) ? wp_strip_all_tags( $v['PluginURI'] ) : 'N/A', ]; if ( in_array( $k, $active_plugins_keys ) ) { // Remove active plugins from list, so we can show active and inactive separately. unset( $plugins[ $k ] ); $active_plugins[ $k ] = $formatted; } else { $plugins[ $k ] = $formatted; } } return [ 'active_plugins' => $active_plugins, 'inactive_plugins' => $plugins, ]; } /** * Get user totals based on user role. * * @return array */ public function __get_user_counts() { $user_count = []; $user_count_data = count_users(); $user_count['total'] = $user_count_data['total_users']; // Get user count based on user role. foreach ( $user_count_data['avail_roles'] as $role => $count ) { $user_count[ $role ] = $count; } return $user_count; } /** * Add weekly cron schedule * * @param array $schedules Cron Schedules. * * @return array */ public function add_weekly_schedule( $schedules ) { $schedules['weekly'] = [ 'interval' => DAY_IN_SECONDS * 7, 'display' => __( 'Once Weekly', 'absolute-addons' ), ]; return $schedules; } /** * Plugin activation hook * * @return void */ public function activate_plugin() { $allowed = get_option( $this->client->getSlug() . '_allow_tracking', 'no' ); // if it wasn't allowed before, do nothing. if ( 'yes' !== $allowed ) { return; } // Re-schedule and delete the last sent time, so we could force send again. wp_schedule_event( time(), 'weekly', $this->client->getSlug() . '_tracker_send_event' ); delete_option( $this->client->getSlug() . '_tracking_last_send' ); $this->send_tracking_data( true ); } /** * Clear our options upon deactivation * * @return void */ public function deactivation_cleanup() { $this->__clear_schedule_event(); if ( 'theme' == $this->client->getType() ) { delete_option( $this->client->getSlug() . '_tracking_last_send' ); delete_option( $this->client->getSlug() . '_allow_tracking' ); } delete_option( $this->client->getSlug() . '_tracking_notice' ); } protected $action_links = array(); protected $action_links_exclude = array( 'deactivate' ); protected $action_links_html = array( 'b' => [ 'class', 'style' ], 'i' => [ 'class', 'style' ], 'span' => [ 'class', 'style' ], 'strong' => [ 'class', 'style' ], ); protected $action_links_args = array( 'label' => '', 'class' => '', 'href' => '', 'target' => '', 'rel' => '', ); public function add_action_links( $id, $args = [] ) { $args = wp_parse_args( $args, $this->action_links_args ); if ( ! in_array( $id, $this->action_links_exclude ) && ! empty( $args['label'] ) && ! empty( $args['href'] ) ) { $this->action_links[ $id ] = sprintf( '%s', esc_attr( $args['class'] ), esc_url( $args['href'] ), esc_attr( $args['target'] ), esc_attr( $args['rel'] ), wp_kses( $args['label'], $this->action_links_html ) ); } return $this; } /** * Hook into action links and modify the deactivate link * * @param array $links Plugin Action Links. * * @return array */ public function plugin_action_links( $links ) { if ( array_key_exists( 'deactivate', $links ) ) { $links['deactivate'] = str_replace( 'action_links ) ) { $links = $links + $this->action_links; } return $links; } /** * Deactivation reasons * @return array */ private function __get_uninstall_reasons() { $reasons = [ [ 'id' => 'how-to-use', 'text' => esc_html__( "I couldn't understand how to make it work.", 'absolute-addons' ), 'type' => 'textarea', 'placeholder' => esc_html__( 'Would you like us to assist you?', 'absolute-addons' ), ], [ 'id' => 'found-better', 'text' => esc_html__( 'I found a better product.', 'absolute-addons' ), 'type' => 'text', 'placeholder' => esc_html__( 'Which Plugin!?', 'absolute-addons' ), ], [ 'id' => 'feature-needed', 'text' => esc_html__( "The plugin is great, but I need specific feature that you don't support.", 'absolute-addons' ), 'type' => 'textarea', 'placeholder' => esc_html__( 'Can you tell us more about feature that you need?', 'absolute-addons' ), ], [ 'id' => 'not-working', 'text' => esc_html__( 'The plugin is not working.', 'absolute-addons' ), 'type' => 'textarea', 'placeholder' => esc_html__( 'Could you tell us a bit more whats not working?', 'absolute-addons' ), ], [ 'id' => 'looking-for-other', 'text' => esc_html__( "It's not what I was looking for.", 'absolute-addons' ), 'type' => '', 'placeholder' => '', ], [ 'id' => 'not-working-as-expected', 'text' => esc_html__( "The plugin didn't work as expected.", 'absolute-addons' ), 'type' => 'textarea', 'placeholder' => esc_html__( 'Please let us know your needs.', 'absolute-addons' ), ], [ 'id' => 'debugging', 'text' => esc_html__( 'Temporary deactivation for debugging.', 'absolute-addons' ), 'type' => '', 'placeholder' => '', ], [ 'id' => 'other', 'text' => esc_html__( 'Other', 'absolute-addons' ), 'type' => 'textarea', 'placeholder' => esc_html__( 'Could you tell us a bit more?', 'absolute-addons' ), ], ]; $extra = apply_filters( $this->client->getSlug() . '_extra_uninstall_reasons', [], $reasons ); if ( is_array( $extra ) && ! empty( $extra ) ) { // extract the last (other) reason and add after extras. $other = array_pop( $reasons ); $reasons = array_merge( $reasons, $extra, [ $other ] ); } return $reasons; } /** * Plugin deactivation uninstall reason submission * * @return void */ public function uninstall_reason_submission() { check_ajax_referer( $this->client->getSlug() . '_insight_action' ); if ( ! isset( $_POST['reason_id'] ) ) { wp_send_json_error( esc_html__( 'Invalid Request', 'absolute-addons' ) ); wp_die(); } $current_user = wp_get_current_user(); global $wpdb; $reason = sanitize_text_field( $_REQUEST['reason_id'] ); $details = isset( $_REQUEST['reason_info'] ) ? trim( sanitize_textarea_field( $_REQUEST['reason_info'] ) ) : ''; $data = [ 'reason' => $reason, 'url' => esc_url( home_url() ), 'admin_email' => get_option( 'admin_email' ), 'first_name' => ( ! empty( $current_user->first_name ) ) ? $current_user->first_name : $current_user->display_name, 'last_name' => $current_user->last_name, 'details' => $reason . ':' . $details, 'software' => isset( $_SERVER['SERVER_SOFTWARE'] ) ? sanitize_text_field( $_SERVER['SERVER_SOFTWARE'] ) : 'Generic', 'php_version' => phpversion(), 'mysql_version' => $wpdb->db_version(), 'wp_version' => get_bloginfo( 'version' ), 'extra' => [ 'user_email' => $current_user->user_email, 'user_name' => $current_user->display_name, 'site' => $this->__get_site_name(), 'memory_limit' => WP_MEMORY_LIMIT, 'debug_mode' => ( defined( 'WP_DEBUG' ) && WP_DEBUG ) ? 'Yes' : 'No', 'locale' => get_locale(), 'version' => get_bloginfo( 'version' ), 'multisite' => is_multisite() ? 'Yes' : 'No', 'ip_address' => $this->__get_server_ip_address(), 'php_execution_time' => @ini_get( 'max_execution_time' ), // phpcs:ignore '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', 'php_ftp' => function_exists( 'ftp_connect' ) ? 'Yes' : 'No', 'php_sftp' => function_exists( 'ssh2_connect' ) ? 'Yes' : 'No', ], 'locale' => get_locale(), 'multisite' => (int) is_multisite(), ]; // Add extra data. $extra = $this->get_extra_data(); if ( ! empty( $extra ) ) { $data['extra'] = $data['extra'] + $extra; } $response = $this->client->request( [ 'body' => $data, 'route' => 'uninstall' ] ); if ( is_wp_error( $response ) ) { wp_send_json_error( $response ); } else { wp_send_json_success(); } wp_die(); } /** * Handle Support Ticket Submission * @return void */ public function support_ticket_submission() { check_ajax_referer( $this->client->getSlug() . '_insight_action' ); if ( empty( $this->ticketTemplate ) || empty( $this->ticketRecipient ) || empty( $this->supportURL ) ) { wp_send_json_error( sprintf( '

%s
%s

', esc_html__( 'Something Went Wrong.', 'absolute-addons' ), esc_html__( 'Please try again after sometime.', 'absolute-addons' ) ) ); wp_die(); } if ( isset( $_REQUEST['name'], $_REQUEST['email'], $_REQUEST['subject'], $_REQUEST['website'], $_REQUEST['message'] ) && ( ! empty( sanitize_text_field( $_REQUEST['name'] ) ) && ! empty( sanitize_email( $_REQUEST['email'] ) ) && ! empty( sanitize_text_field( $_REQUEST['subject'] ) ) && ! empty( sanitize_text_field( $_REQUEST['website'] ) ) && ! empty( sanitize_text_field( $_REQUEST['message'] ) ) ) ) { $headers = [ 'Content-Type: text/html; charset=UTF-8', sprintf( 'From: %s <%s>', sanitize_text_field( $_REQUEST['name'] ), sanitize_email( $_REQUEST['email'] ) ), sprintf( 'Reply-To: %s <%s>', sanitize_text_field( $_REQUEST['name'] ), sanitize_text_field( $_REQUEST['email'] ) ), ]; foreach ( $_REQUEST as $k => $v ) { $sanitizer = 'sanitize_text_field'; if ( 'email' == $k ) { $sanitizer = 'sanitize_email'; } if ( 'website' == $k ) { $sanitizer = 'esc_url'; } $v = call_user_func_array( $sanitizer, [ $v ] ); $_REQUEST[ $k ] = $v; // phpcs: sanitize ok. $k = '__' . strtoupper( $k ) . '__'; $this->ticketTemplate = str_replace( [ $k ], [ $v ], $this->ticketTemplate ); } $slug = $this->client->getSlug(); $isSent = wp_mail( $this->ticketRecipient, sanitize_text_field( $_REQUEST['subject'] ), sprintf( '
%s
', $this->ticketTemplate ), $headers );// phpcs:ignore WordPressVIPMinimum.Functions.RestrictedFunctions.wp_mail_wp_mail if ( $isSent ) { /** * Set Ajax Success Response for Support Ticket Submission * @param string $supportResponse * @param array $_REQUEST */ $supportResponse = apply_filters( "absp_service_api_{$slug}_Support_Request_Ajax_Success_Response" , false, $_REQUEST ); if ( false !== $supportResponse ) { $this->supportResponse = $supportResponse; } else { $this->supportResponse = sprintf( '

%s

', esc_html__( 'Thank you -- Support Ticket Submitted.', 'absolute-addons' ) ); } wp_send_json_success( $this->supportResponse ); wp_die(); } else { /** * Set Support Ticket Ajax Error Response. * @param string $supportErrorResponse * @param array $_REQUEST */ $supportErrorResponse = apply_filters( "absp_service_api_{$slug}_Support_Request_Ajax_Error_Response" , false, $_REQUEST ); if ( false !== $supportErrorResponse ) { $this->supportErrorResponse = $supportErrorResponse; } else { $this->supportErrorResponse = sprintf( '

%s

', esc_html__( 'Something Went Wrong. Please Try Again After Sometime.', 'absolute-addons' ) ); } wp_send_json_error( $this->supportErrorResponse ); } } else { wp_send_json_error( sprintf( '

%s

', esc_html__( 'Missing Required Fields.', 'absolute-addons' ) ) ); } wp_die(); } /** * Handle the plugin deactivation feedback * * @return void */ public function deactivate_scripts() { global $pagenow; if ( 'plugins.php' !== $pagenow ) { return; } $reasons = $this->__get_uninstall_reasons(); $admin_user = $this->__get_admin(); $displayName = ( ! empty( $admin_user->first_name ) && ! empty( $admin_user->last_name ) ) ? $admin_user->first_name . ' ' . $admin_user->last_name : $admin_user->display_name; $showSupportTicket = ( ! empty( $this->ticketTemplate ) && ! empty( $this->ticketRecipient ) && ! empty( $this->supportURL ) ); $slug = $this->client->getSlug(); ?> get_template() == $this->client->getSlug() ) { $current_user = wp_get_current_user(); /** @noinspection PhpUndefinedFieldInspection */ $data = [ 'reason_id' => 'none', 'reason_info' => wp_json_encode( [ 'new_theme' => [ 'name' => $new_name, 'version' => $new_theme->version, 'parent_theme' => $new_name->parent_theme, 'author' => $new_name->parent_theme, ], ] ), 'site' => $this->__get_site_name(), 'url' => esc_url( home_url() ), 'admin_email' => get_option( 'admin_email' ), 'user_email' => $current_user->user_email, 'first_name' => $current_user->first_name, 'last_name' => $current_user->last_name, 'server' => $this->__get_server_info(), 'wp' => $this->__get_wp_info(), 'ip_address' => $this->__get_server_ip_address(), ]; $this->client->request( [ 'body' => $data, 'route' => 'uninstall' ] ); } } /** * Get user IP Address * @return string */ private function __get_server_ip_address() { $response = wp_safe_remote_get( 'https://icanhazip.com/' ); if ( is_wp_error( $response ) ) { return ''; } $ip = trim( wp_remote_retrieve_body( $response ) ); if ( ! filter_var( $ip, FILTER_VALIDATE_IP ) ) { return ''; } return $ip; } /** * Get site name * @return string */ private function __get_site_name() { $site_name = get_bloginfo( 'name' ); if ( empty( $site_name ) ) { $site_name = get_bloginfo( 'description' ); $site_name = wp_trim_words( $site_name, 3, '' ); } if ( empty( $site_name ) ) { $site_name = get_bloginfo( 'url' ); } return $site_name; } } // End of file class-insights.php.