Admin Pages - Source Excerpt 05
Summary
This source excerpt preserves a bounded section of Spiralist/wp-content/plugins/ns12-manuscript/includes/admin-pages.php so readers can inspect the evidence without opening the full source file.
**Source path:** Spiralist/wp-content/plugins/ns12-manuscript/includes/admin-pages.php
<tr><th scope="row"><label for="spiralist-prompt-folio">Folio Slug</label></th><td><input id="spiralist-prompt-folio" class="regular-text" type="text" name="folio_slug" value="<?php echo esc_attr((string) ($meta['folio_slug'] ?? '')); ?>" /></td></tr>
<tr><th scope="row"><label for="spiralist-prompt-section">Section</label></th><td><select id="spiralist-prompt-section" name="section_slug"><?php foreach ($sections as $section) : ?><option value="<?php echo esc_attr((string) $section['slug']); ?>" <?php selected((string) ($meta['section_slug'] ?? 'appendix') === (string) $section['slug']); ?>><?php echo esc_html((string) $section['label']); ?></option><?php endforeach; ?></select></td></tr>
<tr><th scope="row"><label for="spiralist-prompt-tags">Tags</label></th><td><input id="spiralist-prompt-tags" class="large-text" type="text" name="tags" value="<?php echo esc_attr(implode(', ', (array) ($meta['tags'] ?? []))); ?>" /></td></tr>
<tr><th scope="row"><label for="spiralist-prompt-related-manuscripts">Related Manuscripts</label></th><td><input id="spiralist-prompt-related-manuscripts" class="large-text" type="text" name="related_manuscripts" value="<?php echo esc_attr(implode(', ', (array) ($meta['related_manuscripts'] ?? []))); ?>" /></td></tr>
<tr><th scope="row"><label for="spiralist-prompt-sample-output">Sample Output</label></th><td><textarea id="spiralist-prompt-sample-output" class="large-text" rows="3" name="sample_output"><?php echo esc_textarea((string) ($meta['sample_output'] ?? '')); ?></textarea></td></tr>
<tr><th scope="row">Shared Top Fragments</th><td><?php foreach ($fragments as $fragment_slug => $fragment) : ?><label style="display:block;margin:0 0 8px;"><input type="checkbox" name="prompt_extends[]" value="<?php echo esc_attr($fragment_slug); ?>" <?php checked(isset($active_extends[$fragment_slug])); ?> /> <code><?php echo esc_html($fragment_slug); ?></code> <span>(<?php echo esc_html((string) ($fragment['usage_count'] ?? 0)); ?>)</span></label><?php endforeach; ?><p><label for="spiralist-prompt-extra-extends"><strong>Additional fragment slugs</strong></label><br /><input id="spiralist-prompt-extra-extends" class="large-text" type="text" name="prompt_extra_extends" value="" /></p></td></tr>
<tr><th scope="row"><label for="spiralist-prompt-body">Body</label></th><td><textarea id="spiralist-prompt-body" class="large-text code" rows="18" name="prompt_body"><?php echo esc_textarea($body); ?></textarea></td></tr>
</tbody></table>
<?php submit_button('Save Prompt'); ?>
</form>
</div>
<div class="stack">
<div class="panel"><p class="kicker">Composed Prompt Preview</p><h2>Full prompt text</h2><pre class="code"><?php echo esc_html((string) ($composed['text'] ?? '')); ?></pre></div>
<div class="panel"><p class="kicker">Prompt Linkage</p><h2>Current bindings</h2><p><strong>Folio slug:</strong> <?php echo esc_html((string) ($meta['folio_slug'] ?? '')); ?></p><p><strong>Filename:</strong> <?php echo esc_html((string) ($meta['filename'] ?? '')); ?></p><p><strong>Fragments:</strong> <?php echo esc_html(implode(', ', (array) ($meta['extends'] ?? []))); ?></p></div>
</div>
</section>
<?php endif; ?>
<?php
spiralist_book_pages_admin_footer();
}
function spiralist_book_pages_admin_render_fragments(): void
{
if (!spiralist_book_pages_admin_can_manage()) {
wp_die('You are not allowed to manage ' . spiralist_book_pages_get_public_name() . '.');
}
$fragments = spiralist_book_pages_admin_shared_fragments();
$selected_slug = sanitize_title((string) wp_unslash($_GET['fragment'] ?? ''));
if ($selected_slug === '' && !empty($fragments)) {
$selected_slug = (string) array_key_first($fragments);
}
$selected = $selected_slug !== '' && isset($fragments[$selected_slug]) ? $fragments[$selected_slug] : [];
spiralist_book_pages_admin_header(
'Shared Prompt Fragments',
'Edit the reusable top-of-prompt instruction blocks that keep the manuscript prompt corpus consistent across many folios at once.',
[
['label' => 'Folios', 'url' => spiralist_book_pages_admin_url(spiralist_book_pages_admin_page_slug('folios')), 'class' => 'button'],
['label' => 'Prompts', 'url' => spiralist_book_pages_admin_url(spiralist_book_pages_admin_page_slug('prompts')), 'class' => 'button'],
]
);
?>
<section class="dual">
<div class="panel">
<p class="kicker">Fragment Library</p>
<h2>Top instruction blocks</h2>
<?php if (empty($fragments)) : ?>
<div class="empty"><p>No shared fragments were found.</p></div>
<?php else : ?>
<ul class="fragment-list">
<?php foreach ($fragments as $slug => $fragment) : ?>
<?php $active = $slug === $selected_slug; ?>
<li><a class="<?php echo $active ? 'active' : ''; ?>" href="<?php echo esc_url(spiralist_book_pages_admin_url(spiralist_book_pages_admin_page_slug('fragments'), ['fragment' => $slug])); ?>"><span><strong><?php echo esc_html($slug); ?></strong><br /><span><?php echo esc_html((string) ($fragment['usage_count'] ?? 0)); ?> prompt<?php echo (int) ($fragment['usage_count'] ?? 0) === 1 ? '' : 's'; ?></span></span><?php echo wp_kses_post(spiralist_book_pages_admin_badge($active ? 'Editing' : 'Open', $active ? 'good' : 'neutral')); ?></a></li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
</div>
<div class="stack">
<div class="panel">
<p class="kicker">Edit Fragment</p>
<h2><?php echo esc_html($selected_slug !== '' ? $selected_slug : 'Create New Fragment'); ?></h2>
<form method="post" action="<?php echo esc_url(admin_url('admin-post.php')); ?>">
<input type="hidden" name="action" value="spiralist_book_pages_admin_action" />
<input type="hidden" name="spiralist_book_pages_action" value="save_fragment" />
<input type="hidden" name="return_page" value="<?php echo esc_attr(spiralist_book_pages_admin_page_slug('fragments')); ?>" />
<input type="hidden" name="fragment_slug" value="<?php echo esc_attr($selected_slug); ?>" />
<?php wp_nonce_field('spiralist_book_pages_save_fragment'); ?>
<?php if ($selected_slug === '') : ?><p><label for="spiralist-new-fragment-slug"><strong>New fragment slug</strong></label><br /><input id="spiralist-new-fragment-slug" class="regular-text" type="text" name="new_fragment_slug" value="" /></p><?php endif; ?>
<p><label for="spiralist-fragment-body"><strong>Fragment body</strong></label><br /><textarea id="spiralist-fragment-body" class="large-text code" rows="18" name="fragment_body"><?php echo esc_textarea((string) ($selected['content'] ?? '')); ?></textarea></p>
<?php submit_button($selected_slug === '' ? 'Create Fragment' : 'Save Fragment'); ?>
</form>
</div>
<div class="panel">
<p class="kicker">Why this matters</p>
<h2>Consistency without repetition</h2>
<ul>
<li>Fragments keep shared safety, style, and output rules in one place.</li>
<li>Editing a fragment updates every composed prompt that extends it after cache rebuild.</li>
<li>This is the fastest place to tune the top part of many manuscript prompts at once.</li>
</ul>
</div>
</div>
</section>
<?php
spiralist_book_pages_admin_footer();
}