*/ private static function default_entries(): array { $former = [ 'dot' => '#9CA3AF', 'bg' => '#F3F4F6', 'text' => '#6B7280' ]; return [ // Active members 'full-professor' => [ 'label' => __( 'Full Professor', 'academiccrew' ), 'dot' => '#c41230', 'bg' => '#FCEBEB', 'text' => '#A32D2D' ], 'associate-professor' => [ 'label' => __( 'Associate Professor', 'academiccrew' ), 'dot' => '#185FA5', 'bg' => '#E6F1FB', 'text' => '#0C447C' ], 'assistant-professor' => [ 'label' => __( 'Assistant Professor', 'academiccrew' ), 'dot' => '#3B6D11', 'bg' => '#EAF3DE', 'text' => '#3B6D11' ], 'researcher' => [ 'label' => __( 'Researcher', 'academiccrew' ), 'dot' => '#0F6E56', 'bg' => '#E1F5EE', 'text' => '#085041' ], 'postdoc' => [ 'label' => __( 'Postdoctoral Researcher', 'academiccrew' ), 'dot' => '#854F0B', 'bg' => '#FAEEDA', 'text' => '#854F0B' ], 'phd-student' => [ 'label' => __( 'PhD Student', 'academiccrew' ), 'dot' => '#534AB7', 'bg' => '#EEEDFE', 'text' => '#3C3489' ], 'research-assistant' => [ 'label' => __( 'Research Assistant', 'academiccrew' ), 'dot' => '#6B4D99', 'bg' => '#F0ECFB', 'text' => '#4A2E8A' ], 'visiting-researcher' => [ 'label' => __( 'Visiting Researcher', 'academiccrew' ), 'dot' => '#B45309', 'bg' => '#FEF3C7', 'text' => '#92400E' ], 'collaborator' => [ 'label' => __( 'Collaborator', 'academiccrew' ), 'dot' => '#5F5E5A', 'bg' => '#F1EFE8', 'text' => '#444441' ], // Former members 'former-professor' => array_merge( [ 'label' => __( 'Former Professor', 'academiccrew' ) ], $former ), 'former-researcher' => array_merge( [ 'label' => __( 'Former Researcher', 'academiccrew' ) ], $former ), 'former-postdoc' => array_merge( [ 'label' => __( 'Former Postdoctoral Researcher', 'academiccrew' ) ], $former ), 'former-phd' => array_merge( [ 'label' => __( 'Former PhD Student', 'academiccrew' ) ], $former ), 'former-research-assistant' => array_merge( [ 'label' => __( 'Former Research Assistant', 'academiccrew' ) ], $former ), 'alumni' => array_merge( [ 'label' => __( 'Alumni', 'academiccrew' ) ], $former ), ]; } /** @return array */ private static function entries(): array { $stored = get_option( self::OPTION, null ); return is_array( $stored ) ? $stored : self::default_entries(); } /** @return array slug => translated label */ public static function all(): array { return array_map( static fn( array $e ): string => $e['label'], self::entries() ); } /** * @return array */ public static function colors(): array { return array_map( static fn( array $e ): array => [ 'dot' => $e['dot'], 'bg' => $e['bg'], 'text' => $e['text'] ], self::entries() ); } public static function label( string $key ): string { return self::all()[ $key ] ?? $key; } /** Returns the dot/accent hex color for a role. */ public static function color( string $key ): string { return self::colors()[ $key ]['dot'] ?? '#6b7280'; } /** Returns only the role slugs, without labels. */ public static function keys(): array { return array_keys( self::all() ); } /** * Derives bg/text shades from a single accent color — used when saving * a role the admin recolored or a brand new one. * @return array{dot:string,bg:string,text:string} */ public static function shades_from_dot( string $dot ): array { return [ 'dot' => $dot, 'bg' => ColorMath::tint( $dot ), 'text' => ColorMath::shade( $dot ), ]; } /** @param array $entries */ public static function save( array $entries ): void { update_option( self::OPTION, $entries ); } /** Number of members currently assigned to $slug. */ public static function usage_count( string $slug ): int { $query = new \WP_Query( [ 'post_type' => 'academiccrew_member', 'post_status' => 'any', 'posts_per_page' => 1, 'fields' => 'ids', 'no_found_rows' => false, 'meta_query' => [ [ 'key' => '_acc_member_role', 'value' => $slug ] ], // phpcs:ignore WordPress.DB.SlowDBQuery ] ); return (int) $query->found_posts; } }