*/ public static function defaults(): array { return array( 'route' => 'app', 'site_name' => '', 'logo_id' => 0, 'primary' => '#4f46e5', 'mode' => 'light', // light | dark | auto 'preset' => 'console', // console | comfort 'redirect_login' => 1, // wp-login.php -> Dashbread login (non-admins) 'land_in_app' => 1, // after login go to /app 'hide_admin_bar' => 1, // for users without edit_posts 'block_admin' => 1, // wp-admin -> /app for users without edit_posts 'legacy_login' => 1, // /login -> /app redirect 'footer_text' => '', 'powered_by' => 0, // "Powered by Dashbread" in the app footer — opt-in (wp.org guideline 10) 'menus' => array(), // location => menu term id, kept here so it survives theme switches ); } public function register(): void { add_action( 'after_switch_theme', array( $this, 'reapply_menu_locations' ) ); } /** @return array */ public static function all(): array { $saved = get_option( self::OPTION, array() ); return array_merge( self::defaults(), is_array( $saved ) ? $saved : array() ); } public static function get( string $key ): mixed { return self::all()[ $key ] ?? null; } /** @param array $patch */ public static function update( array $patch ): void { update_option( self::OPTION, array_merge( self::all(), $patch ) ); } public static function route(): string { $r = sanitize_title( (string) self::get( 'route' ) ); return '' === $r ? 'app' : $r; } /** Pretty permalinks give /app/...; on "Plain" permalinks the query form still works. */ public static function app_url( string $path = '' ): string { $path = ltrim( $path, '/' ); if ( '' === (string) get_option( 'permalink_structure' ) ) { return add_query_arg( \Dashbread\Core\Router::QV, '/' . $path, home_url( '/' ) ); } return home_url( '/' . self::route() . '/' . $path ); } public static function pretty_permalinks(): bool { return '' !== (string) get_option( 'permalink_structure' ); } /** Core owns the location -> menu mapping; theme mods only mirror it. */ public function reapply_menu_locations(): void { $mine = (array) self::get( 'menus' ); if ( ! $mine ) { return; } $locations = get_theme_mod( 'nav_menu_locations', array() ); set_theme_mod( 'nav_menu_locations', array_merge( (array) $locations, $mine ) ); } }