[ 'label' => 'From-Email', 'type' => 'email', 'required' => true, 'placeholder' => 'you@example.com' ], 'actra-smtp_hostname' => [ 'label' => 'SMTP-Hostname', 'type' => 'text', 'required' => true, 'placeholder' => 'smtp.example.com or localhost' ], 'actra-smtp_username' => [ 'label' => 'SMTP-Username', 'type' => 'text', 'description' => 'Leave empty if your SMTP server does not require authentication.' ], 'actra-smtp_password' => [ 'label' => 'SMTP-Password', 'type' => 'password', 'description' => 'Leave empty if your SMTP server does not require authentication.' ], 'actra-smtp_port' => [ 'label' => 'SMTP-Port', 'type' => 'number', 'required' => true, 'default' => 587 ], 'actra-smtp_tls' => [ 'label' => 'SMTP-TLS', 'type' => 'select', 'options' => ['yes' => 'Yes', 'no' => 'No'] ], ]; add_settings_section( id: 'actra-smtp_main', title: 'Connection Settings', callback: '__return_null', page: Settings::PAGE ); foreach ($fields as $id => $args) { $register_args = [ 'type' => 'string', 'default' => $args['default'] ?? '', ]; switch ($args['type']) { case 'email': $register_args['sanitize_callback'] = 'sanitize_email'; break; case 'number': $register_args['type'] = 'integer'; $register_args['sanitize_callback'] = 'absint'; break; case 'password': // Pass-through to not change a valid password. break; default: $register_args['sanitize_callback'] = 'sanitize_text_field'; break; } register_setting( option_group: Settings::GROUP, option_name: $id, args: $register_args ); add_settings_field( id: $id, title: $args['label'], callback: [$this, 'render_field'], page: Settings::PAGE, section: 'actra-smtp_main', args: array_merge(['id' => $id], $args) ); } } public function render_field(array $args): void { $value = get_option(option: $args['id'], default_value: $args['default'] ?? ''); if ('select' === $args['type']) { echo ''; } else { printf( '', esc_attr(text: $args['type']), esc_attr(text: $args['id']), esc_attr(text: $value), !empty($args['required']) ? ' required' : '', !empty($args['placeholder']) ? ' placeholder="' . esc_attr(text: $args['placeholder']) . '"' : '' ); } if (!empty($args['description'])) { printf('
%s
', esc_html(text: $args['description'])); } } public function render_settings_page(): void { ?>