Read-only assembled-instructions preview (last-run rendered prompt) with Template-vs-Preview guardrail; per-prompt version history + LCS diff. Stage-list-driven. QA APPROVE df92ed3; CI green. Agent-Session: pipeline-settings-m3-merge
132 lines
5.6 KiB
PHP
132 lines
5.6 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
/**
|
|
* phpcs:ignore WordPress.Files.FileName.InvalidClassFileName -- class naming convention differs from WordPress standard
|
|
*
|
|
* Registers the Pipeline Settings wp-admin submenu page and its assets.
|
|
*
|
|
* What: Adds a "Pipeline" submenu under the PRAutoBlogger parent menu so
|
|
* operators can configure per-step model, system instructions, agent
|
|
* prompts, and parameters for every LLM stage in one place. This
|
|
* page is ADDITIVE in M1 -- the existing Settings sections remain
|
|
* unchanged and both surfaces edit the same wp_options / prompts
|
|
* table. Decomposition of redundant tabs is M2.
|
|
* M3 localizes preview / history / diff nonces so pipeline-settings.js
|
|
* can make authenticated AJAX requests for the assembled-instructions
|
|
* preview and per-prompt version history/diff.
|
|
* Who calls it: PRAutoBlogger::register_admin_hooks() via add_action
|
|
* ('admin_menu', ..., 13) and ('admin_enqueue_scripts', ...).
|
|
* Dependencies: PRAutoBlogger_Pipeline_Settings_Save_Handler (save),
|
|
* PRAutoBlogger_Pipeline_Settings_Renderer (render).
|
|
*
|
|
* @see admin/class-pipeline-settings-renderer.php -- Step rail + panel HTML.
|
|
* @see admin/class-pipeline-settings-save-handler.php -- nonce + save logic.
|
|
* @see admin/class-admin-page.php -- Parent menu registration (priority 10).
|
|
* @see ajax/class-pipeline-preview-handler.php -- Preview AJAX (M3).
|
|
* @see ajax/class-pipeline-history-handler.php -- History/diff AJAX (M3).
|
|
* @see ARCHITECTURE.md -- Admin pages table.
|
|
* @see INFORMATION-ARCHITECTURE.md -- Admin page slug registry.
|
|
*/
|
|
class PRAutoBlogger_Pipeline_Settings_Page {
|
|
|
|
/** wp-admin page slug. */
|
|
public const PAGE_SLUG = 'prautoblogger-pipeline';
|
|
|
|
/** Nonce action for saving prompt edits on this page. */
|
|
public const NONCE_ACTION = 'prautoblogger_pipeline_save';
|
|
|
|
/** Nonce field name posted with the save form. */
|
|
public const NONCE_FIELD = 'prautoblogger_pipeline_nonce';
|
|
|
|
/**
|
|
* Register the Pipeline submenu page under the PRAutoBlogger parent menu.
|
|
*
|
|
* Priority 13 -- after board (11), dossier (12). The parent slug must be
|
|
* registered at priority 10 by PRAutoBlogger_Admin_Page::on_register_menu()
|
|
* before any submenu can be attached.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function on_register_menu(): void {
|
|
add_submenu_page(
|
|
'prautoblogger-settings',
|
|
__( 'Pipeline Settings', 'prautoblogger' ),
|
|
__( 'Pipeline', 'prautoblogger' ),
|
|
'manage_options',
|
|
self::PAGE_SLUG,
|
|
array( $this, 'render_page' )
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Enqueue CSS / JS required by the Pipeline Settings page.
|
|
*
|
|
* M3 adds localized data for the assembled-instructions preview toggle
|
|
* and the version history / diff panel (AJAX actions + nonces).
|
|
*
|
|
* @param string $hook_suffix Current admin page hook suffix.
|
|
* @return void
|
|
*/
|
|
public function on_enqueue_assets( string $hook_suffix ): void {
|
|
if ( 'prautoblogger_page_' . self::PAGE_SLUG !== $hook_suffix ) {
|
|
return;
|
|
}
|
|
|
|
wp_enqueue_style( 'prautoblogger-admin', PRAUTOBLOGGER_PLUGIN_URL . 'assets/css/admin.css', array(), PRAUTOBLOGGER_VERSION );
|
|
wp_enqueue_style( 'prautoblogger-model-picker', PRAUTOBLOGGER_PLUGIN_URL . 'assets/css/model-picker.css', array( 'prautoblogger-admin' ), PRAUTOBLOGGER_VERSION );
|
|
wp_enqueue_style( 'prautoblogger-pipeline', PRAUTOBLOGGER_PLUGIN_URL . 'assets/css/pipeline-settings.css', array( 'prautoblogger-admin' ), PRAUTOBLOGGER_VERSION );
|
|
|
|
wp_enqueue_script( 'prautoblogger-admin', PRAUTOBLOGGER_PLUGIN_URL . 'assets/js/admin.js', array( 'jquery' ), PRAUTOBLOGGER_VERSION, true );
|
|
wp_enqueue_script( 'prautoblogger-model-picker', PRAUTOBLOGGER_PLUGIN_URL . 'assets/js/model-picker.js', array( 'jquery', 'prautoblogger-admin' ), PRAUTOBLOGGER_VERSION, true );
|
|
wp_enqueue_script( 'prautoblogger-pipeline', PRAUTOBLOGGER_PLUGIN_URL . 'assets/js/pipeline-settings.js', array( 'jquery', 'prautoblogger-admin' ), PRAUTOBLOGGER_VERSION, true );
|
|
|
|
wp_localize_script(
|
|
'prautoblogger-admin',
|
|
'prautobloggerAdmin',
|
|
array(
|
|
'ajaxUrl' => admin_url( 'admin-ajax.php' ),
|
|
'adminUrl' => admin_url(),
|
|
'siteUrl' => home_url( '/' ),
|
|
'modelsNonce' => wp_create_nonce( 'prautoblogger_get_models' ),
|
|
'imageModels' => PRAutoBlogger_Settings_Fields_Extended::get_image_models(),
|
|
)
|
|
);
|
|
|
|
// M3: localize preview + history + diff nonces for pipeline-settings.js.
|
|
wp_localize_script(
|
|
'prautoblogger-pipeline',
|
|
'prabPipeline',
|
|
array(
|
|
'ajaxUrl' => admin_url( 'admin-ajax.php' ),
|
|
'previewAction' => PRAutoBlogger_Pipeline_Preview_Handler::ACTION,
|
|
'previewNonce' => wp_create_nonce( PRAutoBlogger_Pipeline_Preview_Handler::ACTION ),
|
|
'historyAction' => PRAutoBlogger_Pipeline_History_Handler::ACTION_HISTORY,
|
|
'historyNonce' => wp_create_nonce( PRAutoBlogger_Pipeline_History_Handler::ACTION_HISTORY ),
|
|
'diffAction' => PRAutoBlogger_Pipeline_History_Handler::ACTION_DIFF,
|
|
'diffNonce' => wp_create_nonce( PRAutoBlogger_Pipeline_History_Handler::ACTION_DIFF ),
|
|
)
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Render the Pipeline Settings page.
|
|
*
|
|
* Capability check first; then delegate to the save handler (processes
|
|
* POST before output starts) and the renderer (assembles view data and
|
|
* includes the template).
|
|
*
|
|
* @return void
|
|
*/
|
|
public function render_page(): void {
|
|
if ( ! current_user_can( 'manage_options' ) ) {
|
|
wp_die( esc_html__( 'You do not have permission to access this page.', 'prautoblogger' ) );
|
|
}
|
|
|
|
$save_result = PRAutoBlogger_Pipeline_Settings_Save_Handler::maybe_process_save();
|
|
|
|
$renderer = new PRAutoBlogger_Pipeline_Settings_Renderer();
|
|
$renderer->render( $save_result );
|
|
}
|
|
}
|