' . esc_html__('Default template updated.', 'aigude-tools') . '

'; } } // Deletion if ( isset($_GET['action'], $_GET['tpl_index']) && $_GET['action']==='delete' && check_admin_referer('aigude_tpl_action','aigude_tpl_nonce') ) { $idx = intval($_GET['tpl_index']); if ( isset($templates[$idx]) ) { $deleted_id = $templates[$idx]['id'] ?? ''; unset($templates[$idx]); $templates = array_values($templates); update_option('aigude_prompt_templates', $templates); // If the deleted one was default, clear default if ($deleted_id && get_option('aigude_prompt_default_id') === $deleted_id) { delete_option('aigude_prompt_default_id'); } echo '

' . esc_html__('Template deleted.', 'aigude-tools') . '

'; } } // Load for editing $edit_index = null; $edit_title = ''; $edit_prompt = ''; if ( isset($_GET['action'], $_GET['tpl_index']) && $_GET['action']==='edit' && check_admin_referer('aigude_tpl_action','aigude_tpl_nonce') ) { $idx = intval($_GET['tpl_index']); if ( isset($templates[$idx]) ) { $edit_index = $idx; $edit_title = $templates[$idx]['title']; $edit_prompt = $templates[$idx]['prompt']; } } // Save (new or update) if (isset($_POST['ai_tpl_submit']) && check_admin_referer('aigude_tpl_action','aigude_tpl_nonce')) { $title = sanitize_text_field(wp_unslash($_POST['ai_tpl_title'] ?? '')); $prompt = sanitize_textarea_field(wp_unslash($_POST['ai_tpl_prompt'] ?? '')); $src_lang_placeholders = sanitize_text_field(wp_unslash($_POST['ai_tpl_src_lang'] ?? 'auto')); $prompt_lang = sanitize_text_field(wp_unslash($_POST['ai_tpl_prompt_lang'] ?? 'auto')); // Keep ID if editing; otherwise make one $tpl_id = ''; if (!empty($_POST['ai_tpl_id'])) { $tpl_id = sanitize_text_field(wp_unslash($_POST['ai_tpl_id'])); } else { $tpl_id = function_exists('wp_generate_uuid4') ? wp_generate_uuid4() : ('tpl_' . uniqid('', true)); } $data = [ 'id' => $tpl_id, 'title' => $title, 'prompt' => $prompt, 'src_lang' => $src_lang_placeholders, 'prompt_lang' => $prompt_lang, ]; $make_default = !empty($_POST['ai_tpl_is_default']); if ( $title && $prompt ) { if ( isset($_POST['ai_tpl_index']) && $_POST['ai_tpl_index'] !== '' ) { $idx = (int) $_POST['ai_tpl_index']; $templates[$idx] = $data; printf( '

%s

', esc_html__( 'Template updated.', 'aigude-tools' ) ); } else { $templates[] = $data; printf( '

%s

', esc_html__( 'Template saved.', 'aigude-tools' ) ); } update_option('aigude_prompt_templates', $templates); // Track recents for prompt and placeholder language selections if (class_exists('AIGUDE_Tools_Plugin')) { AIGUDE_Tools_Plugin::push_recent_lang('prompt', $prompt_lang); AIGUDE_Tools_Plugin::push_recent_lang('placeholder', $src_lang_placeholders); } $edit_index = null; $edit_title = ''; $edit_prompt = ''; } if ($make_default) { update_option('aigude_prompt_default_id', $tpl_id); $default_id = $tpl_id; } } // View ?>

$tpl) : $is_default = !empty($tpl['id']) && $tpl['id'] === $default_id; $base = menu_page_url('aigude-tools-templates', false); $edit_url = wp_nonce_url(add_query_arg(['action'=>'edit','tpl_index'=>$i], $base), 'aigude_tpl_action', 'aigude_tpl_nonce'); $del_url = wp_nonce_url(add_query_arg(['action'=>'delete','tpl_index'=>$i], $base), 'aigude_tpl_action', 'aigude_tpl_nonce'); $def_url = wp_nonce_url(add_query_arg(['action'=>'set_default','tpl_index'=>$i], $base), 'aigude_tpl_action', 'aigude_tpl_nonce'); ?>
|

%filename%, %filename_no_ext%, %title%, %current-alt%, %caption%, %description%, %mime%, %width%, %height%.




' . esc_html( sprintf( $example_tpl, '%filename_no_ext|raw%', '%width%', '%height%' ) ) . ''; ?> →