'array', 'sanitize_callback' => [ $this, 'sanitize' ], 'default' => [], ] ); } public function sanitize( $input ) : array { $clean = []; $clean['api_key'] = isset( $input['api_key'] ) ? sanitize_text_field( $input['api_key'] ) : ''; $clean['engine'] = isset( $input['engine'] ) ? sanitize_key( $input['engine'] ) : 'deepl'; if ( ! in_array( $clean['engine'], self::ALLOWED_ENGINES, true ) ) { $clean['engine'] = 'deepl'; } $endpoint_input = isset( $input['endpoint'] ) ? trim( (string) $input['endpoint'] ) : ''; if ( '' === $endpoint_input ) { $clean['endpoint'] = ''; } elseif ( ! self::is_endpoint_override_allowed() ) { $clean['endpoint'] = ''; add_settings_error( self::OPTION_KEY, 'adara_endpoint_override_disabled', __( 'Custom API endpoint overrides are disabled. Define ADARA_TRANSLATE_ALLOW_ENDPOINT_OVERRIDE in wp-config.php to enable for development.', 'adara-translate' ) ); } else { $sanitized = esc_url_raw( $endpoint_input ); if ( '' === $sanitized || ! self::is_valid_endpoint( $sanitized ) ) { $clean['endpoint'] = ''; add_settings_error( self::OPTION_KEY, 'adara_endpoint_invalid', __( 'API endpoint must be an HTTPS URL (or http://localhost for local dev).', 'adara-translate' ) ); } else { $clean['endpoint'] = $sanitized; } } return $clean; } public function render_page() : void { if ( ! current_user_can( 'manage_options' ) ) { return; } $opts = get_option( self::OPTION_KEY, [] ); $api_key = isset( $opts['api_key'] ) ? (string) $opts['api_key'] : ''; $engine = isset( $opts['engine'] ) ? (string) $opts['engine'] : 'deepl'; $endpoint = isset( $opts['endpoint'] ) ? (string) $opts['endpoint'] : self::DEFAULT_ENDPOINT; ?>