' ) : ''; if ( false !== strpos( $error_body, 'MalCare' ) ) { /* translators: %1$s: HTML, %2$s: HTML, %3$s: HTML */ $error_message = $error_message . '' . sprintf( __( 'Sorry for the inconvenience, but your website seems to be having trouble connecting to our server. %1$s Please open a technical %2$ssupport ticket%3$s and share the server\'s outgoing IP address.', 'cartflows' ), '', '', '' ); $ip_address = self::get_valid_ip_address(); $result['message'] = ! empty( $ip_address ) ? __( 'Server\'s outgoing IP address: ', 'cartflows' ) . $ip_address : ''; } $result['error'] = true; $result['call_to_action'] = $error_message; $result['error_code'] = wp_remote_retrieve_response_code( $response ); } else { $result['response_code'] = wp_remote_retrieve_response_code( $response ); } return $result; } /** * Convert the array format in the WooCommerce's expected format for display. * Received array format is array( 0=>key, 1=>Key_value ) expected is array( key=>key_value ) * This is because of the core rules structure which we have created. * * @param array $options Array of key & value in the array format. * @return array $options */ public static function sanitize_array_values( $options ) { if ( is_array( $options ) ) { $sanitized_options = array(); foreach ( $options as $option_key => $option_value ) { $sanitized_options[ trim( $option_value ) ] = trim( $option_value ); } $options = $sanitized_options; } return $options; } /** * Get the IP address of the user's server. * To check weather the IP is not blocked by any firewall. * * Note: This IP address is not stored any where in the database. * * @return string A valid IP address. */ public static function get_valid_ip_address() { if ( isset( $_SERVER['HTTP_X_REAL_IP'] ) ) { //phpcs:ignore WordPressVIPMinimum.Variables.ServerVariables.UserControlledHeaders return self::validate_ip_address( sanitize_text_field( wp_unslash( $_SERVER['HTTP_X_REAL_IP'] ) ) ); } elseif ( isset( $_SERVER['REMOTE_ADDR'] ) ) { //phpcs:ignore WordPressVIPMinimum.Variables.ServerVariables.UserControlledHeaders return self::validate_ip_address( sanitize_text_field( wp_unslash( $_SERVER['REMOTE_ADDR'] ) ) ); //phpcs:ignore WordPressVIPMinimum.Variables.ServerVariables.UserControlledHeaders, WordPressVIPMinimum.Variables.RestrictedVariables.cache_constraints___SERVER__REMOTE_ADDR__ } elseif ( isset( $_SERVER['SERVER_ADDR'] ) ) { //phpcs:ignore WordPressVIPMinimum.Variables.ServerVariables.UserControlledHeaders return self::validate_ip_address( sanitize_text_field( wp_unslash( $_SERVER['SERVER_ADDR'] ) ) ); } else { return ''; } } /** * Validate the provided IP address safe to printing. * * @param string $ip_address IP address to validate. * @return string $ip_address Validated IP address for display/use. */ public static function validate_ip_address( $ip_address ) { $ip_address = filter_var( $ip_address, FILTER_VALIDATE_IP, array() ); return $ip_address ? $ip_address : ''; } /** * Track funnel creation method for analytics. * * @param string $creation_method The method used to create the funnel (e.g., 'scratch', 'ready_made_template'). * @return void */ public static function track_funnel_creation_method( $creation_method ) { $funnel_creation_stats = get_option( 'cartflows_funnel_creation_method', array( 'scratch' => 0, 'ready_made_template' => 0, ) ); if ( isset( $funnel_creation_stats[ $creation_method ] ) ) { $funnel_creation_stats[ $creation_method ]++; } update_option( 'cartflows_funnel_creation_method', $funnel_creation_stats ); } /** * Determine whether to show the CodeMirror code editor fields. * * Returns true when the custom script migration status is 'completed', * meaning users should see the new separate JS and CSS code editors * instead of the old combined textarea. * * @since 2.2.2 * @return bool */ public static function should_show_code_editor() { return 'completed' === \CartFlows_Helper::get_script_migration_status(); } /** * Get the field type for custom script fields based on migration status. * * Returns 'code' after migration is completed, 'textarea' otherwise. * * @since 2.2.2 * @return string 'code' or 'textarea' */ public static function get_custom_script_field_type() { return self::should_show_code_editor() ? 'code' : 'textarea'; } }