array( 'title' => 'Home', 'template' => 'clanfront-home', 'content' => '', ), 'about' => array( 'title' => 'About', 'template' => 'clanfront-about', 'content' => "

This is your clan's story. Tell visitors how it started, who is behind it, what you have achieved and what you are about.

\n\n

Edit this text under Pages → About. Your values, games and achievements are added below it from Clanfront → Settings.

", ), 'join' => array( 'title' => 'Join us', 'template' => 'clanfront-join', 'content' => '

We are always looking for players who fit in with us. Read the requirements, then tell us a bit about yourself.

', ), 'rules' => array( 'title' => 'Rules', 'template' => 'clanfront-rules', 'content' => '', ), 'servers' => array( 'title' => 'Game servers', 'template' => 'clanfront-servers', 'content' => '

Our own servers are open to members and friends. Copy the address and join us in the game.

', ), 'contact' => array( 'title' => 'Contact', 'template' => 'clanfront-page', 'content' => "

For partnerships, press or anything else, email us:

\n\n

[clanfront_email]

", ), ); foreach ( $pages as $slug => $p ) { $existing = get_page_by_path( $slug ); if ( $existing ) { // An existing page keeps its text. It only gets the Clanfront layout when it uses the // theme's default layout; pages set up by another plugin or theme template are left alone. $id = $existing->ID; if ( ! clanfront_page_is_free( $id ) ) { continue; } update_post_meta( $id, '_wp_page_template', $p['template'] ); } else { $id = wp_insert_post( array( 'post_type' => 'page', 'post_status' => 'publish', 'post_title' => $p['title'], 'post_name' => $slug, 'post_content' => $p['content'], ) ); if ( ! $id || is_wp_error( $id ) ) { continue; } update_post_meta( $id, '_wp_page_template', $p['template'] ); } // Only take over the front page when the site shows latest posts or a plain page. if ( 'home' === $slug ) { $front = (int) get_option( 'page_on_front' ); if ( 'page' !== get_option( 'show_on_front' ) || ! $front || $front === (int) $id || clanfront_page_is_free( $front ) ) { update_option( 'show_on_front', 'page' ); update_option( 'page_on_front', (int) $id ); } } } } /** True when a page uses the theme's default layout (or already a Clanfront one), so the plugin may set its layout. */ function clanfront_page_is_free( $page_id ) { $tpl = (string) get_page_template_slug( $page_id ); return '' === $tpl || 'default' === $tpl || array_key_exists( $tpl, clanfront_page_templates() ); } /* ---------- Example content ---------- */ /** Add one of the bundled example pictures to the media library. Returns the attachment ID or 0. */ function clanfront_seed_image( $file, $title ) { $src = CLANFRONT_DIR . 'assets/img/' . $file; if ( ! file_exists( $src ) ) { return 0; } require_once ABSPATH . 'wp-admin/includes/file.php'; require_once ABSPATH . 'wp-admin/includes/image.php'; $bits = wp_upload_bits( 'clanfront-' . $file, null, (string) file_get_contents( $src ) ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents -- a file inside this plugin. if ( ! empty( $bits['error'] ) ) { return 0; } $id = wp_insert_attachment( array( 'post_mime_type' => 'image/jpeg', 'post_title' => $title, 'post_status' => 'inherit', ), $bits['file'] ); if ( ! $id || is_wp_error( $id ) ) { return 0; } wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $bits['file'] ) ); return (int) $id; } function clanfront_seed_content() { $data = clanfront_seed_data(); foreach ( $data['members'] as $i => $m ) { list( $name, $role, $games, $bio ) = $m; $slug = sanitize_title( $name ); if ( get_page_by_path( $slug, OBJECT, 'clanfront_member' ) ) { continue; } $id = wp_insert_post( array( 'post_type' => 'clanfront_member', 'post_status' => 'publish', 'post_title' => $name, 'post_name' => $slug, 'post_content' => $bio, 'menu_order' => $i + 1, ) ); if ( ! $id || is_wp_error( $id ) ) { continue; } $palette = array( '#ff6a00', '#2fb4ff', '#3ecf8e', '#f2c230', '#e0457b', '#9b6bff' ); update_post_meta( $id, 'clanfront_color', $palette[ $i % count( $palette ) ] ); update_post_meta( $id, 'clanfront_role', $role ); update_post_meta( $id, 'clanfront_games', $games ); update_post_meta( $id, 'clanfront_active', '1' ); } foreach ( $data['events'] as $e ) { list( $title, $kind, $days, $time, $game, $opp, $result, $score, $place ) = $e; $slug = sanitize_title( $title ); if ( get_page_by_path( $slug, OBJECT, 'clanfront_match' ) ) { continue; } $id = wp_insert_post( array( 'post_type' => 'clanfront_match', 'post_status' => 'publish', 'post_title' => $title, 'post_name' => $slug, ) ); if ( ! $id || is_wp_error( $id ) ) { continue; } // Dates are relative to the day the plugin is installed, so the site always shows // some results and some upcoming events. $date = new DateTime( clanfront_today(), wp_timezone() ); $date->modify( ( $days >= 0 ? '+' : '' ) . $days . ' days' ); update_post_meta( $id, 'clanfront_date', $date->format( 'Y-m-d' ) ); update_post_meta( $id, 'clanfront_time', $time ); update_post_meta( $id, 'clanfront_kind', $kind ); update_post_meta( $id, 'clanfront_game', $game ); update_post_meta( $id, 'clanfront_opponent', $opp ); update_post_meta( $id, 'clanfront_result', $result ); update_post_meta( $id, 'clanfront_score', $score ); update_post_meta( $id, 'clanfront_placement', $place ); update_post_meta( $id, 'clanfront_notes', 'This is an example. Replace it with your own matches under Clanfront → Matches & events.' ); } if ( ! get_page_by_path( 'community-server', OBJECT, 'clanfront_server' ) ) { $id = wp_insert_post( array( 'post_type' => 'clanfront_server', 'post_status' => 'publish', 'post_title' => 'Community server', 'post_name' => 'community-server', ) ); if ( $id && ! is_wp_error( $id ) ) { update_post_meta( $id, 'clanfront_game', 'Counter-Strike 2' ); update_post_meta( $id, 'clanfront_address', '203.0.113.5:27015' ); update_post_meta( $id, 'clanfront_note', 'Example server. Replace it under Clanfront → Game servers.' ); } } foreach ( array( 1 => 'Clutch round', 2 => 'Tournament day', 3 => 'Game night' ) as $n => $title ) { $slug = sanitize_title( 'example-' . $title ); if ( get_page_by_path( $slug, OBJECT, 'clanfront_media' ) ) { continue; } $id = wp_insert_post( array( 'post_type' => 'clanfront_media', 'post_status' => 'publish', 'post_title' => $title, 'post_name' => $slug, 'menu_order' => $n, ) ); if ( $id && ! is_wp_error( $id ) ) { $img = clanfront_seed_image( 'example-' . $n . '.jpg', 'Example screenshot ' . $n ); if ( $img ) { set_post_thumbnail( $id, $img ); } update_post_meta( $id, 'clanfront_caption', 'Example picture. Replace it under Clanfront → Gallery.' ); } } } function clanfront_seed_data() { // name, role, games, bio $members = array( array( 'Commander Crumbs', 'Leader', 'Counter-Strike 2, Valorant', 'Founded the clan. Example member: replace with a real one under Clanfront → Members.' ), array( 'Ghost Protocol', 'Co-Leader', 'Counter-Strike 2, Rainbow Six Siege', 'Runs scrims and keeps the schedule.' ), array( 'Sgt. Whiffs', 'Captain', 'Valorant, Apex Legends', 'In-game leader for the main team.' ), array( 'Doc Hardscope', 'Coach', 'Counter-Strike 2, Valorant', 'Reviews demos and helps everyone improve.' ), array( 'Lagwagon', 'Recruiter', 'Call of Duty: Warzone, Apex Legends', 'Talk to Lagwagon if you want to join.' ), array( 'Pixel Reaper', 'Player', 'Valorant, Apex Legends', '' ), ); // title, type, days from install date (negative = already played), time, game, opponent, result, score, placement $events = array( array( 'vs Team Orion', 'match', -34, '19:00', 'Counter-Strike 2', 'Team Orion', 'win', '13-9', '' ), array( 'vs Night Owls', 'match', -24, '20:00', 'Valorant', 'Night Owls', 'loss', '10-13', '' ), array( 'Spring Cup final', 'tournament', -12, '18:00', 'Counter-Strike 2', 'Iron Wolves', 'win', '2-1', '1st place' ), array( 'Practice scrim', 'scrim', 3, '19:30', 'Valorant', 'Team Nova Red', '', '', '' ), array( 'Summer League: round 1', 'tournament', 9, '18:00', 'Counter-Strike 2', 'Apex Five', '', '', '' ), array( 'Squad night', 'game_night', 14, '20:00', 'Apex Legends', '', '', '', '' ), ); return array( 'members' => $members, 'events' => $events, ); } /* ---------- Example content for Games, Medals, Hall of Shame and History (1.5.0) ---------- */ /** A published example post, created once (looked up by its slug). Returns its ID, or 0 if it already existed. */ function clanfront_seed_post( $type, $slug, $title, $content = '', $order = 0 ) { if ( get_page_by_path( $slug, OBJECT, $type ) ) { return 0; } $id = wp_insert_post( array( 'post_type' => $type, 'post_status' => 'publish', 'post_title' => $title, 'post_name' => $slug, 'post_content' => $content, 'menu_order' => $order, ) ); return ( $id && ! is_wp_error( $id ) ) ? (int) $id : 0; } /** An example member's ID by name, or 0. */ function clanfront_seed_member_id( $name ) { $m = get_page_by_path( sanitize_title( $name ), OBJECT, 'clanfront_member' ); return $m ? (int) $m->ID : 0; } /** A date relative to today, as Y-m-d. */ function clanfront_seed_date( $days ) { $d = new DateTime( clanfront_today(), wp_timezone() ); $d->modify( ( $days >= 0 ? '+' : '' ) . (int) $days . ' days' ); return $d->format( 'Y-m-d' ); } /** * Example games, medals, Hall of Shame entries and milestones. Safe to run more than once: * anything that already exists (by its address) is skipped, and nothing you wrote is changed. * Returns how many items were added. */ function clanfront_seed_extras() { $added = 0; $note = "\n\n

This is an example. Edit or delete it under Clanfront.

"; // Games: name, short line, platform, status, epitaph, picture, page text. $games = array( array( 'Counter-Strike 2', 'Competitive 5v5 and Friday scrims', 'PC', 'active', '', 'example-1.jpg', '

Our main competitive game. Scrims on Fridays, league matches most weekends, and a lot of arguing about which site to take.

Field notes

' ), array( 'Valorant', 'Ranked stacks and scrims', 'PC', 'active', '', 'example-2.jpg', '

Ranked five-stacks most evenings. Ask in Discord and someone will be on.

Field notes

' ), array( 'Apex Legends', 'Squad nights', 'PC, PlayStation, Xbox', 'active', '', 'example-3.jpg', '

Casual squad nights. Hot drops only, survival optional.

' ), array( 'Call of Duty: Warzone', 'Casual drops', 'PC, PlayStation, Xbox', 'active', '', '', '

For when we want to lose loudly in a big lobby.

' ), array( 'Space Hamsters Online', '', 'PC', 'retired', 'It never stood a chance. Neither did we.', '', '

A brave experiment that lasted exactly one weekend. We still talk about the hamster incident.

' ), ); $i = 0; foreach ( $games as $g ) { ++$i; $id = clanfront_seed_post( 'clanfront_game', sanitize_title( 'example-game-' . $g[0] ), $g[0], $g[6] . $note, $i ); if ( ! $id ) { continue; } ++$added; update_post_meta( $id, 'clanfront_note', $g[1] ); update_post_meta( $id, 'clanfront_platform', $g[2] ); update_post_meta( $id, 'clanfront_status', $g[3] ); update_post_meta( $id, 'clanfront_epitaph', $g[4] ); if ( $g[5] ) { $img = clanfront_seed_image( $g[5], $g[0] . ' cover (example)' ); if ( $img ) { set_post_thumbnail( $id, $img ); } } } // Medals: name, emoji, what it is for, given to. $medals = array( array( 'Squad MVP', '🎖️', 'Carried the team when it mattered.', array( 'Commander Crumbs', 'Ghost Protocol' ) ), array( 'Grenade Juggler', '💣', 'Most teammates taken out with a single grenade.', array( 'Sgt. Whiffs' ) ), array( 'Medic (Allegedly)', '🚑', 'Has revived at least one person. Probably.', array( 'Doc Hardscope' ) ), array( 'Walking Liability', '🔥', 'Somehow always in the line of fire. Usually ours.', array( 'Sgt. Whiffs', 'Lagwagon' ) ), array( 'Clutch King', '🎯', 'Won a 1v3 and has not stopped talking about it.', array( 'Pixel Reaper', 'Ghost Protocol' ) ), ); $i = 0; foreach ( $medals as $m ) { ++$i; $id = clanfront_seed_post( 'clanfront_award', sanitize_title( 'example-medal-' . $m[0] ), $m[0], '', $i ); if ( ! $id ) { continue; } ++$added; update_post_meta( $id, 'clanfront_icon', $m[1] ); update_post_meta( $id, 'clanfront_description', $m[2] ); foreach ( $m[3] as $who ) { $mid = clanfront_seed_member_id( $who ); if ( ! $mid ) { continue; } $have = get_post_meta( $mid, 'clanfront_awards', true ); $have = is_array( $have ) ? array_map( 'absint', $have ) : array(); if ( ! in_array( $id, $have, true ) ) { $have[] = $id; update_post_meta( $mid, 'clanfront_awards', $have ); } } } // Hall of Shame: title, days ago, game, to blame, story. $shame = array( array( 'The Grenade Incident', -9, 'Counter-Strike 2', array( 'Sgt. Whiffs' ), '

Round 14, match point. Sgt. Whiffs announced "I\'ve got this" and threw a perfect grenade into a corner with four of our own players in it. The enemy did not even need to show up.

He got the round MVP. For the other team.

' ), array( 'Defused the Wrong Thing', -27, 'Counter-Strike 2', array( 'Lagwagon' ), '

Lagwagon spent the full ten seconds "defusing" a crate. The bomb was on the other site. So was everyone else.

' ), array( 'The Revive That Wasn\'t', -45, 'Valorant', array( 'Doc Hardscope', 'Pixel Reaper' ), '

Doc Hardscope revived the wrong player. Pixel Reaper, still dead, watched it happen in silence. Their friendship has not recovered.

' ), ); foreach ( $shame as $n => $e ) { $id = clanfront_seed_post( 'clanfront_shame', sanitize_title( 'example-' . $e[0] ), $e[0], $e[4] . $note ); if ( ! $id ) { continue; } ++$added; if ( 0 === $n ) { $img = clanfront_seed_image( 'example-1.jpg', 'Hall of Shame picture (example)' ); if ( $img ) { set_post_thumbnail( $id, $img ); } } update_post_meta( $id, 'clanfront_date', clanfront_seed_date( $e[1] ) ); update_post_meta( $id, 'clanfront_game', $e[2] ); $ids = array(); foreach ( $e[3] as $who ) { $mid = clanfront_seed_member_id( $who ); if ( $mid ) { $ids[] = $mid; } } update_post_meta( $id, 'clanfront_culprits', $ids ); } // History: title, type, days ago, story. $history = array( array( 'The clan is founded', 'founded', -760, '

Two friends, one Discord server and a name that turned out to be a warning.

' ), array( 'First official match', 'milestone', -700, '

We showed up, we played, we lost 2-13. A legend was born anyway.

' ), array( 'The Great Lag Disaster', 'disaster', -540, '

The whole team disconnected in a tournament final. Somebody\'s router is still under investigation.

' ), array( 'Ten members strong', 'roster', -365, '

The roster hits double digits. The friendly fire statistics follow.

' ), array( 'Winter League finalists', 'victory', -300, '

Our first final, and our first trophy-shaped hope.

' ), array( 'Spring Cup champions', 'victory', -12, '

First place in the Spring Cup after a 2-1 final. Nobody was team-killed. Much.

' ), ); foreach ( $history as $h ) { $id = clanfront_seed_post( 'clanfront_milestone', sanitize_title( 'example-' . $h[0] ), $h[0], $h[3] . $note ); if ( ! $id ) { continue; } ++$added; update_post_meta( $id, 'clanfront_kind', $h[1] ); update_post_meta( $id, 'clanfront_date', clanfront_seed_date( $h[2] ) ); } update_option( 'clanfront_seeded_extras', CLANFRONT_VERSION ); return $added; } // The "Add example content" button on the Getting started page. add_action( 'admin_post_clanfront_add_examples', function () { if ( ! current_user_can( 'manage_options' ) ) { wp_die( esc_html__( 'You do not have permission to do this.', 'clanfront' ) ); } check_admin_referer( 'clanfront_add_examples' ); $n = clanfront_seed_extras(); flush_rewrite_rules( false ); wp_safe_redirect( add_query_arg( 'clanfront_examples', (int) $n, admin_url( 'admin.php?page=clanfront-guide' ) ) ); exit; } );