PluginProbe
Auto Alt Text / 2.2.0
Auto Alt Text v2.2.0
3.0.3 2.8.2 1.3.1 1.3.2 2.0.0 2.1.0 2.1.1 2.2.0 2.3.0 2.3.1 2.3.2 2.3.3 2.3.4 2.4.0 2.4.1 2.4.2 2.5.0 2.5.1 2.5.2 2.5.3 2.6.0 2.6.1 2.7.0 2.8.0 2.8.1 All 28 releases
auto-alt-text / src / App / Admin / PluginOptions.php

PluginOptions.php in Auto Alt Text 2.2.0, at src/App/Admin/PluginOptions.php

431 lines 23.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace AATXT\App\Admin;
4
5 use AATXT\App\Logging\DBLogger;
6 use AATXT\App\AIProviders\Azure\AzureTranslator;
7 use AATXT\App\Exceptions\Azure\AzureTranslateInstanceException;
8 use AATXT\App\Utilities\AssetsManager;
9 use AATXT\App\Utilities\Encryption;
10 use AATXT\Config\Constants;
11
12 class PluginOptions
13 {
14 private static ?self $instance = null;
15 private static AssetsManager $assetsManager;
16
17 private function __construct()
18 {
19 //
20 }
21
22 /**
23 * Manage the necessary hooks to implement plugin options and their pages
24 * @return void
25 */
26 public static function register(): void
27 {
28 if (is_null(self::$instance)) {
29 self::$instance = new self();
30 }
31
32 self::$assetsManager = AssetsManager::make();
33
34 add_action('admin_enqueue_scripts', [self::$instance, 'enqueueAdminScripts'], 1);
35 add_action('admin_menu', [self::$instance, 'addOptionsPageToTheMenu']);
36 add_action('admin_init', [self::$instance, 'setupPluginOptions']);
37
38 // Encrypt API Keys on update
39 add_action('pre_update_option_' . Constants::AATXT_OPTION_FIELD_API_KEY_AZURE_COMPUTER_VISION, [self::$instance, 'encryptDataOnUpdate'], 10, 3);
40 add_action('pre_update_option_' . Constants::AATXT_OPTION_FIELD_API_KEY_AZURE_TRANSLATE_INSTANCE, [self::$instance, 'encryptDataOnUpdate'], 10, 3);
41 add_action('pre_update_option_' . Constants::AATXT_OPTION_FIELD_API_KEY_OPENAI, [self::$instance, 'encryptDataOnUpdate'], 10, 3);
42 }
43
44 /**
45 * Encrypt data
46 * @param ?string $newValue
47 * @param ?string $oldValue
48 * @return ?string
49 */
50 public function encryptDataOnUpdate(?string $newValue, ?string $oldValue): ?string
51 {
52 if (!empty($newValue)) {
53 $newValue = (Encryption::make())->encrypt($newValue);
54 }
55 return $newValue;
56 }
57
58 /**
59 * @return void
60 */
61 public static function enqueueAdminScripts(): void
62 {
63 $screen = get_current_screen();
64 $isMainOptionsPage = $screen->id === 'toplevel_page_' . Constants::AATXT_PLUGIN_OPTIONS_PAGE_SLUG;
65
66 if ($isMainOptionsPage || strpos($screen->id, Constants::AATXT_PLUGIN_SLUG . '_') !== false) {
67
68 $adminCss = self::$assetsManager->getAssetUrl('resources/js/admin.js', true);
69
70 wp_enqueue_style(Constants::AATXT_PLUGIN_ASSETS_HANDLE, $adminCss, [], false);
71
72 if ($isMainOptionsPage) {
73 $adminJs = self::$assetsManager->getAssetUrl('resources/js/admin.js', false);
74 wp_enqueue_script(Constants::AATXT_PLUGIN_ASSETS_HANDLE, $adminJs, [], false);
75 }
76
77 }
78 }
79
80 /**
81 * Create options pages
82 * @return void
83 */
84 public static function addOptionsPageToTheMenu(): void
85 {
86 add_menu_page('Auto Alt Text Options', 'Auto Alt Text', 'manage_options', Constants::AATXT_PLUGIN_OPTIONS_PAGE_SLUG, [self::$instance, 'optionsMainPage'], null, 99);
87 add_submenu_page(Constants::AATXT_PLUGIN_OPTIONS_PAGE_SLUG, 'Error Log', 'Error log', 'manage_options', Constants::AATXT_PLUGIN_OPTION_LOG_PAGE_SLUG, [self::$instance, 'logOptionsPage']);
88 }
89
90 /**
91 * Implement the page showing error log
92 * @return void
93 */
94 public static function logOptionsPage(): void
95 {
96 ?>
97 <div class="wrap">
98 <h1><?php esc_html_e('Auto Alt Text Error Log', 'auto-alt-text') ?></h1>
99 <div class="aat-options plugin-description">
100 <p>
101 <?php esc_html_e("If the alt text of your images was not generated correctly, you can find the reason in this log.", 'auto-alt-text'); ?>
102 <br>
103 <?php esc_html_e("Each line corresponds to an error generated by a call to the Azure or OpenAI API after uploading an image.", 'auto-alt-text'); ?>
104 </p>
105 <?php
106 $logs = DBLogger::make()->getImageLog();
107 if ($logs) {
108 echo '<textarea id="error-log" name="error-log" readonly>' . esc_textarea($logs) . '</textarea>';
109 } else {
110 echo '<p>' . esc_html__('There is no error log yet!', 'auto-alt-text') . '</p>';
111 }
112
113 ?>
114 </div>
115 </div>
116 <?php
117 }
118
119 /**
120 * Implement the main option page
121 * @return void
122 */
123 public static function optionsMainPage(): void
124 {
125 ?>
126 <div class="wrap">
127 <h1><?php esc_html_e('Auto Alt Text Options', 'auto-alt-text') ?></h1>
128
129 <div class="aat-options plugin-description">
130 <p>
131 <?php esc_html_e("This plugin allows you to automatically generate Alt Text for the images that are uploaded to the site's media library.", 'auto-alt-text'); ?>
132 <br>
133 <?php esc_html_e("The following methods are available to generate the alt text:", 'auto-alt-text'); ?>
134 </p>
135 <ul>
136 <li>
137 <strong><?php esc_html_e("OpenAI's APIs", 'auto-alt-text'); ?></strong>: <?php esc_html_e("the image will be analyzed by the AI services provided by OpenAI and an alt text will be generated based on the prompt you set;", 'auto-alt-text'); ?>
138 </li>
139 <li>
140 <strong><?php esc_html_e("Azure's APIs", 'auto-alt-text'); ?></strong>: <?php esc_html_e("the image will be analyzed by the AI services provided by Azure and an alt text will be generated in the language of your choice;", 'auto-alt-text'); ?>
141 </li>
142 <li>
143 <strong><?php esc_html_e("Title of the article (not AI)", 'auto-alt-text'); ?></strong>: <?php esc_html_e("if the image is uploaded within an article, the title of the article will be used as alt text;", 'auto-alt-text'); ?>
144 </li>
145 <li>
146 <strong><?php esc_html_e("Title of the attachment (not AI)", 'auto-alt-text'); ?></strong>: <?php esc_html_e("the title of the attachment will be copied into the alt text;", 'auto-alt-text'); ?>
147 </li>
148 </ul>
149 <p><?php esc_html_e("Once all the necessary data for the chosen generation method has been entered, the alt texts will be created automatically upon uploading each image.", 'auto-alt-text'); ?></p>
150 <p><strong>New</strong>: <?php esc_html_e("For images already in the media library, you can create bulk alt texts. Open the Media Library in the \"list\" view, select the images for which to generate the alt text, and choose the \"Generate alt text\" bulk action. (Depending on the number of images chosen and their weight, this may take some time.)", 'auto-alt-text'); ?></p>
151 <p>
152 <strong><?php esc_html_e('Pay attention please:', 'auto-alt-text') ?></strong> <?php esc_html_e("if the alt text for an image is not generated, check the logs on the", 'auto-alt-text'); ?>
153 <a href="<?php esc_url(menu_page_url(Constants::AATXT_PLUGIN_OPTION_LOG_PAGE_SLUG, true)); ?>"><?php esc_html_e('designated page.', 'auto-alt-text') ?></a>
154 </p>
155 </div>
156 <form method="post" action="options.php" class="aat-options">
157 <?php
158 settings_fields('auto_alt_text_options');
159
160 echo '<div>';
161 echo '<label for="' . esc_attr(Constants::AATXT_OPTION_FIELD_TYPOLOGY) . '">' . esc_html__('Generation method', 'auto-alt-text') . '</label>';
162 echo '<p class="description">' . esc_html__("Which method do you want to use to generate the alt text for the images?", 'auto-alt-text') . '</p>';
163 $typology = self::typology();
164
165 ?>
166
167 <select name="<?php echo esc_attr(Constants::AATXT_OPTION_FIELD_TYPOLOGY); ?>"
168 id="<?php echo esc_attr(Constants::AATXT_OPTION_FIELD_TYPOLOGY); ?>">
169 <option value="<?php echo esc_attr(Constants::AATXT_OPTION_TYPOLOGY_DEACTIVATED); ?>"<?php echo esc_attr(self::selected($typology, Constants::AATXT_OPTION_TYPOLOGY_DEACTIVATED)); ?>><?php esc_html_e("Deactivated", 'auto-alt-text'); ?></option>
170 <option value="<?php echo esc_attr(Constants::AATXT_OPTION_TYPOLOGY_CHOICE_OPENAI); ?>"<?php echo esc_attr(self::selected($typology, Constants::AATXT_OPTION_TYPOLOGY_CHOICE_OPENAI)); ?>><?php esc_html_e("OpenAI's APIs", 'auto-alt-text'); ?></option>
171 <option value="<?php echo esc_attr(Constants::AATXT_OPTION_TYPOLOGY_CHOICE_AZURE); ?>"<?php echo esc_attr(self::selected($typology, Constants::AATXT_OPTION_TYPOLOGY_CHOICE_AZURE)); ?>><?php esc_html_e("Azure's APIs", 'auto-alt-text'); ?></option>
172 <option value="<?php echo esc_attr(Constants::AATXT_OPTION_TYPOLOGY_CHOICE_ARTICLE_TITLE); ?>"<?php echo esc_attr(self::selected($typology, Constants::AATXT_OPTION_TYPOLOGY_CHOICE_ARTICLE_TITLE)); ?>><?php esc_html_e("Title of the article (not AI)", 'auto-alt-text'); ?></option>
173 <option value="<?php echo esc_attr(Constants::AATXT_OPTION_TYPOLOGY_CHOICE_ATTACHMENT_TITLE); ?>"<?php echo esc_attr(self::selected($typology, Constants::AATXT_OPTION_TYPOLOGY_CHOICE_ATTACHMENT_TITLE)); ?>><?php esc_html_e("Title of the attachment (not AI)", 'auto-alt-text'); ?></option>
174 </select>
175 <?php
176 echo '</div>';
177
178 echo '<div class="plugin-option type-article-title"><strong>' . esc_html__('Notice', 'auto-alt-text') . '</strong>: ' .
179 esc_html__('If you try to insert an image into a post that has not yet been saved as a draft or published, the plugin cannot generate an alt text based on the post\'s title since the title itself has not yet been saved.', 'auto-alt-text') . ' ' .
180 esc_html__('Therefore, the alt text "Auto draft" will be inserted. To avoid this behavior, save the article draft first and then upload the image.', 'auto-alt-text') .
181 '</div>';
182
183 $openaiModel = self::openAiModel();
184
185 echo '<div class="plugin-option type-openai">';
186 echo '<label for="' . esc_attr(Constants::AATXT_OPTION_FIELD_MODEL_OPENAI) . '">' . esc_html__('Model', 'auto-alt-text') . '</label>';
187
188 echo '<select name="' . esc_attr(Constants::AATXT_OPTION_FIELD_MODEL_OPENAI) . '" id="' . esc_attr(Constants::AATXT_OPTION_FIELD_MODEL_OPENAI) . '">';
189 foreach(Constants::AATXT_OPTION_FIELD_MODEL_OPENAI_OPTIONS as $key => $value) {
190 echo '<option value="' . esc_attr($key) . '" ' . esc_attr(self::selected($openaiModel, $key)) . '>' . esc_html($value) . '</option>';
191 }
192 echo '</select>';
193 echo '</div>';
194
195 echo '<div class="plugin-option type-openai"><strong>' . esc_html__('Notice', 'auto-alt-text') . '</strong>: ' .
196 esc_html__('Rarely it may happen that the chosen model fails to generate correct alt text for the image.', 'auto-alt-text') . ' ' .
197 esc_html__('In these cases, the call to the api will be re-performed using the gpt-4o-mini model as fallback.', 'auto-alt-text') . '<br>' .
198 esc_html__('In case of errors, it is still possible to find the specific reason stated on the', 'auto-alt-text') . ' <a href="' . esc_url(menu_page_url(Constants::AATXT_PLUGIN_OPTION_LOG_PAGE_SLUG, false)) . '">' . esc_html__('error log page', 'auto-alt-text') . '</a>.' .
199 '</div>';
200
201 echo '<div class="plugin-option type-openai">';
202 echo '<label for="' . esc_attr(Constants::AATXT_OPTION_FIELD_API_KEY_OPENAI) . '">' . esc_html__('OpenAI API Key', 'auto-alt-text') . '</label>';
203 echo '<p class="description">' . esc_html__("Enter your API Key", 'auto-alt-text') . '</p>';
204 $apiKey = get_option(Constants::AATXT_OPTION_FIELD_API_KEY_OPENAI);
205 echo '<input type="password" name="' . esc_attr(Constants::AATXT_OPTION_FIELD_API_KEY_OPENAI) . '" value="' . esc_attr((Encryption::make())->decrypt($apiKey)) . '" />';
206 echo '</div>';
207
208 echo '<div class="plugin-option type-openai">';
209 echo '<label for="' . esc_attr(Constants::AATXT_OPTION_FIELD_PROMPT_OPENAI) . '">' . esc_html__('Prompt', 'auto-alt-text') . '</label>';
210 echo '<p class="description">' . esc_html__("Enter a specific and detailed prompt according to your needs.", 'auto-alt-text') . '</p>';
211 $defaultPrompt = sprintf(esc_html__("Act like an SEO expert and write an alt text of up to 125 characters for this image.", 'auto-alt-text'), Constants::AATXT_IMAGE_URL_TAG);
212 $prompt = get_option(Constants::AATXT_OPTION_FIELD_PROMPT_OPENAI) ?: $defaultPrompt;
213 echo '<textarea name="' . esc_attr(Constants::AATXT_OPTION_FIELD_PROMPT_OPENAI) . '" rows="5" cols="50">' . esc_textarea($prompt) . '</textarea>';
214 echo '</div>';
215
216 echo '<div class="plugin-option type-azure">' . esc_html__("Fill out the following fields to leverage Azure's computer vision services to generate the Alt texts.", 'auto-alt-text') . '</div>';
217
218 echo '<div class="plugin-option type-azure">';
219 echo '<label for="' . esc_attr(Constants::AATXT_OPTION_FIELD_API_KEY_AZURE_COMPUTER_VISION) . '">' . esc_html__('Azure Computer Vision API Key', 'auto-alt-text') . '</label>';
220 echo '<p class="description">' . esc_html__("Enter the API key for the Computer Vision service of your Azure account.", 'auto-alt-text') . '</p>';
221 $apiKey = get_option(Constants::AATXT_OPTION_FIELD_API_KEY_AZURE_COMPUTER_VISION);
222 echo '<input type="password" name="' . esc_attr(Constants::AATXT_OPTION_FIELD_API_KEY_AZURE_COMPUTER_VISION) . '" value="' . esc_attr((Encryption::make())->decrypt($apiKey)) . '" />';
223 echo '</div>';
224
225 echo '<div class="plugin-option type-azure">';
226 echo '<label for="' . esc_attr(Constants::AATXT_OPTION_FIELD_ENDPOINT_AZURE_COMPUTER_VISION) . '">' . esc_html__('Azure Computer Vision Endpoint', 'auto-alt-text') . '</label>';
227 echo '<p class="description">' . esc_html__("Enter the endpoint of the Computer Vision service.", 'auto-alt-text') . ' (es. https://computer-vision-france-central.cognitiveservices.azure.com/)</p>';
228 $endpoint = get_option(Constants::AATXT_OPTION_FIELD_ENDPOINT_AZURE_COMPUTER_VISION);
229 echo '<input type="text" name="' . esc_attr(Constants::AATXT_OPTION_FIELD_ENDPOINT_AZURE_COMPUTER_VISION) . '" value="' . esc_attr($endpoint) . '" />';
230 echo '</div>';
231
232 echo '<div class="plugin-option type-azure">' .
233 '<strong>' . esc_html__('The default alt text language is English.', 'auto-alt-text') . '</strong><br>' .
234 esc_html__('If you want to translate into another language, enter the following data necessary for the translation API to work.', 'auto-alt-text') . ' ' .
235 esc_html__('After saving the changes you can select the desired language.', 'auto-alt-text') .
236 '</div>';
237
238 echo '<div class="plugin-option type-azure">';
239 echo '<label for="' . esc_attr(Constants::AATXT_OPTION_FIELD_API_KEY_AZURE_TRANSLATE_INSTANCE) . '">' . esc_html__('Azure Translate Instance API Key', 'auto-alt-text') . '</label>';
240 echo '<p class="description">' . esc_html__("Enter your API key for the Azure Translate Instance service.", 'auto-alt-text') . '</p>';
241 $translationApiKey = get_option(Constants::AATXT_OPTION_FIELD_API_KEY_AZURE_TRANSLATE_INSTANCE);
242 echo '<input type="password" name="' . esc_attr(Constants::AATXT_OPTION_FIELD_API_KEY_AZURE_TRANSLATE_INSTANCE) . '" value="' . esc_attr((Encryption::make())->decrypt($translationApiKey)) . '" class="notRequired" />';
243 echo '</div>';
244
245 echo '<div class="plugin-option type-azure">';
246 echo '<label for="' . esc_attr(Constants::AATXT_OPTION_FIELD_ENDPOINT_AZURE_TRANSLATE_INSTANCE) . '">' . esc_html__('Azure Translate Instance Endpoint', 'auto-alt-text') . '</label>';
247 echo '<p class="description">' . esc_html__("Enter the endpoint of the Translate Instance service", 'auto-alt-text') . ' (es. https://api.cognitive.microsofttranslator.com/)</p>';
248 $translationEndpoint = get_option(Constants::AATXT_OPTION_FIELD_ENDPOINT_AZURE_TRANSLATE_INSTANCE);
249 echo '<input type="text" name="' . esc_attr(Constants::AATXT_OPTION_FIELD_ENDPOINT_AZURE_TRANSLATE_INSTANCE) . '" value="' . esc_attr($translationEndpoint) . '" class="notRequired" />';
250 echo '</div>';
251
252 echo '<div class="plugin-option type-azure">';
253 echo '<label for="' . esc_attr(Constants::AATXT_OPTION_FIELD_REGION_AZURE_TRANSLATE_INSTANCE) . '">' . esc_html__('Azure Translate Instance Region', 'auto-alt-text') . '</label>';
254 echo '<p class="description">' . esc_html__("Enter the region of the Azure Translate Instance service.", 'auto-alt-text') . ' (es. westeurope)</p>';
255 $translationRegion = get_option(Constants::AATXT_OPTION_FIELD_REGION_AZURE_TRANSLATE_INSTANCE);
256 echo '<input type="text" name="' . esc_attr(Constants::AATXT_OPTION_FIELD_REGION_AZURE_TRANSLATE_INSTANCE) . '" value="' . esc_attr($translationRegion) . '" class="notRequired" />';
257 echo '</div>';
258
259 if ($translationApiKey && $translationEndpoint && $translationRegion):
260 echo '<div class="plugin-option type-azure">';
261 echo '<label for="' . esc_attr(Constants::AATXT_OPTION_FIELD_LANGUAGE_AZURE_TRANSLATE_INSTANCE) . '">' . esc_html__('Alt Text Language', 'auto-alt-text') . '</label>';
262 echo '<p class="description">' . esc_html__("Select the language in which the alt text should be written.", 'auto-alt-text') . '</p>';
263 $currentLanguage = get_option(Constants::AATXT_OPTION_FIELD_LANGUAGE_AZURE_TRANSLATE_INSTANCE);
264
265 try {
266 $supportedLanguages = (AzureTranslator::make())->supportedLanguages();
267 } catch (AzureTranslateInstanceException $e) {
268 $supportedLanguages = [
269 "en" => [
270 "name" => "English",
271 "nativeName" => "English",
272 "dir" => "ltr",
273 ]
274 ];
275 echo '<p style="color:red"><strong>' . esc_html($e->getMessage()) . '</strong></p>';
276 }
277
278 ?>
279 <select name="<?php echo esc_attr(Constants::AATXT_OPTION_FIELD_LANGUAGE_AZURE_TRANSLATE_INSTANCE); ?>"
280 id="<?php echo esc_attr(Constants::AATXT_OPTION_FIELD_LANGUAGE_AZURE_TRANSLATE_INSTANCE); ?>">
281 <?php
282 foreach ($supportedLanguages as $key => $language):
283 ?>
284 <option value="<?php echo esc_attr($key) ?>" <?php echo esc_attr(self::selected($currentLanguage, $key)); ?>><?php echo esc_html($language['name']); ?></option>
285 <?php
286 endforeach;
287 ?>
288 </select>
289
290 <?php
291
292 echo '</div>';
293 endif;
294
295 submit_button();
296 ?>
297 </form>
298 </div>
299 <?php
300 }
301
302 /**
303 * If option is selected return the selected attribute
304 * @param string $selectedValue
305 * @param string $inputValue
306 * @return string
307 */
308 public static function selected(string $selectedValue, string $inputValue): string
309 {
310 if (empty($selectedValue) && 'en' == $inputValue) {
311 return ' selected';
312 }
313 return $selectedValue == $inputValue ? ' selected' : '';
314 }
315
316
317 /**
318 * Register input fields and option settings
319 * @return void
320 */
321 public static function setupPluginOptions(): void
322 {
323 register_setting('auto_alt_text_options', Constants::AATXT_OPTION_FIELD_API_KEY_OPENAI);
324 register_setting('auto_alt_text_options', Constants::AATXT_OPTION_FIELD_PROMPT_OPENAI, [self::class, 'sanitizeTextArea']);
325 register_setting('auto_alt_text_options', Constants::AATXT_OPTION_FIELD_TYPOLOGY, [self::class, 'sanitizeText']);
326 register_setting('auto_alt_text_options', Constants::AATXT_OPTION_FIELD_MODEL_OPENAI, [self::class, 'sanitizeText']);
327 register_setting('auto_alt_text_options', Constants::AATXT_OPTION_FIELD_API_KEY_AZURE_COMPUTER_VISION);
328 register_setting('auto_alt_text_options', Constants::AATXT_OPTION_FIELD_ENDPOINT_AZURE_COMPUTER_VISION, [self::class, 'sanitizeUrl']);
329 register_setting('auto_alt_text_options', Constants::AATXT_OPTION_FIELD_API_KEY_AZURE_TRANSLATE_INSTANCE);
330 register_setting('auto_alt_text_options', Constants::AATXT_OPTION_FIELD_ENDPOINT_AZURE_TRANSLATE_INSTANCE, [self::class, 'sanitizeUrl']);
331 register_setting('auto_alt_text_options', Constants::AATXT_OPTION_FIELD_REGION_AZURE_TRANSLATE_INSTANCE, [self::class, 'sanitizeText']);
332 register_setting('auto_alt_text_options', Constants::AATXT_OPTION_FIELD_LANGUAGE_AZURE_TRANSLATE_INSTANCE, [self::class, 'sanitizeText']);
333 }
334
335 /**
336 * @return string
337 */
338 public static function typology(): string
339 {
340 return get_option(Constants::AATXT_OPTION_FIELD_TYPOLOGY);
341 }
342
343 public static function openAiModel(): string
344 {
345 return get_option(Constants::AATXT_OPTION_FIELD_MODEL_OPENAI) ?: Constants::AATXT_GPT4O;
346 }
347
348 /**
349 * @return string
350 */
351 public static function prompt(): string
352 {
353 return get_option(Constants::AATXT_OPTION_FIELD_PROMPT_OPENAI);
354 }
355
356 /**
357 * @return string
358 */
359 public static function apiKeyOpenAI(): string
360 {
361 $apiKey = get_option(Constants::AATXT_OPTION_FIELD_API_KEY_OPENAI);
362 return (Encryption::make())->decrypt($apiKey);
363 }
364
365 /**
366 * @return string
367 */
368 public static function apiKeyAzureComputerVision(): string
369 {
370 $apiKey = get_option(Constants::AATXT_OPTION_FIELD_API_KEY_AZURE_COMPUTER_VISION);
371 return (Encryption::make())->decrypt($apiKey);
372 }
373
374 /**
375 * @return string
376 */
377 public static function endpointAzureComputerVision(): string
378 {
379 return get_option(Constants::AATXT_OPTION_FIELD_ENDPOINT_AZURE_COMPUTER_VISION);
380 }
381
382 /**
383 * @return string
384 */
385 public static function apiKeyAzureTranslateInstance(): string
386 {
387 $apiKey = get_option(Constants::AATXT_OPTION_FIELD_API_KEY_AZURE_TRANSLATE_INSTANCE);
388 return (Encryption::make())->decrypt($apiKey);
389 }
390
391 /**
392 * @return string
393 */
394 public static function endpointAzureTranslateInstance(): string
395 {
396 return get_option(Constants::AATXT_OPTION_FIELD_ENDPOINT_AZURE_TRANSLATE_INSTANCE);
397 }
398
399 /**
400 * @return string
401 */
402 public static function regionAzureTranslateInstance(): string
403 {
404 return get_option(Constants::AATXT_OPTION_FIELD_REGION_AZURE_TRANSLATE_INSTANCE);
405 }
406
407 /**
408 * @return string
409 */
410 public static function languageAzureTranslateInstance(): string
411 {
412 return get_option(Constants::AATXT_OPTION_FIELD_LANGUAGE_AZURE_TRANSLATE_INSTANCE) ?: 'en';
413 }
414
415 public static function sanitizeUrl($input): string
416 {
417 return sanitize_url($input);
418 }
419
420 public static function sanitizeText($input): string
421 {
422 return sanitize_text_field($input);
423 }
424
425 public static function sanitizeTextArea($input): string
426 {
427 return sanitize_textarea_field($input);
428 }
429
430 }
431