clanfront_labels( 'Game', 'Games', array( 'featured_image' => 'Cover image', 'set_featured_image' => 'Set cover image', 'remove_featured_image' => 'Remove cover image', 'use_featured_image' => 'Use as cover image', 'add_new' => 'Add game', ) ), 'public' => true, 'has_archive' => 'games', 'rewrite' => array( 'slug' => 'game', 'with_front' => false ), 'supports' => array( 'title', 'editor', 'thumbnail', 'page-attributes' ), 'show_in_menu' => CLANFRONT_MENU, 'show_in_rest' => false, ) ); register_post_type( 'clanfront_award', array( 'labels' => clanfront_labels( 'Medal', 'Medals', array( 'add_new' => 'Add medal', 'featured_image' => 'Medal picture (optional)', 'set_featured_image' => 'Set medal picture', 'remove_featured_image' => 'Remove medal picture', 'use_featured_image' => 'Use as medal picture', ) ), 'public' => false, 'show_ui' => true, 'exclude_from_search' => true, 'supports' => array( 'title', 'thumbnail', 'page-attributes' ), 'show_in_menu' => CLANFRONT_MENU, 'show_in_rest' => false, ) ); register_post_type( 'clanfront_shame', array( 'labels' => clanfront_labels( 'Hall of Shame entry', 'Hall of Shame', array( 'menu_name' => 'Hall of Shame', 'all_items' => 'Hall of Shame', 'add_new' => 'Add entry', 'not_found' => 'No shameful moments yet', 'featured_image' => 'Picture (optional)', 'set_featured_image' => 'Set picture', 'remove_featured_image' => 'Remove picture', 'use_featured_image' => 'Use as picture', ) ), 'public' => true, 'has_archive' => 'hall-of-shame', 'rewrite' => array( 'slug' => 'shame', 'with_front' => false ), 'supports' => array( 'title', 'editor', 'thumbnail' ), 'show_in_menu' => CLANFRONT_MENU, 'show_in_rest' => false, ) ); register_post_type( 'clanfront_milestone', array( 'labels' => clanfront_labels( 'Milestone', 'History', array( 'menu_name' => 'History', 'all_items' => 'History', 'add_new' => 'Add milestone', 'not_found' => 'No milestones yet', 'featured_image' => 'Picture (optional)', 'set_featured_image' => 'Set picture', 'remove_featured_image' => 'Remove picture', 'use_featured_image' => 'Use as picture', ) ), 'public' => true, 'has_archive' => 'history', 'rewrite' => array( 'slug' => 'milestone', 'with_front' => false ), 'supports' => array( 'title', 'editor', 'thumbnail' ), 'show_in_menu' => CLANFRONT_MENU, 'show_in_rest' => false, ) ); } add_action( 'init', 'clanfront_register_extra_types' ); // Hall of Shame entries and milestones have no page of their own: send visitors to the list, at that entry. add_action( 'template_redirect', function () { foreach ( array( 'clanfront_shame' => 'shame', 'clanfront_milestone' => 'milestone' ) as $type => $anchor ) { if ( is_singular( $type ) ) { wp_safe_redirect( get_post_type_archive_link( $type ) . '#' . $anchor . '-' . get_queried_object_id() ); exit; } } } ); /* ---------- Games ---------- */ function clanfront_game_statuses() { return array( 'active' => 'Playing now', 'retired' => 'Retired (the Game Graveyard)', ); } /** Game pages. $status: 'active', 'retired' or 'all'. In the order set in the admin. */ function clanfront_get_games( $status = 'active' ) { $all = get_posts( array( 'post_type' => 'clanfront_game', 'post_status' => 'publish', 'posts_per_page' => -1, 'orderby' => array( 'menu_order' => 'ASC', 'title' => 'ASC' ), 'no_found_rows' => true, ) ); if ( 'all' === $status ) { return $all; } $out = array(); foreach ( $all as $g ) { $s = 'retired' === (string) get_post_meta( $g->ID, 'clanfront_status', true ) ? 'retired' : 'active'; if ( $s === $status ) { $out[] = $g; } } return $out; } function clanfront_has_games() { return (bool) clanfront_get_games( 'all' ); } /** Lower-case game names written in a member's "Games" field. */ function clanfront_member_game_list( $member ) { $raw = (string) get_post_meta( $member->ID, 'clanfront_games', true ); $out = array(); foreach ( preg_split( '/[,\n;]+/', $raw ) as $g ) { $g = trim( $g ); if ( '' !== $g ) { $out[] = function_exists( 'mb_strtolower' ) ? mb_strtolower( $g ) : strtolower( $g ); } } return $out; } /** Active members who list this game in their "Games" field. */ function clanfront_game_players( $game ) { $name = trim( get_the_title( $game ) ); $name = function_exists( 'mb_strtolower' ) ? mb_strtolower( $name ) : strtolower( $name ); $out = array(); foreach ( clanfront_get_members() as $m ) { if ( in_array( $name, clanfront_member_game_list( $m ), true ) ) { $out[] = $m; } } return $out; } /** Cover picture of a game, or a tile with its first letters. */ function clanfront_game_cover( $game, $size = 'medium_large' ) { if ( has_post_thumbnail( $game ) ) { return '' . get_the_post_thumbnail( $game, $size, array( 'alt' => '', 'loading' => 'lazy' ) ) . ''; } $initials = function_exists( 'mb_substr' ) ? mb_strtoupper( mb_substr( get_the_title( $game ), 0, 2 ) ) : strtoupper( substr( get_the_title( $game ), 0, 2 ) ); return ''; } /** Cards that link to each game's page. */ function clanfront_game_cards( $games, $retired = false ) { if ( ! $games ) { return ''; } $html = '