13, 'max_font' => 28, 'max_tags' => 60, 'orderby' => 'count', 'link' => 'yes', ], $atts, 'academiccrew_areas_cloud' ); $min_font = max( 8, (int) $atts['min_font'] ); $max_font = min( 60, (int) $atts['max_font'] ); $max_tags = max( 1, (int) $atts['max_tags'] ); $counts = $this->collect_area_counts(); if ( empty( $counts ) ) return ''; if ( $atts['orderby'] === 'name' ) { ksort( $counts ); } else { arsort( $counts ); } $counts = array_slice( $counts, 0, $max_tags, true ); $min_count = min( $counts ); $max_count = max( $counts ); $range = max( 1, $max_count - $min_count ); $archive_url = get_option( 'academiccrew_members_archive_page_id' ) ? get_permalink( (int) get_option( 'academiccrew_members_archive_page_id' ) ) : ''; ob_start(); ?>
enqueue_assets_once(); return ob_get_clean(); } /** Registers + enqueues the tag-cloud CSS, at most once per request. */ private function enqueue_assets_once(): void { static $done = false; if ( $done ) { return; } $done = true; wp_register_style( 'acc-areas-cloud', false, [], ACADEMICCREW_VERSION ); wp_add_inline_style( 'acc-areas-cloud', <<<'CSS' .acc-areas-cloud{display:flex;flex-wrap:wrap;gap:8px 12px;align-items:baseline;line-height:1.4} .acc-area-cloud-tag{color:var(--acc-red,#c41230);text-decoration:none;font-weight:500;transition:opacity .15s} .acc-area-cloud-tag:hover{opacity:1!important;text-decoration:underline} CSS ); wp_enqueue_style( 'acc-areas-cloud' ); } private function collect_area_counts(): array { $members = get_posts( [ 'post_type' => 'academiccrew_member', 'post_status' => 'publish', 'posts_per_page' => -1, 'fields' => 'ids', ] ); $counts = []; foreach ( $members as $mid ) { $raw = get_post_meta( (int) $mid, '_acc_research_areas', true ); $areas = is_array( $raw ) ? $raw : []; foreach ( $areas as $area ) { $area = trim( $area ); if ( $area ) { $counts[ $area ] = ( $counts[ $area ] ?? 0 ) + 1; } } } return $counts; } }