page_slug, // Menu Slug [ $this, 'render_settings_page' ] // Callback function to render the page ); } /** * Registers settings, sections, and fields using the Settings API. */ public function register_settings() { register_setting( $this->option_group, // Option group $this->option_name, // Option name [ $this, 'sanitize_settings' ] // Sanitization callback ); // Stripe Section add_settings_section( 'quiztech_stripe_section', // Section ID __( 'Stripe API Keys', 'quiztech' ), // Section Title '__return_false', // Section callback (optional description) $this->page_slug // Page slug where section appears ); // Stripe Public Key Field add_settings_field( 'quiztech_stripe_public_key', // Field ID __( 'Stripe Public Key', 'quiztech' ), // Field Title [ $this, 'render_text_field' ], // Field render callback $this->page_slug, // Page slug 'quiztech_stripe_section', // Section ID [ // Arguments for callback 'id' => 'quiztech_stripe_public_key', 'option_name' => $this->option_name, 'key' => 'stripe_public_key', 'description' => __( 'Enter your Stripe publishable API key.', 'quiztech' ) ] ); // Stripe Secret Key Field add_settings_field( 'quiztech_stripe_secret_key', // Field ID __( 'Stripe Secret Key', 'quiztech' ), // Field Title [ $this, 'render_text_field' ], // Field render callback $this->page_slug, // Page slug 'quiztech_stripe_section', // Section ID [ // Arguments for callback 'id' => 'quiztech_stripe_secret_key', 'option_name' => $this->option_name, 'key' => 'stripe_secret_key', 'type' => 'password', // Mask the input 'description' => __( 'Enter your Stripe secret API key. This is kept confidential.', 'quiztech' ) ] ); // --- SMTP Section --- add_settings_section( 'quiztech_smtp_section', // Section ID __( 'SMTP Settings', 'quiztech' ), // Section Title [ $this, 'render_smtp_section_description' ], // Section callback for description $this->page_slug // Page slug where section appears ); // SMTP Enabled Field (Checkbox) add_settings_field( 'quiztech_smtp_enabled', __( 'Enable SMTP', 'quiztech' ), [ $this, 'render_checkbox_field' ], // New callback needed $this->page_slug, 'quiztech_smtp_section', [ 'id' => 'quiztech_smtp_enabled', 'option_name' => $this->option_name, 'key' => 'smtp_enabled', 'description' => __( 'Enable sending emails via a custom SMTP server instead of the default WordPress mail function.', 'quiztech' ) ] ); // SMTP Host Field add_settings_field( 'quiztech_smtp_host', __( 'SMTP Host', 'quiztech' ), [ $this, 'render_text_field' ], $this->page_slug, 'quiztech_smtp_section', [ 'id' => 'quiztech_smtp_host', 'option_name' => $this->option_name, 'key' => 'smtp_host', 'description' => __( 'e.g., smtp.example.com', 'quiztech' ) ] ); // SMTP Port Field add_settings_field( 'quiztech_smtp_port', __( 'SMTP Port', 'quiztech' ), [ $this, 'render_text_field' ], // Use text field, sanitize as number later $this->page_slug, 'quiztech_smtp_section', [ 'id' => 'quiztech_smtp_port', 'option_name' => $this->option_name, 'key' => 'smtp_port', 'type' => 'number', 'description' => __( 'e.g., 587 (TLS) or 465 (SSL)', 'quiztech' ) ] ); // SMTP Encryption Field (Select) add_settings_field( 'quiztech_smtp_encryption', __( 'Encryption', 'quiztech' ), [ $this, 'render_select_field' ], // New callback needed $this->page_slug, 'quiztech_smtp_section', [ 'id' => 'quiztech_smtp_encryption', 'option_name' => $this->option_name, 'key' => 'smtp_encryption', 'options' => [ '' => __( 'None', 'quiztech' ), 'ssl' => __( 'SSL', 'quiztech' ), 'tls' => __( 'TLS', 'quiztech' ), ], 'description' => __( 'Select the encryption method.', 'quiztech' ) ] ); // SMTP Auth Field (Checkbox) add_settings_field( 'quiztech_smtp_auth', __( 'Use Authentication', 'quiztech' ), [ $this, 'render_checkbox_field' ], // Reuse callback $this->page_slug, 'quiztech_smtp_section', [ 'id' => 'quiztech_smtp_auth', 'option_name' => $this->option_name, 'key' => 'smtp_auth', 'description' => __( 'Enable if your SMTP server requires a username and password.', 'quiztech' ) ] ); // SMTP Username Field add_settings_field( 'quiztech_smtp_username', __( 'SMTP Username', 'quiztech' ), [ $this, 'render_text_field' ], $this->page_slug, 'quiztech_smtp_section', [ 'id' => 'quiztech_smtp_username', 'option_name' => $this->option_name, 'key' => 'smtp_username', 'description' => __( 'The username for SMTP authentication.', 'quiztech' ) ] ); // SMTP Password Field add_settings_field( 'quiztech_smtp_password', __( 'SMTP Password', 'quiztech' ), [ $this, 'render_text_field' ], $this->page_slug, 'quiztech_smtp_section', [ 'id' => 'quiztech_smtp_password', 'option_name' => $this->option_name, 'key' => 'smtp_password', 'type' => 'password', 'description' => __( 'The password for SMTP authentication. Stored as plain text in the database.', 'quiztech' ) ] ); // SMTP From Address Field add_settings_field( 'quiztech_smtp_from_address', __( 'From Email Address', 'quiztech' ), [ $this, 'render_text_field' ], $this->page_slug, 'quiztech_smtp_section', [ 'id' => 'quiztech_smtp_from_address', 'option_name' => $this->option_name, 'key' => 'smtp_from_address', 'type' => 'email', 'description' => __( 'The email address emails will be sent from.', 'quiztech' ) ] ); // SMTP From Name Field add_settings_field( 'quiztech_smtp_from_name', __( 'From Name', 'quiztech' ), [ $this, 'render_text_field' ], $this->page_slug, 'quiztech_smtp_section', [ 'id' => 'quiztech_smtp_from_name', 'option_name' => $this->option_name, 'key' => 'smtp_from_name', 'description' => __( 'The name emails will be sent from.', 'quiztech' ) ] ); // Future settings sections/fields (e.g., email, defaults) should be registered here. } // End register_settings() /** * Renders the main settings page container and form. */ public function render_settings_page() { ?>