'array', 'sanitize_callback' => [ $this, 'sanitize' ], 'default' => [], ] ); } /** * Sanitize submitted settings. * * @param array $input Raw values. * @return array */ public function sanitize( $input ) { if ( ! is_array( $input ) ) { $input = []; } $existing = get_option( 'phemightforms_settings', [] ); $provider = isset( $input['captcha_provider'] ) ? sanitize_key( $input['captcha_provider'] ) : ( $existing['captcha_provider'] ?? '' ); if ( ! in_array( $provider, [ '', 'recaptcha_v2', 'hcaptcha', 'turnstile' ], true ) ) { $provider = ''; } $encryption = isset( $input['smtp_encryption'] ) ? sanitize_key( $input['smtp_encryption'] ) : ( $existing['smtp_encryption'] ?? 'tls' ); if ( ! in_array( $encryption, [ 'none', 'ssl', 'tls' ], true ) ) { $encryption = 'tls'; } $mailer = isset( $input['smtp_mailer'] ) ? sanitize_key( $input['smtp_mailer'] ) : ( $existing['smtp_mailer'] ?? 'default' ); if ( ! in_array( $mailer, [ 'default', 'smtp' ], true ) ) { $mailer = 'default'; } // SMTP passwords must not pass through sanitize_text_field(); that can // strip or alter valid password characters. Keep as a string, remove // null bytes only, and preserve the existing value when left blank. $smtp_pass = isset( $input['smtp_pass'] ) ? (string) $input['smtp_pass'] : ''; $smtp_pass = str_replace( "\0", '', $smtp_pass ); if ( '' === $smtp_pass && ! empty( $existing['smtp_pass'] ) ) { $smtp_pass = (string) $existing['smtp_pass']; } return array_merge( $existing, [ 'from_name' => isset( $input['from_name'] ) ? sanitize_text_field( $input['from_name'] ) : ( $existing['from_name'] ?? '' ), 'from_email' => isset( $input['from_email'] ) ? sanitize_email( $input['from_email'] ) : ( $existing['from_email'] ?? '' ), 'honeypot' => isset( $input['honeypot'] ) ? ( ! empty( $input['honeypot'] ) ? 1 : 0 ) : ( $existing['honeypot'] ?? 1 ), 'store_entries' => isset( $input['store_entries'] ) ? ( ! empty( $input['store_entries'] ) ? 1 : 0 ) : ( $existing['store_entries'] ?? 1 ), 'captcha_provider' => $provider, 'captcha_site_key' => isset( $input['captcha_site_key'] ) ? sanitize_text_field( $input['captcha_site_key'] ) : ( $existing['captcha_site_key'] ?? '' ), 'captcha_secret_key' => isset( $input['captcha_secret_key'] ) ? sanitize_text_field( $input['captcha_secret_key'] ) : ( $existing['captcha_secret_key'] ?? '' ), 'entry_retention_days' => isset( $input['entry_retention_days'] ) ? absint( $input['entry_retention_days'] ) : ( $existing['entry_retention_days'] ?? 0 ), 'smtp_mailer' => $mailer, 'smtp_enabled' => 'smtp' === $mailer ? 1 : 0, 'smtp_host' => isset( $input['smtp_host'] ) ? sanitize_text_field( $input['smtp_host'] ) : ( $existing['smtp_host'] ?? '' ), 'smtp_port' => isset( $input['smtp_port'] ) ? absint( $input['smtp_port'] ) : ( $existing['smtp_port'] ?? 587 ), 'smtp_encryption' => $encryption, 'smtp_auth' => isset( $input['smtp_auth'] ) ? ( ! empty( $input['smtp_auth'] ) ? 1 : 0 ) : ( $existing['smtp_auth'] ?? 1 ), 'smtp_user' => isset( $input['smtp_user'] ) ? sanitize_text_field( $input['smtp_user'] ) : ( $existing['smtp_user'] ?? '' ), 'smtp_pass' => $smtp_pass, 'smtp_from_email' => isset( $input['smtp_from_email'] ) ? sanitize_email( $input['smtp_from_email'] ) : ( $existing['smtp_from_email'] ?? '' ), 'smtp_from_name' => isset( $input['smtp_from_name'] ) ? sanitize_text_field( $input['smtp_from_name'] ) : ( $existing['smtp_from_name'] ?? '' ), 'mailchimp_api_key' => isset( $input['mailchimp_api_key'] ) ? sanitize_text_field( $input['mailchimp_api_key'] ) : ( $existing['mailchimp_api_key'] ?? '' ), 'mailchimp_list_id' => isset( $input['mailchimp_list_id'] ) ? sanitize_text_field( $input['mailchimp_list_id'] ) : ( $existing['mailchimp_list_id'] ?? '' ), 'google_sheets_url' => isset( $input['google_sheets_url'] ) ? esc_url_raw( $input['google_sheets_url'] ) : ( $existing['google_sheets_url'] ?? '' ), 'akismet_enabled' => isset( $input['akismet_enabled'] ) ? ( ! empty( $input['akismet_enabled'] ) ? 1 : 0 ) : ( $existing['akismet_enabled'] ?? 0 ), 'akismet_key' => isset( $input['akismet_key'] ) ? sanitize_text_field( $input['akismet_key'] ) : ( $existing['akismet_key'] ?? '' ), ] ); } /** * Output the settings form. */ public static function render_page() { if ( ! current_user_can( Admin::CAPABILITY ) ) { wp_die( esc_html__( 'Permission denied.', 'phemightforms' ) ); } $tab = isset( $_GET['tab'] ) ? sanitize_key( wp_unslash( $_GET['tab'] ) ) : 'general'; // phpcs:ignore WordPress.Security.NonceVerification.Recommended $settings = get_option( 'phemightforms_settings', [] ); $get = static function ( $key, $default = '' ) use ( $settings ) { return isset( $settings[ $key ] ) ? $settings[ $key ] : $default; }; $tabs = [ 'general' => __( 'General', 'phemightforms' ), 'integrations' => __( 'Integrations', 'phemightforms' ), ]; ?>

 1, 'form_name' => 'Contact', 'fields' => [ [ 'label' => 'Email', 'value' => 'user@example.com' ] ], 'date' => '2026-01-01 12:00:00' ], JSON_PRETTY_PRINT ) ); ?>