← Back
Editing: SettingsList.php
<?php namespace WPForms\Integrations\UsageTracking; /** * The plugin settings usage tracking reports, and the shape each one is reported in. * * @since 2.0.5.3 */ class SettingsList { /** * Reported settings and their value types. * * A setting missing from this list is never reported. * * @since 2.0.5.3 */ private const TYPES = [ 'gdpr' => 'bool', 'gdpr-disable-uuid' => 'bool', 'gdpr-disable-details' => 'bool', 'global-assets' => 'bool', 'hide-announcements' => 'bool', 'hide-admin-bar' => 'bool', 'uninstall-data' => 'bool', 'usage-tracking-enabled' => 'bool', 'modern-markup' => 'bool', 'modern-markup-is-set' => 'bool', 'modern-markup-hide-setting' => 'bool', 'logs-enable' => 'bool', 'email-async' => 'bool', 'email-carbon-copy' => 'bool', 'email-summaries-disable' => 'bool', 'recaptcha-noconflict' => 'bool', 'turnstile-execution' => 'bool', 'ai-feature-used' => 'bool', 'ai-feature-disabled' => 'bool', 'ai-mcp-write-enabled' => 'bool', 'lite-connect-enabled' => 'bool', 'geolocation-current-location' => 'bool', 'stripe-test-mode' => 'bool', 'stripe-webhooks-enabled' => 'bool', 'square-sandbox-mode' => 'bool', 'square-webhooks-enabled' => 'bool', 'paypal-commerce-sandbox-mode' => 'bool', 'paypal-commerce-webhooks-enabled' => 'bool', 'authorize_net-test-mode' => 'bool', 'mercado_pago-test-mode' => 'bool', 'mercado_pago-webhooks-enabled' => 'bool', 'paystack-test-mode' => 'bool', 'paystack-webhooks-enabled' => 'bool', 'disable-css' => 'option', 'captcha-provider' => 'option', 'recaptcha-type' => 'option', 'turnstile-theme' => 'option', 'currency' => 'option', 'delete-spam-entries' => 'option', 'email-template' => 'option', 'email-typography' => 'option', 'email-typography-dark' => 'option', 'email-header-image-size' => 'option', 'email-header-image-size-dark' => 'option', 'geolocation-field-provider' => 'option', 'user-registration-template' => 'option', 'stripe-card-mode' => 'option', 'stripe-api-version' => 'option', 'stripe-webhooks-communication' => 'option', 'square-webhooks-communication' => 'option', 'paypal-commerce-webhooks-communication' => 'option', 'mercado_pago-webhooks-communication' => 'option', 'paystack-webhooks-communication' => 'option', 'recaptcha-v3-threshold' => 'number', 'lite-connect-enabled-since' => 'int', 'lite-connect-enabled-email' => 'email', ]; /** * Get the stored settings that are reported. * * @since 2.0.5.3 * * @param mixed $settings Stored `wpforms_settings` option. * * @return array */ public function get_allowed( $settings ): array { $settings = is_array( $settings ) ? $settings : []; $allowed = []; foreach ( self::TYPES as $key => $type ) { if ( ! isset( $settings[ $key ] ) ) { continue; } $value = $this->normalize( $settings[ $key ], $type ); if ( $value === null ) { continue; } $allowed[ $key ] = $value; } return $allowed; } /** * Get the value to report for a stored value, or null when it does not fit its type. * * @since 2.0.5.3 * * @param mixed $value Stored value. * @param string $type Value type. * * @return mixed */ private function normalize( $value, string $type ) { // Read the stored toggle the way wpforms_setting() does: any non-empty value is on. if ( $type === 'bool' ) { return ! empty( $value ); } if ( $type === 'option' ) { return $this->normalize_option( $value ); } if ( $type === 'number' ) { return $this->normalize_number( $value ); } if ( $type === 'int' ) { return is_numeric( $value ) ? absint( $value ) : null; } if ( $type === 'email' ) { return is_string( $value ) && is_email( $value ) ? $value : null; } return null; } /** * Get an option value when it is a short string of plain characters or an integer, null otherwise. * * @since 2.0.5.3 * * @param mixed $value Stored value. * * @return string|int|null */ private function normalize_option( $value ) { if ( ! is_string( $value ) && ! is_int( $value ) ) { return null; } return preg_match( '/^[a-z0-9_-]{0,20}$/iD', (string) $value ) === 1 ? $value : null; } /** * Get a number between 0 and 1 rounded to two decimals, null for anything else. * * @since 2.0.5.3 * * @param mixed $value Stored value. * * @return float|null */ private function normalize_number( $value ): ?float { if ( ! is_numeric( $value ) ) { return null; } $number = (float) $value; return $number >= 0 && $number <= 1 ? round( $number, 2 ) : null; } }
Save File
Cancel