'attachment',
'post_mime_type' => 'image',
'post_status' => 'inherit',
'posts_per_page' => -1,
'orderby' => 'ID',
'order' => 'DESC',
);
$args = wp_parse_args($args_override, $default_args);
return get_posts($args);
}
public function alt_description_page() {
if (!current_user_can('manage_options')) {
wp_die(__('You do not have sufficient permissions to access this page.', 'ada-compliance-guardian'));
}
?>
';
printf(
wp_kses_post(__('The Plan API Key is not configured. This is required to track usage. Please visit the Initial Setup page to enter your key.', 'ada-compliance-guardian')),
esc_url($setup_page_url)
);
echo '
';
return;
}
$api_key = get_option(self::OPTION_API_KEY, '');
if (empty($api_key)) {
echo '';
printf(
wp_kses_post(__('The Image Alt Text Generation API Key is not configured. This plugin requires a key to function. Please visit the Initial Setup page to enter your API key.', 'ada-compliance-guardian')),
esc_url($setup_page_url)
);
echo '
';
return;
}
?>
'attachment', 'post_mime_type' => 'image', 'post_status' => 'inherit', 'posts_per_page' => -1,
'meta_query' => array(
'relation' => 'OR',
array('key' => '_wp_attachment_image_alt', 'compare' => 'NOT EXISTS'),
array('key' => '_wp_attachment_image_alt', 'value' => '', 'compare' => '=')
)
);
$missing_alt_images_query = new WP_Query($args_missing_count);
$missing_alt_images_count = $missing_alt_images_query->post_count;
?>
get_all_media_images();
if (!empty($all_images)) {
echo '
';
} else {
echo '
' . esc_html__('No images found in the media library.', 'ada-compliance-guardian') . '
';
}
?>
visit the Initial Setup page to enter your API key.', 'ada-compliance-guardian')),
esc_url(admin_url('admin.php?page=ada-compliance-guardian-setup'))
);
if (empty($api_key)) {
return array('error' => __('Image Alt Text Generation API Key is not configured. ', 'ada-compliance-guardian') . $setup_page_url_html, 'error_code' => 400);
}
if (strpos($api_key, 'AIza') !== 0) {
return array('error' => __('The configured Image Alt Text Generation API Key appears to be invalid. ', 'ada-compliance-guardian') . $setup_page_url_html, 'error_code' => 400);
}
$gemini_api_url = 'https://generativelanguage.googleapis.com/v1beta/models/' . self::GEMINI_MODEL . ':generateContent?key=' . $api_key;
$request_body = array(
'contents' => array(array('parts' => array(array('text' => $prompt_text), array('inline_data' => array('mime_type' => $image_mime_type, 'data' => $base64_image_data))))),
'generationConfig' => array('temperature' => 0.45, 'topK' => 32, 'topP' => 1, 'maxOutputTokens' => 150),
'safetySettings' => array(
array('category' => 'HARM_CATEGORY_HARASSMENT', 'threshold' => 'BLOCK_MEDIUM_AND_ABOVE'),
array('category' => 'HARM_CATEGORY_HATE_SPEECH', 'threshold' => 'BLOCK_MEDIUM_AND_ABOVE'),
array('category' => 'HARM_CATEGORY_SEXUALLY_EXPLICIT', 'threshold' => 'BLOCK_MEDIUM_AND_ABOVE'),
array('category' => 'HARM_CATEGORY_DANGEROUS_CONTENT', 'threshold' => 'BLOCK_MEDIUM_AND_ABOVE'),
)
);
$api_response = wp_remote_post($gemini_api_url, array(
'method' => 'POST', 'headers' => array('Content-Type' => 'application/json'),
'body' => wp_json_encode($request_body), 'timeout' => 45,
));
if (is_wp_error($api_response)) {
return array('error' => __('Image Alt Text Generation API request failed: ', 'ada-compliance-guardian') . $api_response->get_error_message(), 'error_code' => 500);
}
$response_body = wp_remote_retrieve_body($api_response);
$response_code = wp_remote_retrieve_response_code($api_response);
$decoded_response = json_decode($response_body, true);
if ($response_code !== 200 || !$decoded_response) {
$api_error_detail = isset($decoded_response['error']['message']) ? $decoded_response['error']['message'] : substr($response_body, 0, 500);
if ($response_code === 400 && strpos($api_error_detail, 'API key not valid') !== false) {
return array('error' => __('The Image Alt Text Generation API Key is not valid. ', 'ada-compliance-guardian') . $setup_page_url_html . '