@@ -116,12 +116,11 @@ protected function _renderContent() {
116116 echo '<tr> ' ;
117117 echo '<th scope="row"><label for="visualizer_openai_api_key"> ' . esc_html__ ( 'OpenAI API Key (ChatGPT) ' , 'visualizer ' ) . '</label></th> ' ;
118118 echo '<td> ' ;
119- echo '<div style="position: relative; display: inline-block; width: 100%;"> ' ;
120- echo '<input type="password" id="visualizer_openai_api_key" name="visualizer_openai_api_key" value=" ' . esc_attr ( $ openai_key ) . '" class="regular-text visualizer-api-key-input" placeholder=" ' . ( $ has_openai_key ? esc_attr__ ( 'API key is set (enter new key to replace) ' , 'visualizer ' ) : '' ) . '" autocomplete="off" /> ' ;
121- echo '<button type="button" class="button visualizer-toggle-key" data-target="visualizer_openai_api_key" style="margin-left: 5px; vertical-align: top;"> ' ;
122- echo '<span class="dashicons dashicons-visibility" style="margin-top: 3px;"></span> ' ;
123- echo '</button> ' ;
124- echo '</div> ' ;
119+ echo '<input type="password" id="visualizer_openai_api_key" name="visualizer_openai_api_key" value="" class="regular-text" placeholder=" ' . ( $ has_openai_key ? esc_attr__ ( 'API key is set (enter new key to replace) ' , 'visualizer ' ) : esc_attr__ ( 'Enter API key ' , 'visualizer ' ) ) . '" autocomplete="off" /> ' ;
120+ if ( $ has_openai_key ) {
121+ echo '<input type="hidden" name="visualizer_openai_api_key_exists" value="1" /> ' ;
122+ echo '<p class="description" style="color: #46b450; font-weight: 500;"><span class="dashicons dashicons-yes-alt" style="color: #46b450;"></span> ' . esc_html__ ( 'API key is configured ' , 'visualizer ' ) . '</p> ' ;
123+ }
125124 echo '<p class="description"> ' . esc_html__ ( 'Enter your OpenAI API key to enable ChatGPT integration. ' , 'visualizer ' ) . ' <a href="https://platform.openai.com/api-keys" target="_blank"> ' . esc_html__ ( 'Get API Key ' , 'visualizer ' ) . '</a></p> ' ;
126125 echo '</td> ' ;
127126 echo '</tr> ' ;
@@ -130,12 +129,11 @@ protected function _renderContent() {
130129 echo '<tr> ' ;
131130 echo '<th scope="row"><label for="visualizer_gemini_api_key"> ' . esc_html__ ( 'Google Gemini API Key ' , 'visualizer ' ) . '</label></th> ' ;
132131 echo '<td> ' ;
133- echo '<div style="position: relative; display: inline-block; width: 100%;"> ' ;
134- echo '<input type="password" id="visualizer_gemini_api_key" name="visualizer_gemini_api_key" value=" ' . esc_attr ( $ gemini_key ) . '" class="regular-text visualizer-api-key-input" placeholder=" ' . ( $ has_gemini_key ? esc_attr__ ( 'API key is set (enter new key to replace) ' , 'visualizer ' ) : '' ) . '" autocomplete="off" /> ' ;
135- echo '<button type="button" class="button visualizer-toggle-key" data-target="visualizer_gemini_api_key" style="margin-left: 5px; vertical-align: top;"> ' ;
136- echo '<span class="dashicons dashicons-visibility" style="margin-top: 3px;"></span> ' ;
137- echo '</button> ' ;
138- echo '</div> ' ;
132+ echo '<input type="password" id="visualizer_gemini_api_key" name="visualizer_gemini_api_key" value="" class="regular-text" placeholder=" ' . ( $ has_gemini_key ? esc_attr__ ( 'API key is set (enter new key to replace) ' , 'visualizer ' ) : esc_attr__ ( 'Enter API key ' , 'visualizer ' ) ) . '" autocomplete="off" /> ' ;
133+ if ( $ has_gemini_key ) {
134+ echo '<input type="hidden" name="visualizer_gemini_api_key_exists" value="1" /> ' ;
135+ echo '<p class="description" style="color: #46b450; font-weight: 500;"><span class="dashicons dashicons-yes-alt" style="color: #46b450;"></span> ' . esc_html__ ( 'API key is configured ' , 'visualizer ' ) . '</p> ' ;
136+ }
139137 echo '<p class="description"> ' . esc_html__ ( 'Enter your Google Gemini API key. ' , 'visualizer ' ) . ' <a href="https://makersuite.google.com/app/apikey" target="_blank"> ' . esc_html__ ( 'Get API Key ' , 'visualizer ' ) . '</a></p> ' ;
140138 echo '</td> ' ;
141139 echo '</tr> ' ;
@@ -144,12 +142,11 @@ protected function _renderContent() {
144142 echo '<tr> ' ;
145143 echo '<th scope="row"><label for="visualizer_claude_api_key"> ' . esc_html__ ( 'Anthropic Claude API Key ' , 'visualizer ' ) . '</label></th> ' ;
146144 echo '<td> ' ;
147- echo '<div style="position: relative; display: inline-block; width: 100%;"> ' ;
148- echo '<input type="password" id="visualizer_claude_api_key" name="visualizer_claude_api_key" value=" ' . esc_attr ( $ claude_key ) . '" class="regular-text visualizer-api-key-input" placeholder=" ' . ( $ has_claude_key ? esc_attr__ ( 'API key is set (enter new key to replace) ' , 'visualizer ' ) : '' ) . '" autocomplete="off" /> ' ;
149- echo '<button type="button" class="button visualizer-toggle-key" data-target="visualizer_claude_api_key" style="margin-left: 5px; vertical-align: top;"> ' ;
150- echo '<span class="dashicons dashicons-visibility" style="margin-top: 3px;"></span> ' ;
151- echo '</button> ' ;
152- echo '</div> ' ;
145+ echo '<input type="password" id="visualizer_claude_api_key" name="visualizer_claude_api_key" value="" class="regular-text" placeholder=" ' . ( $ has_claude_key ? esc_attr__ ( 'API key is set (enter new key to replace) ' , 'visualizer ' ) : esc_attr__ ( 'Enter API key ' , 'visualizer ' ) ) . '" autocomplete="off" /> ' ;
146+ if ( $ has_claude_key ) {
147+ echo '<input type="hidden" name="visualizer_claude_api_key_exists" value="1" /> ' ;
148+ echo '<p class="description" style="color: #46b450; font-weight: 500;"><span class="dashicons dashicons-yes-alt" style="color: #46b450;"></span> ' . esc_html__ ( 'API key is configured ' , 'visualizer ' ) . '</p> ' ;
149+ }
153150 echo '<p class="description"> ' . esc_html__ ( 'Enter your Anthropic Claude API key. ' , 'visualizer ' ) . ' <a href="https://console.anthropic.com/account/keys" target="_blank"> ' . esc_html__ ( 'Get API Key ' , 'visualizer ' ) . '</a></p> ' ;
154151 echo '</td> ' ;
155152 echo '</tr> ' ;
@@ -162,28 +159,6 @@ protected function _renderContent() {
162159
163160 echo '</form> ' ;
164161
165- // Add JavaScript to handle show/hide toggle
166- ?>
167- <script type="text/javascript">
168- jQuery(document).ready(function($) {
169- $('.visualizer-toggle-key').on('click', function() {
170- var $button = $(this);
171- var targetId = $button.attr('data-target');
172- var $input = $('#' + targetId);
173- var $icon = $button.find('.dashicons');
174-
175- if ($input.attr('type') === 'password') {
176- $input.attr('type', 'text');
177- $icon.removeClass('dashicons-visibility').addClass('dashicons-hidden');
178- } else {
179- $input.attr('type', 'password');
180- $icon.removeClass('dashicons-hidden').addClass('dashicons-visibility');
181- }
182- });
183- });
184- </script>
185- <?php
186-
187162 echo '</div> ' ; // End opacity wrapper
188163
189164 if ( $ is_locked ) {
@@ -202,15 +177,18 @@ protected function _renderContent() {
202177 * @return void
203178 */
204179 private function _saveSettings () {
205- if ( isset ( $ _POST ['visualizer_openai_api_key ' ] ) ) {
180+ // Only update OpenAI key if a new value is provided
181+ if ( isset ( $ _POST ['visualizer_openai_api_key ' ] ) && ! empty ( $ _POST ['visualizer_openai_api_key ' ] ) ) {
206182 update_option ( 'visualizer_openai_api_key ' , sanitize_text_field ( $ _POST ['visualizer_openai_api_key ' ] ) );
207183 }
208184
209- if ( isset ( $ _POST ['visualizer_gemini_api_key ' ] ) ) {
185+ // Only update Gemini key if a new value is provided
186+ if ( isset ( $ _POST ['visualizer_gemini_api_key ' ] ) && ! empty ( $ _POST ['visualizer_gemini_api_key ' ] ) ) {
210187 update_option ( 'visualizer_gemini_api_key ' , sanitize_text_field ( $ _POST ['visualizer_gemini_api_key ' ] ) );
211188 }
212189
213- if ( isset ( $ _POST ['visualizer_claude_api_key ' ] ) ) {
190+ // Only update Claude key if a new value is provided
191+ if ( isset ( $ _POST ['visualizer_claude_api_key ' ] ) && ! empty ( $ _POST ['visualizer_claude_api_key ' ] ) ) {
214192 update_option ( 'visualizer_claude_api_key ' , sanitize_text_field ( $ _POST ['visualizer_claude_api_key ' ] ) );
215193 }
216194 }
0 commit comments