'sanitize_text_field'));
register_setting('aitoa_settings', 'aitoa_default_try_on_type', array('sanitize_callback' => 'sanitize_text_field'));
add_settings_section(
'aitoa_main_section',
__('API Settings', 'ai-try-on-assistant'),
array($this, 'section_callback'),
'aitoa_settings'
);
add_settings_field(
'aitoa_gemini_api_key',
__('Gemini API Key', 'ai-try-on-assistant'),
array($this, 'api_key_field'),
'aitoa_settings',
'aitoa_main_section'
);
add_settings_field(
'aitoa_default_try_on_type',
__('Default Try-On Type', 'ai-try-on-assistant'),
array($this, 'default_type_field'),
'aitoa_settings',
'aitoa_main_section'
);
}
public function section_callback()
{
echo '
';
echo '
' . esc_html__('Getting Started', 'ai-try-on-assistant') . ' ';
echo '
' . esc_html__('Configure your Google Gemini API key and default settings to enable AI-powered virtual try-on functionality.', 'ai-try-on-assistant') . '
';
echo '
' . esc_html__('API Key:', 'ai-try-on-assistant') . ' ' . sprintf(
/* translators: %s: Link to Google AI Studio */
esc_html__('Get your free API key from %s', 'ai-try-on-assistant'),
'Google AI Studio '
) . '
';
echo '
' . esc_html__('Usage:', 'ai-try-on-assistant') . ' ' . esc_html__('Enable try-on for individual products in the product edit page, then select which images can be tried on.', 'ai-try-on-assistant') . '
';
echo '
';
echo '';
echo '
' . esc_html__('External Service Notice', 'ai-try-on-assistant') . ' ';
echo '
' . esc_html__('This plugin uses Google Gemini AI API to process virtual try-on requests. When customers use the try-on feature:', 'ai-try-on-assistant') . '
';
echo '
';
echo '' . esc_html__('User photos and product images are sent to Google\'s servers for AI processing', 'ai-try-on-assistant') . ' ';
echo '' . esc_html__('Data is only transmitted when customers actively use the try-on feature', 'ai-try-on-assistant') . ' ';
echo '' . esc_html__('Google\'s Privacy Policy and Terms of Service apply to this data processing', 'ai-try-on-assistant') . ' ';
echo ' ';
echo '
' . sprintf(
/* translators: %1$s: Terms link, %2$s: Privacy link */
esc_html__('Review Google\'s %1$s and %2$s for more information.', 'ai-try-on-assistant'),
'' . esc_html__('Terms of Service', 'ai-try-on-assistant') . ' ',
'' . esc_html__('Privacy Policy', 'ai-try-on-assistant') . ' '
) . '
';
echo '
';
}
public function api_key_field()
{
$value = get_option('aitoa_gemini_api_key');
echo ' ';
echo '' . esc_html__('Enter your Google Gemini API key', 'ai-try-on-assistant') . '
';
}
public function default_type_field()
{
$value = get_option('aitoa_default_try_on_type', 'clothes');
$types = array(
'clothes' => __('Clothes', 'ai-try-on-assistant'),
'hair' => __('Hair Style', 'ai-try-on-assistant'),
'makeup' => __('Makeup', 'ai-try-on-assistant')
);
echo '';
foreach ($types as $key => $label) {
echo '' . esc_html($label) . ' ';
}
echo ' ';
echo '' . esc_html__('Select the default try-on type for new products', 'ai-try-on-assistant') . '
';
}
public function settings_page()
{
?>
ID, '_aitoa_enable_try_on', true);
$try_on_type = get_post_meta($post->ID, '_aitoa_try_on_type', true);
$tryable_images = get_post_meta($post->ID, '_aitoa_tryable_images', true);
if (empty($try_on_type)) {
$try_on_type = get_option('aitoa_default_try_on_type', 'clothes');
}
if (!is_array($tryable_images)) {
$tryable_images = array();
}
?>
' . esc_html__('Save product to load images', 'ai-try-on-assistant') . '';
return;
}
$attachment_ids = array();
// Featured image
if ($product->get_image_id()) {
$attachment_ids[] = $product->get_image_id();
}
// Gallery images
$gallery_ids = $product->get_gallery_image_ids();
if (!empty($gallery_ids)) {
$attachment_ids = array_merge($attachment_ids, $gallery_ids);
}
if (empty($attachment_ids)) {
echo '' . esc_html__('No product images found', 'ai-try-on-assistant') . '
';
return;
}
foreach ($attachment_ids as $attachment_id) {
$image_url = wp_get_attachment_image_url($attachment_id, 'thumbnail');
$image_alt = get_post_meta($attachment_id, '_wp_attachment_image_alt', true);
$is_checked = in_array($attachment_id, $selected_images);
echo '';
echo '
';
echo '
';
echo '
' . esc_html($image_alt ?: __('Product Image', 'ai-try-on-assistant')) . ' ';
echo '
';
}
}
public function save_product_meta_box($post_id)
{
if (!isset($_POST['aitoa_product_meta_nonce']) || !wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['aitoa_product_meta_nonce'])), 'aitoa_save_product_meta')) {
return;
}
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
return;
}
if (!current_user_can('edit_post', $post_id)) {
return;
}
// Save enable try-on
$enable_try_on = isset($_POST['aitoa_enable_try_on']) ? 'yes' : 'no';
update_post_meta($post_id, '_aitoa_enable_try_on', $enable_try_on);
// Save try-on type
if (isset($_POST['aitoa_try_on_type'])) {
update_post_meta($post_id, '_aitoa_try_on_type', sanitize_text_field(wp_unslash($_POST['aitoa_try_on_type'])));
}
// Save tryable images
$tryable_images = array();
if (isset($_POST['aitoa_tryable_images']) && is_array($_POST['aitoa_tryable_images'])) {
$tryable_images = array_map('intval', $_POST['aitoa_tryable_images']);
}
update_post_meta($post_id, '_aitoa_tryable_images', $tryable_images);
}
}