'string', 'sanitize_callback' => array( $this, 'sanitize_domain_id' ), 'default' => '', ) ); register_setting( 'aiara_settings', 'aiara_enabled', array( 'type' => 'boolean', 'sanitize_callback' => 'rest_sanitize_boolean', 'default' => true, ) ); } public function sanitize_domain_id( $value ): string { $value = trim( sanitize_text_field( $value ) ); if ( '' !== $value && ! ctype_alnum( $value ) ) { add_settings_error( 'aiara_domain_id', 'aiara_invalid_domain_id', __( 'Die Domain-ID darf nur Buchstaben und Zahlen enthalten.', 'aiara-cookie-consent' ), 'error' ); return get_option( 'aiara_domain_id', '' ); } return $value; } public function enqueue_admin_assets( $hook ): void { if ( 'toplevel_page_aiara-cookie-consent' !== $hook ) { return; } wp_enqueue_style( 'aiara-admin', AIARA_PLUGIN_URL . 'assets/css/admin.css', array(), AIARA_VERSION ); wp_enqueue_script( 'aiara-admin', AIARA_PLUGIN_URL . 'assets/js/admin.js', array( 'jquery' ), AIARA_VERSION, true ); wp_localize_script( 'aiara-admin', 'aiaraAdmin', array( 'ajaxUrl' => admin_url( 'admin-ajax.php' ), 'nonce' => wp_create_nonce( 'aiara_test_connection' ), ) ); } public function ajax_test_connection(): void { check_ajax_referer( 'aiara_test_connection', 'nonce' ); if ( ! current_user_can( 'manage_options' ) ) { wp_send_json_error( array( 'message' => __( 'Keine Berechtigung.', 'aiara-cookie-consent' ) ) ); } $domain_id = sanitize_text_field( wp_unslash( $_POST['domain_id'] ?? '' ) ); if ( empty( $domain_id ) || ! ctype_alnum( $domain_id ) ) { wp_send_json_error( array( 'message' => __( 'Bitte geben Sie eine gültige Domain-ID ein.', 'aiara-cookie-consent' ) ) ); } $response = wp_remote_get( AIARA_API_BASE . '/api/v1/banner/' . $domain_id, array( 'timeout' => 10, 'headers' => array( 'Accept' => 'application/json' ), ) ); if ( is_wp_error( $response ) ) { wp_send_json_error( array( /* translators: %s: error message from the HTTP request */ 'message' => sprintf( __( 'Verbindungsfehler: %s', 'aiara-cookie-consent' ), $response->get_error_message() ), ) ); } $code = wp_remote_retrieve_response_code( $response ); if ( 200 === $code ) { $data = json_decode( wp_remote_retrieve_body( $response ), true ); wp_send_json_success( array( 'hostname' => $data['hostname'] ?? '', 'message' => __( 'Verbindung erfolgreich!', 'aiara-cookie-consent' ), ) ); } elseif ( 404 === $code || 403 === $code ) { wp_send_json_error( array( 'message' => __( 'Domain-ID nicht gefunden oder nicht konfiguriert.', 'aiara-cookie-consent' ) ) ); } else { wp_send_json_error( array( /* translators: %d: HTTP status code */ 'message' => sprintf( __( 'Unerwarteter Fehler (HTTP %d).', 'aiara-cookie-consent' ), $code ), ) ); } } public function render_settings_page(): void { $domain_id = get_option( 'aiara_domain_id', '' ); $enabled = get_option( 'aiara_enabled', true ); ?>

v

' . esc_html( $domain_id ) . '' ); ?>

<script src="..." data-cookie-category="analytics" type="text/plain"></script>

analytics, marketing, functional' ); ?>