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 = array() ) { $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() { // Env Setup. $projectSlug = $this->client->getSlug(); /** * Support Page URL * @param string $supportURL */ $supportURL = apply_filters( "WebAppick_{$projectSlug}_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( "WebAppick_{$projectSlug}_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( "WebAppick_{$projectSlug}_Support_Ticket_Email_Template", false ); if ( FALSE !== $ticketTemplate ) { $this->ticketTemplate = $ticketTemplate; } // initialize. if ( $this->client->getType() == 'plugin' ) { $this->init_plugin(); } elseif ( $this->client->getType() == 'theme' ) { $this->init_theme(); } $this->didInit = 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->__is_local_server() ) { add_action( 'plugin_action_links_' . $this->client->getBasename(), [ $this, 'plugin_action_links' ] ); add_action( 'admin_footer', [ $this, 'deactivate_scripts' ] ); } $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' ], 10, 1 ); // 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 WebAppick 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 * * @see strtotime() * @link https://www.php.net/manual/en/function.strtotime.php */ $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->send_request( $this->get_tracking_data(), '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(); $store_country = get_option('woocommerce_default_country'); $admin_emails = [ get_option( 'admin_email' ), $admin_user->user_email ]; $admin_emails = array_filter( $admin_emails ); $admin_emails = array_unique( $admin_emails ); $data = [ 'version' => $this->client->getProjectVersion(), 'url' => esc_url( home_url() ), 'site' => $this->__get_site_name(), 'admin_email' => implode( ',', $admin_emails ), 'first_name' => $admin_user->first_name ? $admin_user->first_name : $admin_user->display_name, 'last_name' => $admin_user->last_name, 'plugin' => $this->client->getName(), 'hash' => $this->client->getHash(), '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_user_ip_address(), 'theme' => get_stylesheet(), 'country' => $store_country ]; // for child classes. $extra = $this->get_extra_data(); if ( ! empty( $extra ) ) { $data['extra'] = $extra; } return apply_filters( $this->client->getSlug() . '_tracker_data', $data ); } /** * If a child class wants to send extra data * * @return mixed */ 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 (php, mysql, server, WordPress versions).', 'woo-feed' ), ]; $data = apply_filters( $this->client->getSlug() . '_what_tracked', $data ); return $data; } /** * Get the message array of what data being collected * @return array */ public function get_data_collection_description() { 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() { 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; } /** * Check if the current server is localhost * * @return boolean */ public function __is_local_server() { // phpcs:disable return apply_filters( 'WebAppick_is_local', isset( $_SERVER['REMOTE_ADDR'] ) ? in_array( $_SERVER['REMOTE_ADDR'], [ '127.0.0.1', '::1' ] ) : true ); // phpcs:enable } /** * 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->__notice_dismissed() ) { return; } if ( $this->is_tracking_allowed() ) { return; } if ( ! current_user_can( 'manage_options' ) ) { return; } // don't show tracking if a local server. if ( ! $this->__is_local_server() ) { if ( empty( $this->notice ) ) { $notice = sprintf( apply_filters( $this->client->getSlug() . '_tracking_default_notice_message', /* translators: 1: plugin name */ esc_html__( 'Want to help make %1$s even more awesome? Allow %1$s to collect non-sensitive diagnostic data and usage information.', 'woo-feed' ) ), '' . esc_html( $this->client->getName() ) . '' ); } else { $notice = $this->notice; } $notice .= ' (' . esc_html__( 'what we collect', 'woo-feed' ) . ')'; $notice .= ''; echo '

'; echo wp_kses_post($notice); // phpcs:ignore xss ok echo '

'; echo ' ' . esc_html__( 'No thanks', 'woo-feed' ) . ''; echo ' ' . esc_html__( 'Allow', 'woo-feed' ) . ''; echo '

'; echo ""; } } /** * Tracking Opt In URL * @return string */ public function get_opt_in_url() { return add_query_arg( [ $this->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 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 = 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 ); } /** * 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; $server_data = [ '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', ]; return $server_data; } /** * Get WordPress related data. * * @return array */ private function __get_wp_info() { $wp_data = [ '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', ]; return $wp_data; } /** * 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 ) ) { unset( $plugins[ $k ] ); // Remove active plugins from list so we can show active and inactive separately0 $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', 'woo-feed' ), ]; 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' ); } /** * 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( ' 'could-not-understand', 'text' => esc_html__( 'I couldn\'t understand how to make it work', 'woo-feed' ), 'type' => 'textarea', 'placeholder' => esc_html__( 'Would you like us to assist you?', 'woo-feed' ), ], [ 'id' => 'found-better-plugin', 'text' => esc_html__( 'I found a better plugin', 'woo-feed' ), 'type' => 'text', 'placeholder' => esc_html__( 'Which plugin?', 'woo-feed' ), ], [ 'id' => 'not-have-that-feature', 'text' => esc_html__( 'The plugin is great, but I need specific feature that you don\'t support', 'woo-feed' ), 'type' => 'textarea', 'placeholder' => esc_html__( 'Could you tell us more about that feature?', 'woo-feed' ), ], [ 'id' => 'is-not-working', 'text' => esc_html__( 'The plugin is not working', 'woo-feed' ), 'type' => 'textarea', 'placeholder' => esc_html__( 'Could you tell us a bit more whats not working?', 'woo-feed' ), ], [ 'id' => 'looking-for-other', 'text' => esc_html__( 'It\'s not what I was looking for', 'woo-feed' ), 'type' => '', 'placeholder' => '', ], [ 'id' => 'did-not-work-as-expected', 'text' => esc_html__( 'The plugin didn\'t work as expected', 'woo-feed' ), 'type' => 'textarea', 'placeholder' => esc_html__( 'What did you expect?', 'woo-feed' ), ], [ 'id' => 'debugging', 'text' => esc_html__( 'Temporary deactivation for debugging', 'woo-feed' ), 'type' => '', 'placeholder' => '', ], [ 'id' => 'other', 'text' => esc_html__( 'Other', 'woo-feed' ), 'type' => 'textarea', 'placeholder' => esc_html__( 'Could you tell us a bit more?', 'woo-feed' ), ], ]; $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', 'woo-feed' ) ); wp_die(); } $current_user = wp_get_current_user(); global $wpdb; // @TODO remove deprecated data after server update $data = [ 'hash' => $this->client->getHash(), 'reason_id' => isset( $_REQUEST['reason_id'] ) && ! empty( $_REQUEST['reason_id'] ) ? sanitize_text_field( $_REQUEST['reason_id'] ) : '', 'reason_info' => isset( $_REQUEST['reason_info'] ) ? trim( sanitize_textarea_field( $_REQUEST['reason_info'] ) ) : '', 'plugin' => $this->client->getName(), 'site' => $this->__get_site_name(), 'url' => esc_url( home_url() ), 'admin_email' => get_option( 'admin_email' ), 'user_email' => $current_user->user_email, 'user_name' => $current_user->display_name, // deprecated. 'first_name' => ( ! empty( $current_user->first_name ) ) ? $current_user->first_name : $current_user->display_name, 'last_name' => $current_user->last_name, 'server' => $this->__get_server_info(), 'software' => isset( $_SERVER['SERVER_SOFTWARE'] ) ? sanitize_text_field( $_SERVER['SERVER_SOFTWARE'] ) : 'Generic', // deprecated, using $data['server'] for wp info. 'php_version' => phpversion(), // deprecated, using $data['server'] for wp info. 'mysql_version' => $wpdb->db_version(), // deprecated, using $data['server'] for wp info. 'wp' => $this->__get_wp_info(), 'wp_version' => get_bloginfo( 'version' ), // deprecated, using $data['wp'] for wp info. 'locale' => get_locale(), // deprecated, using $data['wp'] for wp info. 'multisite' => is_multisite() ? 'Yes' : 'No', // deprecated, using $data['wp'] for wp info. 'ip_address' => $this->__get_user_ip_address(), 'version' => $this->client->getProjectVersion(), ]; // Add extra data. $extra = $this->get_extra_data(); if ( ! empty( $extra ) ) { $data['extra'] = $extra; } $this->client->send_request( $data, 'reason' ); 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.', 'woo-feed' ), esc_html__( 'Please try again after sometime.', 'woo-feed' ) ) ); 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 ); } $projectSlug = $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( "WebAppick_{$projectSlug}_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.', 'woo-feed' ) ); } wp_send_json_success( $this->supportResponse ); wp_die(); } else { /** * Set Support Ticket Ajax Error Response. * @param string $supportErrorResponse * @param array $_REQUEST */ $supportErrorResponse = apply_filters( "WebAppick_{$projectSlug}_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.', 'woo-feed' ) ); } wp_send_json_error( $this->supportErrorResponse ); } } else { wp_send_json_error( sprintf( '

%s

', esc_html__( 'Missing Required Fields.', 'woo-feed' ) ) ); } 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 ) ); ?> get_template() == $this->client->getSlug() ) { $current_user = wp_get_current_user(); /** @noinspection PhpUndefinedFieldInspection */ $data = [ 'hash' => $this->client->getHash(), '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_user_ip_address(), 'version' => $this->client->getProjectVersion(), ]; $this->client->send_request( $data, 'reason' ); } } /** * Get user IP Address * @return string */ private function __get_user_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 Insights.php.