slug => translated default label */ private static function default_entries(): array { return [ 'scientific' => __( 'Scientific', 'academiccrew' ), 'industrial' => __( 'Industrial', 'academiccrew' ), ]; } /** @return array slug => label, in stored order */ public static function all(): array { $stored = get_option( self::OPTION, null ); return is_array( $stored ) ? $stored : self::default_entries(); } public static function keys(): array { return array_keys( self::all() ); } public static function label( string $slug ): string { return self::all()[ $slug ] ?? $slug; } public static function exists( string $slug ): bool { return isset( self::all()[ $slug ] ); } /** @param array $entries slug => label */ public static function save( array $entries ): void { update_option( self::OPTION, $entries ); } /** Number of published projects currently tagged with $slug. */ public static function usage_count( string $slug ): int { $query = new \WP_Query( [ 'post_type' => 'acc_collaboration', 'post_status' => 'any', 'posts_per_page' => 1, 'fields' => 'ids', 'no_found_rows' => false, 'meta_query' => [ [ 'key' => '_acc_project_type', 'value' => $slug ] ], // phpcs:ignore WordPress.DB.SlowDBQuery ] ); return (int) $query->found_posts; } }