fix: remove duplicate sanitize_image_model method in admin-page
append-tail approach in prior fixup commit produced a second partial copy of the sanitize_image_model() method (lines 342-350 truncated + lines 351-362 complete). Replaced entire file with 353-line canonical version. Agent-Session: phase2-admin-m1-engineer
This commit is contained in:
@@ -18,11 +18,11 @@ declare(strict_types=1);
|
|||||||
*/
|
*/
|
||||||
class PRAutoBlogger_Admin_Page {
|
class PRAutoBlogger_Admin_Page {
|
||||||
|
|
||||||
private const PAGE_SLUG = 'prautoblogger-settings';
|
private const PAGE_SLUG = 'prautoblogger-settings';
|
||||||
private const OPTION_GROUP = 'prautoblogger_settings_group';
|
private const OPTION_GROUP = 'prautoblogger_settings_group';
|
||||||
|
|
||||||
/** Register the top-level PRAutoBlogger menu item. */
|
/** Register the top-level PRAutoBlogger menu item. */
|
||||||
public function on_register_menu(): void {
|
public function on_register_menu(): void {
|
||||||
add_menu_page(
|
add_menu_page(
|
||||||
__( 'PRAutoBlogger', 'prautoblogger' ),
|
__( 'PRAutoBlogger', 'prautoblogger' ),
|
||||||
__( 'PRAutoBlogger', 'prautoblogger' ),
|
__( 'PRAutoBlogger', 'prautoblogger' ),
|
||||||
@@ -32,10 +32,10 @@ public function on_register_menu(): void {
|
|||||||
'dashicons-edit-page',
|
'dashicons-edit-page',
|
||||||
30
|
30
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Register all settings with the WordPress Settings API. */
|
/** Register all settings with the WordPress Settings API. */
|
||||||
public function on_register_settings(): void {
|
public function on_register_settings(): void {
|
||||||
$sections = PRAutoBlogger_Settings_Fields::get_sections();
|
$sections = PRAutoBlogger_Settings_Fields::get_sections();
|
||||||
$fields = PRAutoBlogger_Settings_Fields::get_fields();
|
$fields = PRAutoBlogger_Settings_Fields::get_fields();
|
||||||
|
|
||||||
@@ -56,10 +56,10 @@ public function on_register_settings(): void {
|
|||||||
);
|
);
|
||||||
add_settings_field( $field['id'], $field['label'], array( $this, 'render_field' ), self::PAGE_SLUG, $section, $field );
|
add_settings_field( $field['id'], $field['label'], array( $this, 'render_field' ), self::PAGE_SLUG, $section, $field );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Enqueue admin CSS and JS on all PRAutoBlogger admin pages. */
|
/** Enqueue admin CSS and JS on all PRAutoBlogger admin pages. */
|
||||||
public function on_enqueue_assets( string $hook_suffix ): void {
|
public function on_enqueue_assets( string $hook_suffix ): void {
|
||||||
$pages = array(
|
$pages = array(
|
||||||
'toplevel_page_' . self::PAGE_SLUG,
|
'toplevel_page_' . self::PAGE_SLUG,
|
||||||
'prautoblogger_page_prautoblogger-board',
|
'prautoblogger_page_prautoblogger-board',
|
||||||
@@ -105,24 +105,24 @@ public function on_enqueue_assets( string $hook_suffix ): void {
|
|||||||
if ( 'prautoblogger_page_prautoblogger-ideas' === $hook_suffix ) {
|
if ( 'prautoblogger_page_prautoblogger-ideas' === $hook_suffix ) {
|
||||||
wp_enqueue_script( 'prautoblogger-ideas-browser', PRAUTOBLOGGER_PLUGIN_URL . 'assets/js/ideas-browser.js', array( 'jquery', 'prautoblogger-admin' ), PRAUTOBLOGGER_VERSION, true );
|
wp_enqueue_script( 'prautoblogger-ideas-browser', PRAUTOBLOGGER_PLUGIN_URL . 'assets/js/ideas-browser.js', array( 'jquery', 'prautoblogger-admin' ), PRAUTOBLOGGER_VERSION, true );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Render the settings page (delegates to template). */
|
/** Render the settings page (delegates to template). */
|
||||||
public function render_page(): void {
|
public function render_page(): void {
|
||||||
if ( ! current_user_can( 'manage_options' ) ) {
|
if ( ! current_user_can( 'manage_options' ) ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$sections = PRAutoBlogger_Settings_Fields::get_sections();
|
$sections = PRAutoBlogger_Settings_Fields::get_sections();
|
||||||
$fields = PRAutoBlogger_Settings_Fields::get_fields();
|
$fields = PRAutoBlogger_Settings_Fields::get_fields();
|
||||||
include PRAUTOBLOGGER_PLUGIN_DIR . 'templates/admin/settings-page.php';
|
include PRAUTOBLOGGER_PLUGIN_DIR . 'templates/admin/settings-page.php';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Render a single settings field based on its type.
|
* Render a single settings field based on its type.
|
||||||
*
|
*
|
||||||
* @param array<string, mixed> $args Field definition.
|
* @param array<string, mixed> $args Field definition.
|
||||||
*/
|
*/
|
||||||
public function render_field( array $args ): void {
|
public function render_field( array $args ): void {
|
||||||
$id = esc_attr( $args['id'] );
|
$id = esc_attr( $args['id'] );
|
||||||
$type = $args['type'] ?? 'text';
|
$type = $args['type'] ?? 'text';
|
||||||
$default = $args['default'] ?? '';
|
$default = $args['default'] ?? '';
|
||||||
@@ -243,16 +243,16 @@ public function render_field( array $args ): void {
|
|||||||
if ( '' !== $desc ) {
|
if ( '' !== $desc ) {
|
||||||
printf( '<p class="ab-field-desc">%s</p>', esc_html( $desc ) );
|
printf( '<p class="ab-field-desc">%s</p>', esc_html( $desc ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delegate source status rendering to the dedicated field class.
|
* Delegate source status rendering to the dedicated field class.
|
||||||
*
|
*
|
||||||
* @see admin/fields/class-source-status-field.php
|
* @see admin/fields/class-source-status-field.php
|
||||||
*/
|
*/
|
||||||
private function render_source_status_field(): void {
|
private function render_source_status_field(): void {
|
||||||
PRAutoBlogger_Source_Status_Field::render();
|
PRAutoBlogger_Source_Status_Field::render();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delegate model picker rendering to the dedicated field class.
|
* Delegate model picker rendering to the dedicated field class.
|
||||||
@@ -263,9 +263,9 @@ private function render_source_status_field(): void {
|
|||||||
*
|
*
|
||||||
* @see admin/fields/class-openrouter-model-field.php
|
* @see admin/fields/class-openrouter-model-field.php
|
||||||
*/
|
*/
|
||||||
private function render_model_select_field( string $id, string $value, array $args ): void {
|
private function render_model_select_field( string $id, string $value, array $args ): void {
|
||||||
PRAutoBlogger_OpenRouter_Model_Field::render( $id, $value, $args );
|
PRAutoBlogger_OpenRouter_Model_Field::render( $id, $value, $args );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sanitize a settings field value.
|
* Sanitize a settings field value.
|
||||||
@@ -273,7 +273,7 @@ private function render_model_select_field( string $id, string $value, array $ar
|
|||||||
* @param mixed $value The submitted value.
|
* @param mixed $value The submitted value.
|
||||||
* @return mixed Sanitized value.
|
* @return mixed Sanitized value.
|
||||||
*/
|
*/
|
||||||
public function sanitize_field( $value ) {
|
public function sanitize_field( $value ) {
|
||||||
$option_name = '';
|
$option_name = '';
|
||||||
$filter = current_filter();
|
$filter = current_filter();
|
||||||
if ( 0 === strpos( $filter, 'sanitize_option_' ) ) {
|
if ( 0 === strpos( $filter, 'sanitize_option_' ) ) {
|
||||||
@@ -337,17 +337,8 @@ public function sanitize_field( $value ) {
|
|||||||
return PRAutoBlogger_Image_Template_Filler::sanitize_for_save( (string) $value );
|
return PRAutoBlogger_Image_Template_Filler::sanitize_for_save( (string) $value );
|
||||||
}
|
}
|
||||||
return sanitize_text_field( (string) $value );
|
return sanitize_text_field( (string) $value );
|
||||||
}
|
|
||||||
|
|
||||||
/** Validate model id against the registry and persist the derived provider. */
|
|
||||||
private function sanitize_image_model( string $value ): string {
|
|
||||||
$candidate = sanitize_text_field( $value );
|
|
||||||
$provider = PRAutoBlogger_Image_Model_Registry::provider_for( $candidate );
|
|
||||||
if ( '' !== $provider ) {
|
|
||||||
update_option( 'prautoblogger_image_provider', $provider );
|
|
||||||
return $candidate;
|
|
||||||
}
|
}
|
||||||
add_settings_error( 'prautoblogger_image_model', 'prautoblogger_image_model_unknown', sprintf( esc_html__( 'Image model "%s" is not in the registry. Keeping the previous selection.', 'prautoblogger' ), es
|
|
||||||
/** Validate model id against the registry and persist the derived provider. */
|
/** Validate model id against the registry and persist the derived provider. */
|
||||||
private function sanitize_image_model( string $value ): string {
|
private function sanitize_image_model( string $value ): string {
|
||||||
$candidate = sanitize_text_field( $value );
|
$candidate = sanitize_text_field( $value );
|
||||||
|
|||||||
Reference in New Issue
Block a user