Skip to content

Commit 13c002d

Browse files
committed
Flagship Landing: Add initial functionality
It's disabled because the design hasn't been implemented yet.
1 parent a6e6027 commit 13c002d

File tree

24 files changed

+742
-6
lines changed

24 files changed

+742
-6
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,4 +113,6 @@ public_html/wp-content/themes/twentytwentyfour
113113
public_html/wp-content/themes/wporg-parent-2021
114114
public_html/wp-content/themes/wporg-events-2023/style.css
115115
public_html/wp-content/themes/wporg-events-2023/editor.css
116+
public_html/wp-content/themes/wporg-flagship-landing/style.css
117+
public_html/wp-content/themes/wporg-flagship-landing/editor.css
116118
public_html/wp-content/fonts

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
"public_html/wp-content/plugins/wcpt",
2020
"public_html/wp-content/plugins/wordcamp-forms-to-drafts",
2121
"public_html/wp-content/plugins/wordcamp-speaker-feedback",
22-
"public_html/wp-content/themes/wporg-events-2023"
22+
"public_html/wp-content/themes/wporg-events-2023",
23+
"public_html/wp-content/themes/wporg-flagship-landing"
2324
],
2425
"browserslist": [
2526
"extends @wordpress/browserslist-config"

public_html/wp-content/mu-plugins/load-other-mu-plugins.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ function wcorg_include_common_plugins() {
1616
require_once dirname( __DIR__ ) . '/mu-plugins-private/wporg-mu-plugins.php';
1717
}
1818

19+
// Include the public `wporg-mu-plugins` that are synced from Git to SVN. These are different than the
20+
// ones included in `wcorg_include_common_plugins()`.
21+
require_once dirname( __DIR__ ) . '/mu-plugins-private/wporg-mu-plugins/pub-sync/loader.php';
22+
1923
wcorg_include_individual_mu_plugins();
2024
wcorg_include_mu_plugin_folders();
2125
}
@@ -27,9 +31,6 @@ function wcorg_include_network_only_plugins() {
2731
if ( EVENTS_NETWORK_ID === SITE_ID_CURRENT_SITE ) {
2832
$network_folder = 'events';
2933

30-
// Include the public `wporg-mu-plugins` that are synced from Git to SVN. These are different than the
31-
// ones included in `wcorg_include_common_plugins()`.
32-
require_once dirname( __DIR__ ) . '/mu-plugins-private/wporg-mu-plugins/pub-sync/loader.php';
3334
} else {
3435
$network_folder = 'wordcamp';
3536
}

public_html/wp-content/sunrise-wordcamp.php

Lines changed: 106 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
<?php
22

33
namespace WordCamp\Sunrise;
4+
use WP_Network, WP_Site;
5+
use WordCamp_Loader;
6+
47
defined( 'WPINC' ) || die();
58

69
// phpcs:disable WordPress.WP.AlternativeFunctions.parse_url_parse_url -- It's not available this early.
@@ -44,6 +47,82 @@ function main() {
4447
'path' => $path
4548
) = guess_requested_domain_path();
4649

50+
/*
51+
* @todo enable this when design is implemented.
52+
if ( is_flagship_landing_url( $domain, $path ) ) {
53+
if ( setup_flagship_landing_site( $domain ) ) {
54+
return;
55+
}
56+
}
57+
*/
58+
59+
redirect_to_site( $domain, $path );
60+
}
61+
62+
/**
63+
* Show the flagship landing page.
64+
*/
65+
function setup_flagship_landing_site( string $domain ): bool {
66+
$latest_site = get_latest_site( $domain );
67+
68+
if ( ! $latest_site ) {
69+
return false;
70+
}
71+
72+
set_network_and_site( $latest_site );
73+
74+
remove_action( 'template_redirect', 'redirect_canonical' );
75+
76+
add_filter(
77+
'template',
78+
function (): string {
79+
return 'wporg-parent-2021';
80+
}
81+
);
82+
83+
add_filter(
84+
'stylesheet',
85+
function (): string {
86+
return 'wporg-flagship-landing';
87+
}
88+
);
89+
90+
add_filter(
91+
'option_wccsp_settings',
92+
function ( array $settings ): array {
93+
$settings['enabled'] = 'off';
94+
95+
return $settings;
96+
}
97+
);
98+
99+
return true;
100+
}
101+
102+
/**
103+
* Set the current network and site when given a site.
104+
*
105+
* phpcs:disable WordPress.WP.GlobalVariablesOverride.Prohibited -- WP is designed in a way that requires this.
106+
* Setting these vars is what `sunrise.php` is designed to do.
107+
*/
108+
function set_network_and_site( object $site ) {
109+
global $current_site, $current_blog, $blog_id, $site_id, $domain, $path, $public;
110+
111+
// Originally WP referred to networks as "sites" and sites as "blogs".
112+
$current_site = WP_Network::get_instance( WORDCAMP_NETWORK_ID );
113+
$site_id = $current_site->id;
114+
$path = stripslashes( $_SERVER['REQUEST_URI'] );
115+
$current_blog = WP_Site::get_instance( $site->blog_id );
116+
117+
$blog_id = $current_blog->id;
118+
$domain = $current_blog->domain;
119+
$public = $current_blog->public;
120+
}
121+
122+
/**
123+
* Redirect requests to the correct site.
124+
*/
125+
function redirect_to_site( string $domain, string $path ): void {
47126
add_action( 'template_redirect', __NAMESPACE__ . '\redirect_duplicate_year_permalinks_to_post_slug' );
48127

49128
$status_code = 301;
@@ -131,6 +210,20 @@ function guess_requested_domain_path() {
131210
);
132211
}
133212

