encrypt($newValue); } return $newValue; } /** * @return void */ public static function enqueueAdminScripts(): void { $screen = get_current_screen(); $isMainOptionsPage = $screen->id === 'toplevel_page_' . Constants::AATXT_PLUGIN_OPTIONS_PAGE_SLUG; if ($isMainOptionsPage || strpos($screen->id, Constants::AATXT_PLUGIN_SLUG . '_') !== false) { $adminCss = self::$assetsManager->getAssetUrl('resources/js/admin.js', true); wp_enqueue_style(Constants::AATXT_PLUGIN_ASSETS_HANDLE, $adminCss, [], false); if ($isMainOptionsPage) { $adminJs = self::$assetsManager->getAssetUrl('resources/js/admin.js', false); wp_enqueue_script(Constants::AATXT_PLUGIN_ASSETS_HANDLE, $adminJs, [], false); } } } /** * Create options pages * @return void */ public static function addOptionsPageToTheMenu(): void { add_menu_page('Auto Alt Text Options', 'Auto Alt Text', 'manage_options', Constants::AATXT_PLUGIN_OPTIONS_PAGE_SLUG, [self::$instance, 'optionsMainPage'], null, 99); 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']); } /** * Implement the page showing error log * @return void */ public static function logOptionsPage(): void { ?>


getImageLog(); if ($logs) { echo ''; } else { echo '

' . esc_html__('There is no error log yet!', 'auto-alt-text') . '

'; } ?>


New:

'; echo ''; echo '

' . esc_html__("Which method do you want to use to generate the alt text for the images?", 'auto-alt-text') . '

'; $typology = self::typology(); ?> '; echo '
' . esc_html__('Notice', 'auto-alt-text') . ': ' . 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') . ' ' . 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') . '
'; $openaiModel = self::openAiModel(); echo '
'; echo ''; echo ''; echo '
'; echo '
' . esc_html__('Notice', 'auto-alt-text') . ': ' . esc_html__('Rarely it may happen that the chosen model fails to generate correct alt text for the image.', 'auto-alt-text') . ' ' . 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') . '
' . esc_html__('In case of errors, it is still possible to find the specific reason stated on the', 'auto-alt-text') . ' ' . esc_html__('error log page', 'auto-alt-text') . '.' . '
'; echo '
'; echo ''; echo '

' . esc_html__("Enter your API Key", 'auto-alt-text') . '

'; $apiKey = get_option(Constants::AATXT_OPTION_FIELD_API_KEY_OPENAI); echo ''; echo '
'; echo '
'; echo ''; echo '

' . esc_html__("Enter a specific and detailed prompt according to your needs.", 'auto-alt-text') . '

'; $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); $prompt = get_option(Constants::AATXT_OPTION_FIELD_PROMPT_OPENAI) ?: $defaultPrompt; echo ''; echo '
'; echo '
' . esc_html__("Fill out the following fields to leverage Azure's computer vision services to generate the Alt texts.", 'auto-alt-text') . '
'; echo '
'; echo ''; echo '

' . esc_html__("Enter the API key for the Computer Vision service of your Azure account.", 'auto-alt-text') . '

'; $apiKey = get_option(Constants::AATXT_OPTION_FIELD_API_KEY_AZURE_COMPUTER_VISION); echo ''; echo '
'; echo '
'; echo ''; echo '

' . esc_html__("Enter the endpoint of the Computer Vision service.", 'auto-alt-text') . ' (es. https://computer-vision-france-central.cognitiveservices.azure.com/)

'; $endpoint = get_option(Constants::AATXT_OPTION_FIELD_ENDPOINT_AZURE_COMPUTER_VISION); echo ''; echo '
'; echo '
' . '' . esc_html__('The default alt text language is English.', 'auto-alt-text') . '
' . esc_html__('If you want to translate into another language, enter the following data necessary for the translation API to work.', 'auto-alt-text') . ' ' . esc_html__('After saving the changes you can select the desired language.', 'auto-alt-text') . '
'; echo '
'; echo ''; echo '

' . esc_html__("Enter your API key for the Azure Translate Instance service.", 'auto-alt-text') . '

'; $translationApiKey = get_option(Constants::AATXT_OPTION_FIELD_API_KEY_AZURE_TRANSLATE_INSTANCE); echo ''; echo '
'; echo '
'; echo ''; echo '

' . esc_html__("Enter the endpoint of the Translate Instance service", 'auto-alt-text') . ' (es. https://api.cognitive.microsofttranslator.com/)

'; $translationEndpoint = get_option(Constants::AATXT_OPTION_FIELD_ENDPOINT_AZURE_TRANSLATE_INSTANCE); echo ''; echo '
'; echo '
'; echo ''; echo '

' . esc_html__("Enter the region of the Azure Translate Instance service.", 'auto-alt-text') . ' (es. westeurope)

'; $translationRegion = get_option(Constants::AATXT_OPTION_FIELD_REGION_AZURE_TRANSLATE_INSTANCE); echo ''; echo '
'; if ($translationApiKey && $translationEndpoint && $translationRegion): echo '
'; echo ''; echo '

' . esc_html__("Select the language in which the alt text should be written.", 'auto-alt-text') . '

'; $currentLanguage = get_option(Constants::AATXT_OPTION_FIELD_LANGUAGE_AZURE_TRANSLATE_INSTANCE); try { $supportedLanguages = (AzureTranslator::make())->supportedLanguages(); } catch (AzureTranslateInstanceException $e) { $supportedLanguages = [ "en" => [ "name" => "English", "nativeName" => "English", "dir" => "ltr", ] ]; echo '

' . esc_html($e->getMessage()) . '

'; } ?> '; endif; submit_button(); ?>
decrypt($apiKey); } /** * @return string */ public static function apiKeyAzureComputerVision(): string { $apiKey = get_option(Constants::AATXT_OPTION_FIELD_API_KEY_AZURE_COMPUTER_VISION); return (Encryption::make())->decrypt($apiKey); } /** * @return string */ public static function endpointAzureComputerVision(): string { return get_option(Constants::AATXT_OPTION_FIELD_ENDPOINT_AZURE_COMPUTER_VISION); } /** * @return string */ public static function apiKeyAzureTranslateInstance(): string { $apiKey = get_option(Constants::AATXT_OPTION_FIELD_API_KEY_AZURE_TRANSLATE_INSTANCE); return (Encryption::make())->decrypt($apiKey); } /** * @return string */ public static function endpointAzureTranslateInstance(): string { return get_option(Constants::AATXT_OPTION_FIELD_ENDPOINT_AZURE_TRANSLATE_INSTANCE); } /** * @return string */ public static function regionAzureTranslateInstance(): string { return get_option(Constants::AATXT_OPTION_FIELD_REGION_AZURE_TRANSLATE_INSTANCE); } /** * @return string */ public static function languageAzureTranslateInstance(): string { return get_option(Constants::AATXT_OPTION_FIELD_LANGUAGE_AZURE_TRANSLATE_INSTANCE) ?: 'en'; } public static function sanitizeUrl($input): string { return sanitize_url($input); } public static function sanitizeText($input): string { return sanitize_text_field($input); } public static function sanitizeTextArea($input): string { return sanitize_textarea_field($input); } }