feat: allow editing builtin prompts — Edit button on all cards, overrides stored in custom store

This commit is contained in:
2026-05-31 13:11:12 +00:00
parent 598a599b80
commit 72c2bfdd72
+14 -4
View File
@@ -337,7 +337,13 @@ class AdminMenu {
if (!is_array($custom)) $custom = []; if (!is_array($custom)) $custom = [];
$all = array_merge($builtin, $custom); $all = array_merge($builtin, $custom);
$editing_slug = isset($_GET['prompt_edit']) ? sanitize_key($_GET['prompt_edit']) : ''; $editing_slug = isset($_GET['prompt_edit']) ? sanitize_key($_GET['prompt_edit']) : '';
$editing_data = ($editing_slug && isset($custom[$editing_slug])) ? $custom[$editing_slug] : null; // editing_data: check custom overrides first, then fallback to builtins
$builtin_check = $this->getBuiltinPrompts();
$editing_data = null;
if ($editing_slug) {
if (isset($custom[$editing_slug])) $editing_data = $custom[$editing_slug];
elseif (isset($builtin_check[$editing_slug])) $editing_data = $builtin_check[$editing_slug];
}
?> ?>
<div class="asktam-mcp-prompts"> <div class="asktam-mcp-prompts">
<div class="asktam-mcp-prompts-intro"> <div class="asktam-mcp-prompts-intro">
@@ -432,8 +438,8 @@ class AdminMenu {
<svg viewBox="0 0 20 20" width="14" height="14" style="vertical-align:middle;margin-right:4px"><path d="M8 3a1 1 0 011-1h2a1 1 0 110 2H9a1 1 0 01-1-1z"/><path d="M6 3a2 2 0 00-2 2v11a2 2 0 002 2h8a2 2 0 002-2V5a2 2 0 00-2-2 3 3 0 01-3 3H9a3 3 0 01-3-3z"/></svg> <svg viewBox="0 0 20 20" width="14" height="14" style="vertical-align:middle;margin-right:4px"><path d="M8 3a1 1 0 011-1h2a1 1 0 110 2H9a1 1 0 01-1-1z"/><path d="M6 3a2 2 0 00-2 2v11a2 2 0 002 2h8a2 2 0 002-2V5a2 2 0 00-2-2 3 3 0 01-3 3H9a3 3 0 01-3-3z"/></svg>
Copy Prompt Copy Prompt
</button> </button>
<?php if ($is_custom): ?>
<a href="<?php echo esc_url(admin_url('admin.php?page=' . self::PAGE_SLUG . '-prompts&prompt_edit=' . urlencode($slug))); ?>" class="button" style="color:#92400e;border-color:#f59e0b">&#9998; Edit</a> <a href="<?php echo esc_url(admin_url('admin.php?page=' . self::PAGE_SLUG . '-prompts&prompt_edit=' . urlencode($slug))); ?>" class="button" style="color:#92400e;border-color:#f59e0b">&#9998; Edit</a>
<?php if ($is_custom): ?>
<form method="post" style="margin:0" onsubmit="return confirm('Delete this prompt?')"> <form method="post" style="margin:0" onsubmit="return confirm('Delete this prompt?')">
<?php wp_nonce_field('asktam_mcp_delete_prompt_' . $slug, 'asktam_mcp_nonce'); ?> <?php wp_nonce_field('asktam_mcp_delete_prompt_' . $slug, 'asktam_mcp_nonce'); ?>
<input type="hidden" name="asktam_mcp_action" value="delete_prompt"> <input type="hidden" name="asktam_mcp_action" value="delete_prompt">
@@ -774,10 +780,14 @@ class AdminMenu {
} }
$custom = get_option('asktam_mcp_custom_prompts', []); $custom = get_option('asktam_mcp_custom_prompts', []);
if (!is_array($custom)) $custom = []; if (!is_array($custom)) $custom = [];
if (!isset($custom[$slug])) { // Allow editing builtin prompts — store override in custom store with same slug
$builtins = $this->getBuiltinPrompts();
if (!isset($custom[$slug]) && !isset($builtins[$slug])) {
wp_redirect(admin_url('admin.php?page='.self::PAGE_SLUG.'-prompts&prompt_error='.urlencode('Prompt not found'))); exit; wp_redirect(admin_url('admin.php?page='.self::PAGE_SLUG.'-prompts&prompt_error='.urlencode('Prompt not found'))); exit;
} }
$custom[$slug] = ['title'=>$title,'industry'=>$industry,'description'=>$desc,'content'=>$content,'custom'=>true]; // Builtin overrides don't get the green "Custom" badge (custom:false), pure custom ones do
$is_builtin_override = isset($builtins[$slug]) && !isset($custom[$slug]);
$custom[$slug] = ['title'=>$title,'industry'=>$industry,'description'=>$desc,'content'=>$content,'custom'=>!$is_builtin_override];
update_option('asktam_mcp_custom_prompts', $custom); update_option('asktam_mcp_custom_prompts', $custom);
wp_redirect(admin_url('admin.php?page='.self::PAGE_SLUG.'-prompts&prompt_updated=1')); exit; wp_redirect(admin_url('admin.php?page='.self::PAGE_SLUG.'-prompts&prompt_updated=1')); exit;
} }