array( 'label' => __( 'Scanner', 'acceguru' ), 'group' => 'acceguru_settings_scanner', 'kind' => 'form' ),
'fixers' => array( 'label' => __( 'Fixers', 'acceguru' ), 'group' => 'acceguru_settings_fixers', 'kind' => 'form' ),
'ai' => array( 'label' => __( 'AI Alt Text', 'acceguru' ), 'group' => 'acceguru_settings_ai', 'kind' => 'form' ),
'statement' => array( 'label' => __( 'Statement', 'acceguru' ), 'kind' => 'view', 'view' => 'statement-page.php' ),
'advanced' => array( 'label' => __( 'Rules', 'acceguru' ), 'group' => 'acceguru_settings_advanced', 'kind' => 'form' ),
);
/**
* Filters the Settings page tab list.
*
* Each tab descriptor must have at least: label, kind ('form' | 'view' | 'callback').
* For 'form' add 'group' (option-group registered via register_setting).
* For 'view' add 'view' (filename in admin/views/).
* For 'callback' add 'render' (callable that prints the tab body).
*
* @param array $tabs Existing tab descriptors keyed by slug.
*/
$filtered_tabs = apply_filters( 'acceguru_settings_tabs', $default_tabs );
$tabs = array();
if ( is_array( $filtered_tabs ) ) {
foreach ( $filtered_tabs as $slug => $tab ) {
if (
! is_string( $slug )
|| '' === $slug
|| sanitize_key( $slug ) !== $slug
|| ! is_array( $tab )
|| ! isset( $tab['label'], $tab['kind'] )
|| ! is_string( $tab['label'] )
|| '' === trim( $tab['label'] )
|| ! is_string( $tab['kind'] )
) {
continue;
}
$kind = $tab['kind'];
if ( 'form' === $kind ) {
// The page has dedicated markup for its four built-in form tabs.
if (
! isset( $default_tabs[ $slug ] )
|| 'form' !== $default_tabs[ $slug ]['kind']
|| ! isset( $tab['group'] )
|| ! is_string( $tab['group'] )
|| '' === trim( $tab['group'] )
) {
continue;
}
} elseif ( 'view' === $kind ) {
if (
! isset( $tab['view'] )
|| ! is_string( $tab['view'] )
|| '' === $tab['view']
|| basename( $tab['view'] ) !== $tab['view']
|| ! str_ends_with( $tab['view'], '.php' )
|| ! is_file( ACCEGURU_PATH . 'admin/views/' . $tab['view'] )
) {
continue;
}
} elseif ( 'callback' === $kind ) {
if ( ! isset( $tab['render'] ) || ! is_callable( $tab['render'] ) ) {
continue;
}
} else {
continue;
}
$tabs[ $slug ] = $tab;
}
}
// A broken extension must not leave the Settings page empty.
if ( array() === $tabs ) {
$tabs = $default_tabs;
}
$active = isset( $_GET['tab'] ) ? sanitize_key( (string) $_GET['tab'] ) : 'scanner'; // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Read-only tab selector for display, sanitised and validated against the known tab list below; no state change.
if ( ! isset( $tabs[ $active ] ) ) {
$active = isset( $tabs['scanner'] ) ? 'scanner' : (string) array_key_first( $tabs );
}
$current = $tabs[ $active ];
/**
* Reads scalar settings without converting damaged arrays or objects.
* Stored values are not changed; the normal default is used for this view.
*/
$option_scalar = static function ( string $name, mixed $default ): mixed {
$value = get_option( $name, $default );
return is_scalar( $value ) ? $value : $default;
};
/**
* Render a label cell for a form-row.
*
* @param string $title Field title.
* @param string $tip Optional help-tip text. Renders as a help-dot tooltip.
* @param string $hint Optional inline hint shown under the title.
* @param string $badge Optional pre-escaped HTML appended after the title.
*/
$render_label = static function ( string $title, string $tip = '', string $hint = '', string $badge = '' ): void {
echo '
';
echo esc_html( $title );
if ( '' !== $badge ) {
echo wp_kses( ' ' . $badge, acceguru_admin_allowed_html() );
}
echo '';
if ( '' !== $hint ) {
echo '' . wp_kses( $hint, array( 'strong' => array(), 'em' => array() ) ) . '';
}
echo '
';
if ( '' !== $tip ) {
echo wp_kses( ' ' . Acceguru_Admin::help_tip( $tip ), acceguru_admin_allowed_html() );
}
echo '
';
};
/**
* Render a toggle (checkbox styled as iOS-style switch).
*/
$render_toggle = static function ( string $option, int $default = 0 ) use ( $option_scalar ): void {
$checked = (int) $option_scalar( $option, $default );
printf(
'',
esc_attr( $option ),
checked( 1, $checked, false )
);
};
/**
* Render a select.
*
* @param array $choices value => label.
*/
$render_select = static function ( string $option, array $choices, string $default = '' ) use ( $option_scalar ): void {
$current = (string) $option_scalar( $option, '' === $default ? array_key_first( $choices ) : $default );
printf( '';
};
?>