` heading. Defaults to "Settings". */ public function __construct( private SettingsRegistry $registry, private string $page_slug = '', private string $registry_page = 'default', private string $heading = '' ) { if ( '' === $this->page_slug ) { $this->page_slug = Menu::SLUG . '-settings'; } if ( '' === $this->heading ) { $this->heading = __( 'Settings', 'all-in-one-utilities' ); } } /** * Hook registration with the core Settings API. * * @return void */ public function boot(): void { add_action( 'admin_init', array( $this, 'register' ) ); } /** * Register every tab as a WordPress option/setting. * * @return void */ public function register(): void { $this->registry->register_with_wp(); } /** * Render the Settings screen. * * @return void */ public function render(): void { $tabs = $this->registry->get_tabs_for_page( $this->registry_page ); if ( empty( $tabs ) ) { ?>

heading ); ?>

heading, $this->nav_groups( $tabs, $current ), $this->search_index( $tabs ) ); ?>

registry->option_name( $current ) ); ?> render_tab( $current ); ?>
registry_page ); ?>
registry_page ); ?>
render_doc_templates( $current ); } /** * The admin page slug that renders a tab from the given `add_tab()` * page group: this screen for its own group, Free's Settings screen * for the default group. * * @param string $registry_page The tab's page group. * @return string */ private function page_slug_for( string $registry_page ): string { return ( $registry_page === $this->registry_page || 'default' !== $registry_page ) ? $this->page_slug : Menu::SLUG . '-settings'; } /** * An unticked checkbox posts nothing, and `SettingsRegistry::save_mirrors()` * skips fields it didn't receive, so a mirrored checkbox sends an * explicit "off" first (the checkbox itself overrides it when ticked). * * @param Field $field Mirrored field. * @param string $name_prefix Its input name prefix. * @return void */ private static function render_mirror_off_input( Field $field, string $name_prefix ): void { if ( 'checkbox' === $field->type ) { printf( '', esc_attr( $name_prefix . '[' . $field->id . ']' ) ); } } /** * URL of one of this screen's tabs. * * @param string $tab_id Tab id. * @param string $anchor Optional element id to jump to. * @return string */ private function tab_url( string $tab_id, string $anchor = '' ): string { $url = add_query_arg( array( 'page' => $this->page_slug, 'tab' => $tab_id, ), admin_url( 'admin.php' ) ); return '' !== $anchor ? $url . '#' . $anchor : $url; } /** * The left column's groups: one per tab, listing its sections. Only the * current tab's group starts open. * * @param array $tabs This screen's tabs. * @param string $current Current tab id. * @return array> */ private function nav_groups( array $tabs, string $current ): array { $groups = array(); foreach ( $tabs as $tab_id => $tab ) { $items = array(); foreach ( $this->registry->get_sections( $tab_id ) as $section_id => $section ) { $anchor = 'aiou-section-' . $section_id; $items[] = array( 'label' => $section['label'], 'url' => $tab_id === $current ? '#' . $anchor : $this->tab_url( $tab_id, $anchor ), 'anchor' => $tab_id === $current ? $anchor : '', ); } $groups[] = array( 'id' => $tab_id, 'label' => $tab['label'], 'icon' => AdminShell::tab_icon( $tab_id ), 'open' => $tab_id === $current, 'items' => $items, ); } return $groups; } /** * Quick-search entries for every section and labelled field on this * screen, across all of its tabs. * * @param array $tabs This screen's tabs. * @return array> */ private function search_index( array $tabs ): array { $index = array(); foreach ( $tabs as $tab_id => $tab ) { foreach ( $this->registry->get_sections( $tab_id ) as $section_id => $section ) { $index[] = array( 'label' => $section['label'], 'context' => $tab['label'], 'url' => $this->tab_url( $tab_id, 'aiou-section-' . $section_id ), 'keywords' => $section['description'], ); foreach ( $this->registry->get_fields( $tab_id, $section_id ) as $field ) { if ( '' === $field->label ) { continue; } $index[] = array( 'label' => $field->label, 'context' => $tab['label'] . ' › ' . $section['label'], 'url' => $this->tab_url( $tab_id, 'aiou-row-' . $section_id . '-' . $field->id ), 'keywords' => (string) ( $field->args['toggle_label'] ?? '' ), ); } } } return $index; } /** * Close a section before it's painted if this browser last left it * closed (`admin-settings.js` saves the choice in localStorage under * `aiouClosedSections`). Runs first inside the section's body. * * @return void */ private static function restore_section_state(): void { ?> registry->get_values( $tab_id ); $name_prefix = $this->registry->option_name( $tab_id ); foreach ( $this->registry->get_sections( $tab_id ) as $section_id => $section ) { $inactive = $this->registry->inactive_fields( $tab_id, $section_id, $values[ $section_id ] ?? array() ); $body_id = 'aiou-section-body-' . $section_id; $toggles = array_filter( $this->registry->get_fields( $tab_id, $section_id ), static fn ( Field $field ): bool => 'checkbox' === $field->type ); $on = count( array_filter( $toggles, static fn ( Field $field ): bool => ! empty( $values[ $section_id ][ $field->id ] ) ) ); ?>

render_info_button( 'section-' . $section_id, $section['label'] ); ?>

registry->get_fields( $tab_id, $section_id ) as $field ) : ?> id; $depends_on = $field->args['depends_on'] ?? null; $field_owner = $this->registry->get_field_owner( $tab_id, $section_id, $field->id ); $row_classes = $field_owner !== $section['owner'] ? array( 'aiou-field-row', 'aiou-owner--' . $field_owner ) : array(); $row_attrs = ' id="' . esc_attr( 'aiou-row-' . $section_id . '-' . $field->id ) . '"'; if ( $depends_on ) { $row_attrs .= ' data-aiou-depends="' . esc_attr( 'aiou-field-' . $section_id . '-' . $depends_on ) . '"'; if ( ! empty( $field->args['depends_hide'] ) ) { $row_attrs .= ' data-aiou-depends-hide'; } // Shown, but greyed out and inert (or hidden), while what it depends on is off. if ( isset( $inactive[ $field->id ] ) ) { $row_classes[] = 'aiou-is-inactive'; $row_attrs .= empty( $field->args['depends_hide'] ) ? ' inert' : ' inert hidden'; } } if ( $row_classes ) { $row_attrs .= ' class="' . esc_attr( implode( ' ', $row_classes ) ) . '"'; } ?> > args['full_width'] ) ) : ?> args['label_above'] ) ) : ?> render_mirrors( $tab_id, $section_id ); ?>
registry->get_mirrors( $tab_id, $section_id ); if ( ! $mirrors ) { return; } $tabs = $this->registry->get_tabs(); $sources = array_unique( wp_list_pluck( $mirrors, 'tab' ) ); $values = array(); $headings = array_filter( wp_list_pluck( $mirrors, 'heading' ) ); $heading = $headings ? (string) reset( $headings ) : __( 'Related emails', 'all-in-one-utilities' ); $mirrored = array(); foreach ( $sources as $source ) { $values[ $source ] = $this->registry->get_values( $source ); } foreach ( $mirrors as $mirror ) { $mirrored[ $mirror['tab'] . '/' . $mirror['section'] ][ $mirror['field']->id ] = true; } ?>

%2$s', esc_url( add_query_arg( array( 'page' => $this->page_slug_for( $tabs[ $source ]['page'] ?? 'default' ), 'tab' => $source, ), admin_url( 'admin.php' ) ) ), esc_html( $tabs[ $source ]['label'] ?? $source ) ); } printf( /* translators: %s: link(s) to the settings tab(s) these fields also appear on */ esc_html__( 'These are the same settings shown on the %s tab. Changes saved here or there update both.', 'all-in-one-utilities' ), implode( ', ', $links ) // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- each link is built from esc_url()/esc_html() above. ); ?>

id ] ?? $field->default; $name = $this->registry->option_name( $mirror['tab'] ) . '[' . $mirror['section'] . ']'; $id = 'aiou-mirror-' . $mirror['section'] . '-' . $field->id; $owner = 'free' !== $mirror['owner'] ? ' aiou-field-row aiou-owner--' . $mirror['owner'] : ''; $attrs = ''; // Keep a `depends_on` link working when its controller is mirrored here too. $depends_on = (string) ( $field->args['depends_on'] ?? '' ); if ( '' !== $depends_on && isset( $mirrored[ $mirror['tab'] . '/' . $mirror['section'] ][ $depends_on ] ) ) { $attrs .= ' data-aiou-depends="' . esc_attr( 'aiou-mirror-' . $mirror['section'] . '-' . $depends_on ) . '"'; $inactive = $this->registry->inactive_fields( $mirror['tab'], $mirror['section'], $values[ $mirror['tab'] ][ $mirror['section'] ] ?? array() ); if ( isset( $inactive[ $field->id ] ) ) { $owner .= ' aiou-is-inactive'; $attrs .= ' inert'; } } ?> > args['full_width'] ) ) : ?> __( 'Pro', 'all-in-one-utilities' ), 'woo' => __( 'Woo', 'all-in-one-utilities' ), 'tools' => __( 'Tools', 'all-in-one-utilities' ), 'chat' => __( 'Chat', 'all-in-one-utilities' ), 'external' => __( 'Add-on', 'all-in-one-utilities' ), ); printf( ' %2$s', esc_attr( $owner ), esc_html( $labels[ $owner ] ?? ucfirst( $owner ) ) ); } /** * Render an "i" info-control button. * * @param string $target Doc template target key. * @param string $for_label Label used to build an accessible name. * @return void */ private function render_info_button( string $target, string $for_label ): void { printf( ' ', esc_attr( $target ), /* translators: %s: field or section label */ esc_attr( sprintf( __( 'More information about %s', 'all-in-one-utilities' ), $for_label ) ) ); } /** * Render hidden