From e87d974f710431341c56739d007fd3a079d87d51 Mon Sep 17 00:00:00 2001 From: Viktor Miller Date: Fri, 16 Jan 2026 11:45:16 +0900 Subject: [PATCH] feat(03-01): create settings class with WordPress Settings API - Settings class with singleton pattern - Registered 5 settings: receiver_email, captcha_provider, captcha_site_key, captcha_secret_key, thankyou_url - Proper sanitization callbacks for each setting type - Helper method get_option() for clean API access - Integrated with admin menu structure --- includes/class-admin-menu.php | 11 +-- includes/class-settings.php | 138 ++++++++++++++++++++++++++++++++++ umzugsliste.php | 4 + 3 files changed, 145 insertions(+), 8 deletions(-) create mode 100644 includes/class-settings.php diff --git a/includes/class-admin-menu.php b/includes/class-admin-menu.php index b51fd09..e30c5dd 100644 --- a/includes/class-admin-menu.php +++ b/includes/class-admin-menu.php @@ -86,13 +86,8 @@ class Umzugsliste_Admin_Menu { * Settings page callback */ public function settings_page() { - ?> -
-

Umzugsliste Einstellungen

-
-

-
-
- render_settings_page(); } } diff --git a/includes/class-settings.php b/includes/class-settings.php new file mode 100644 index 0000000..aefaf73 --- /dev/null +++ b/includes/class-settings.php @@ -0,0 +1,138 @@ + 'string', + 'sanitize_callback' => 'sanitize_email', + 'default' => '', + ) + ); + + // Register captcha provider setting + register_setting( + 'umzugsliste_settings', + 'umzugsliste_captcha_provider', + array( + 'type' => 'string', + 'sanitize_callback' => 'sanitize_text_field', + 'default' => 'none', + ) + ); + + // Register captcha site key setting + register_setting( + 'umzugsliste_settings', + 'umzugsliste_captcha_site_key', + array( + 'type' => 'string', + 'sanitize_callback' => array( $this, 'sanitize_api_key' ), + 'default' => '', + ) + ); + + // Register captcha secret key setting + register_setting( + 'umzugsliste_settings', + 'umzugsliste_captcha_secret_key', + array( + 'type' => 'string', + 'sanitize_callback' => array( $this, 'sanitize_api_key' ), + 'default' => '', + ) + ); + + // Register thank you URL setting + register_setting( + 'umzugsliste_settings', + 'umzugsliste_thankyou_url', + array( + 'type' => 'string', + 'sanitize_callback' => 'esc_url_raw', + 'default' => home_url(), + ) + ); + } + + /** + * Sanitize API key (trim whitespace) + */ + public function sanitize_api_key( $value ) { + return sanitize_text_field( trim( $value ) ); + } + + /** + * Render settings page + */ + public function render_settings_page() { + // Check user capabilities + if ( ! current_user_can( 'edit_posts' ) ) { + return; + } + + ?> +
+

Umzugsliste Einstellungen

+
+ +
+
+