213+
/**
214+
* Check if the given domain/path is a flagship landing page.
215+
*/
216+
function is_flagship_landing_url( string $domain, string $path ): bool {
217+
$flagship_events = array( 'asia', 'centroamerica', 'europe', 'us' );
218+
$third_level_domain = explode( '.', $domain )[0];
219+
220+
if ( in_array( $third_level_domain, $flagship_events ) && '/' === $path ) {
221+
return true;
222+
}
223+
224+
return false;
225+
}
226+
134227
/**
135228
* Redirect root site front-end requests to Central.
136229
*
@@ -528,8 +621,19 @@ function get_canonical_year_url( $domain, $path ) {
528621
break;
529622
}
530623

624+
$latest = get_latest_site( $domain );
625+
626+
return $latest ? 'https://' . $latest->domain . $latest->path : false;
627+
}
628+
629+
/**
630+
* Get the latest site for a given city.
631+
*/
632+
function get_latest_site( string $domain ) {
633+
global $wpdb;
634+
531635
$latest = $wpdb->get_row( $wpdb->prepare( "
532-
SELECT `domain`, `path`
636+
SELECT `blog_id`, `domain`, `path`
533637
FROM $wpdb->blogs
534638
WHERE
535639
( domain = %s AND path != '/' ) OR -- Match city/year format.
@@ -540,7 +644,7 @@ function get_canonical_year_url( $domain, $path ) {
540644
"%.{$domain}"
541645
) );
542646

543-
return $latest ? 'https://' . $latest->domain . $latest->path : false;
647+
return $latest;
544648
}
545649

546650
/**
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"extends": "@wordpress/stylelint-config",
3+
"rules": {
4+
"max-line-length": null,
5+
"no-duplicate-selectors": null,
6+
"no-descending-specificity": null,
7+
"rule-empty-line-before": [
8+
"always-multi-line",
9+
{
10+
"except": [
11+
"first-nested",
12+
"after-single-line-comment"
13+
]
14+
}
15+
],
16+
"selector-class-pattern": null
17+
}
18+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# wporg-flagship-landing
2+
3+
You must run the `build` task for this to be recognized as a valid theme by WP.

0 commit comments

Comments
 (0)