'; printf( wp_kses( /* translators: %s: AltTextLab settings page link */ __( '[AltTextLab] Thanks for installing AltTextLab! To complete setup, please go to the settings page.', 'alttextlab' ), array( 'a' => array( 'href' => array() ) ) ), esc_url(admin_url( 'admin.php?page=alttextlab' )) ); echo '

'; } /** * Shows an alert message when user's credit balance is insufficient. * */ public function display_tokens_notice() { // Bail early if notice transient is not set if ( ! get_transient( 'alttextlab_insufficient_credits' ) ) { return; } $api_key = AltTextLab_Utility::get_api_key(); if ( ! empty( $api_key ) ) { $api = new AltTextLab_API( $api_key ); $account = $api->get_account(); if ( is_array( $account ) && isset( $account['credits'] ) && (int) $account['credits'] > 0 ) { delete_transient( 'alttextlab_insufficient_credits' ); return; } } echo '

'; printf( wp_kses( /* translators: %s: URL to manage credits in AltTextLab user account */ __( "[AltTextLab] You don't have enough credits. Manage your account to get more credits.", 'alttextlab' ), array( 'a' => array( 'href' => array(), 'target' => array() ) ) ), esc_url( AltTextLab_Utility::get_credits_url() ) ); echo '

'; } /** * Shows an alert when the account monthly token limit has been reached. * */ public function display_notice_monthly_limit_exceeded() { if ( ! get_transient( 'alttextlab_monthly_limit_exceeded' ) ) { return; } echo '

'; echo esc_html( __( "[AltTextLab] You've reached the monthly limit for this API key. Increase it in your AltTextLab dashboard, or wait until it resets next month.", 'alttextlab' ) ); echo '

'; } /** * Presents an error message suggesting the user retry their action at a later time. * */ public function display_notice_try_later() { // Bail early if notice transient is not set if ( ! get_transient( 'alttextlab_try_later_notice' ) ) { return; } echo '

'; printf( wp_kses( __( '[AltTextLab] Something went wrong. Please try again later.', 'alttextlab' ), array( 'a' => array( 'href' => array(), 'target' => array() ) ) ) ); echo '

'; delete_transient( 'alttextlab_try_later_notice' ); } /** * Shows a warning notification when the provided API credentials are not valid. * */ public function display_notice_api_key_invalid() { // Bail early if notice transient is not set if ( ! get_transient( 'alttextlab_api_key_invalid_notice' ) ) { return; } echo '

'; printf( wp_kses( /* translators: %s: URL to manage credits in AltTextLab user account */ __( "[AltTextLab] Your API key is not valid . Manage your account to get new key.", 'alttextlab' ), array( 'a' => array( 'href' => array(), 'target' => array() ) ) ), esc_url( AltTextLab_Utility::get_credits_url() ) ); echo '

'; delete_transient( 'alttextlab_api_key_invalid_notice' ); } /** * Alerts users when API authentication credentials are missing or not configured. * */ public function display_api_key_missing_notice() { if ( ! isset( $_GET['api_key_missing'] ) ) { return; } $api_key = AltTextLab_Utility::get_api_key(); if ( ! empty( $api_key ) ) { return; } echo '

'; echo wp_kses( __('[AltTextLab] Please add your API key to generate alt text.', 'alttextlab' ), array( 'strong' => array() ) ); echo '

'; } /** * Displays notification after bulk selection processing * */ public function render_bulk_select_notice() { // Retrieve number of images that underwent processing $count = get_transient( 'bulk_generate_alt' ); if ( $count === false ) { return; } // Build user notification text $message = sprintf( "[AltTextLab] Finished generating alt text for %d %s.", $count, _n( 'image', 'images', $count, 'alttextlab' ) ); // Show success message to user echo "

", esc_html($message), "

"; // Remove temporary data after displaying notice delete_transient( 'bulk_generate_alt' ); } /** * Display a success notice to the user after successfully enriching post content. * */ public function display_enrich_post_content_success_notice() { // Check if this is an AJAX call if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) { check_ajax_referer( 'alttextlab_enrich_post_content_transient', 'security' ); $message = get_transient( 'alttextlab_enrich_post_content_success' ); // If transient is set, return the message as JSON response if ( $message ) { delete_transient( 'alttextlab_enrich_post_content_success' ); wp_send_json_success( [ 'message' => $message ] ); } else { wp_send_json_error( [ 'message' => 'No message found' ] ); } } else if ( ! get_current_screen()->is_block_editor() ) { $message = get_transient( 'alttextlab_enrich_post_content_success' ); // Bail early if notice transient is not set if ( ! $message ) { return; } echo '

', esc_html( $message ), '

'; // Delete the transient delete_transient( 'alttextlab_enrich_post_content_success' ); } } }