self::TAB_SLUG, 'label' => __( 'Abilities', 'acrossai-abilities-manager' ), 'priority' => 10, ); return $tabs; } /** * Registers settings sections and fields via the WordPress Settings API. * * Hooked to admin_init. Sections AND `option_group` both target the * per-tab page slug derived from the host package's * `SettingsPage::get_settings_renderer()->tab_page_slug()` helper * (acrossai-co/main-menu v0.0.14+). Each tab having its own * `option_group` is what prevents the cross-tab option-clobber bug that * shared-`acrossai-settings` had in 0.0.12 (saving one tab silently * wiped other tabs' options). * * Returns silently if the main-menu package has not booted this request * (defensive guard — the bootstrap in acrossai-abilities-manager.php on * plugins_loaded priority 0 makes this practically unreachable, but a * null renderer here just means "skip Settings API registration this * request" rather than fataling). * * @since 0.1.0 * @return void */ public function register_settings(): void { $renderer = \AcrossAI_Main_Menu\SettingsPage::get_settings_renderer(); if ( ! $renderer ) { return; } $page_slug = $renderer->tab_page_slug( self::TAB_SLUG ); // Both persisted options are registered here so the option_group whitelist // is complete before either section renders (option_group is one-shot per // admin_init request). register_setting( $page_slug, 'acrossai_abilities_per_page', array( 'sanitize_callback' => array( $this, 'sanitize_per_page' ), 'default' => 20, ) ); register_setting( $page_slug, 'acrossai_abilities_uninstall_delete_data', array( 'sanitize_callback' => array( $this, 'sanitize_uninstall_flag' ), 'default' => 0, ) ); // Section 1 of 3 (rendered first): Display settings. // // The Uninstall Settings section is registered separately by // register_uninstall_settings() at admin_init priority 20 so it always // renders LAST — after Core_Settings_Menu's Upload Media Abilities // section (Feature 046). Sections render in the order they were added. add_settings_section( 'acrossai_display_settings_section', __( 'Display Settings', 'acrossai-abilities-manager' ), '__return_false', $page_slug ); add_settings_field( 'acrossai_abilities_per_page', __( 'Abilities per page', 'acrossai-abilities-manager' ), array( $this, 'render_per_page_field' ), $page_slug, 'acrossai_display_settings_section' ); } /** * Registers the "Uninstall Settings" section at admin_init priority 20. * * Wired separately so it lands AFTER every other section registered at * default priority 10 (Display Settings above, plus * `Core_Settings_Menu`'s Upload Media Abilities section — Feature 046). * Sections render in the order they were added, so a later hook priority * pushes this section to the bottom of the Abilities tab. * * @since 0.1.0 * @return void */ public function register_uninstall_settings(): void { $renderer = \AcrossAI_Main_Menu\SettingsPage::get_settings_renderer(); if ( ! $renderer ) { return; } $page_slug = $renderer->tab_page_slug( self::TAB_SLUG ); add_settings_section( 'acrossai_uninstall_settings_section', __( 'Uninstall Settings', 'acrossai-abilities-manager' ), '__return_false', $page_slug ); add_settings_field( 'acrossai_abilities_uninstall_delete_data', __( 'Delete all data on uninstall', 'acrossai-abilities-manager' ), array( $this, 'render_uninstall_field' ), $page_slug, 'acrossai_uninstall_settings_section' ); } /** * Sanitizes the abilities per-page value. * * Accepts integers in [1, 200]; returns 20 for anything outside that range. * * @since 0.1.0 * @param mixed $value Raw submitted value. * @return int */ public function sanitize_per_page( $value ): int { $int = absint( $value ); return ( $int < 1 || $int > 200 ) ? 20 : $int; } /** * Renders the abilities per-page number input field. * * @since 0.1.0 * @return void */ public function render_per_page_field(): void { $value = (int) get_option( 'acrossai_abilities_per_page', 20 ); printf( '

%s

', esc_attr( (string) $value ), esc_html__( 'Number of abilities shown per page. Default: 20. Min: 1. Max: 200.', 'acrossai-abilities-manager' ) ); } /** * Sanitizes the uninstall delete data checkbox value. * * Returns 1 when the checkbox is checked, 0 when unchecked or absent. * Browsers do not send unchecked checkboxes, so an absent value means 0. * * @since 0.1.0 * @param mixed $value Raw submitted value. * @return int */ public function sanitize_uninstall_flag( $value ): int { return empty( $value ) ? 0 : 1; } /** * Renders the uninstall delete data checkbox field. * * @since 0.1.0 * @return void */ public function render_uninstall_field(): void { $checked = (bool) get_option( 'acrossai_abilities_uninstall_delete_data', 0 ); printf( '

%s

', checked( $checked, true, false ), esc_html__( 'Delete all data on uninstall', 'acrossai-abilities-manager' ), esc_html__( '⚠ Warning: When checked, uninstalling this plugin will permanently delete all custom database tables and plugin options. This cannot be undone.', 'acrossai-abilities-manager' ) ); } }