Skip to content

Commit

Permalink
Flagship Landing: Add initial functionality
Browse files Browse the repository at this point in the history
It's disabled because the design hasn't been implemented yet.
  • Loading branch information
iandunn committed Jan 30, 2024
1 parent a6e6027 commit 13c002d
Show file tree
Hide file tree
Showing 24 changed files with 742 additions and 6 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,6 @@ public_html/wp-content/themes/twentytwentyfour
public_html/wp-content/themes/wporg-parent-2021
public_html/wp-content/themes/wporg-events-2023/style.css
public_html/wp-content/themes/wporg-events-2023/editor.css
public_html/wp-content/themes/wporg-flagship-landing/style.css
public_html/wp-content/themes/wporg-flagship-landing/editor.css
public_html/wp-content/fonts
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
"public_html/wp-content/plugins/wcpt",
"public_html/wp-content/plugins/wordcamp-forms-to-drafts",
"public_html/wp-content/plugins/wordcamp-speaker-feedback",
"public_html/wp-content/themes/wporg-events-2023"
"public_html/wp-content/themes/wporg-events-2023",
"public_html/wp-content/themes/wporg-flagship-landing"
],
"browserslist": [
"extends @wordpress/browserslist-config"
Expand Down
7 changes: 4 additions & 3 deletions public_html/wp-content/mu-plugins/load-other-mu-plugins.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ function wcorg_include_common_plugins() {
require_once dirname( __DIR__ ) . '/mu-plugins-private/wporg-mu-plugins.php';
}

// Include the public `wporg-mu-plugins` that are synced from Git to SVN. These are different than the
// ones included in `wcorg_include_common_plugins()`.
require_once dirname( __DIR__ ) . '/mu-plugins-private/wporg-mu-plugins/pub-sync/loader.php';

wcorg_include_individual_mu_plugins();
wcorg_include_mu_plugin_folders();
}
Expand All @@ -27,9 +31,6 @@ function wcorg_include_network_only_plugins() {
if ( EVENTS_NETWORK_ID === SITE_ID_CURRENT_SITE ) {
$network_folder = 'events';

// Include the public `wporg-mu-plugins` that are synced from Git to SVN. These are different than the
// ones included in `wcorg_include_common_plugins()`.
require_once dirname( __DIR__ ) . '/mu-plugins-private/wporg-mu-plugins/pub-sync/loader.php';
} else {
$network_folder = 'wordcamp';
}
Expand Down
108 changes: 106 additions & 2 deletions public_html/wp-content/sunrise-wordcamp.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<?php

namespace WordCamp\Sunrise;
use WP_Network, WP_Site;
use WordCamp_Loader;

defined( 'WPINC' ) || die();

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

/*
* @todo enable this when design is implemented.
if ( is_flagship_landing_url( $domain, $path ) ) {
if ( setup_flagship_landing_site( $domain ) ) {
return;
}
}
*/

redirect_to_site( $domain, $path );
}

/**
* Show the flagship landing page.
*/
function setup_flagship_landing_site( string $domain ): bool {
$latest_site = get_latest_site( $domain );

if ( ! $latest_site ) {
return false;
}

set_network_and_site( $latest_site );

remove_action( 'template_redirect', 'redirect_canonical' );

add_filter(
'template',
function (): string {
return 'wporg-parent-2021';
}
);

add_filter(
'stylesheet',
function (): string {
return 'wporg-flagship-landing';
}
);

add_filter(
'option_wccsp_settings',
function ( array $settings ): array {
$settings['enabled'] = 'off';

return $settings;
}
);

return true;
}

/**
* Set the current network and site when given a site.
*
* phpcs:disable WordPress.WP.GlobalVariablesOverride.Prohibited -- WP is designed in a way that requires this.
* Setting these vars is what `sunrise.php` is designed to do.
*/
function set_network_and_site( object $site ) {
global $current_site, $current_blog, $blog_id, $site_id, $domain, $path, $public;

// Originally WP referred to networks as "sites" and sites as "blogs".
$current_site = WP_Network::get_instance( WORDCAMP_NETWORK_ID );
$site_id = $current_site->id;
$path = stripslashes( $_SERVER['REQUEST_URI'] );
$current_blog = WP_Site::get_instance( $site->blog_id );

$blog_id = $current_blog->id;
$domain = $current_blog->domain;
$public = $current_blog->public;
}

/**
* Redirect requests to the correct site.
*/
function redirect_to_site( string $domain, string $path ): void {
add_action( 'template_redirect', __NAMESPACE__ . '\redirect_duplicate_year_permalinks_to_post_slug' );

$status_code = 301;
Expand Down Expand Up @@ -131,6 +210,20 @@ function guess_requested_domain_path() {
);
}

/**
* Check if the given domain/path is a flagship landing page.
*/
function is_flagship_landing_url( string $domain, string $path ): bool {
$flagship_events = array( 'asia', 'centroamerica', 'europe', 'us' );
$third_level_domain = explode( '.', $domain )[0];

if ( in_array( $third_level_domain, $flagship_events ) && '/' === $path ) {
return true;
}

return false;
}

/**
* Redirect root site front-end requests to Central.
*
Expand Down Expand Up @@ -528,8 +621,19 @@ function get_canonical_year_url( $domain, $path ) {
break;
}

$latest = get_latest_site( $domain );

return $latest ? 'https://' . $latest->domain . $latest->path : false;
}

/**
* Get the latest site for a given city.
*/
function get_latest_site( string $domain ) {
global $wpdb;

$latest = $wpdb->get_row( $wpdb->prepare( "
SELECT `domain`, `path`
SELECT `blog_id`, `domain`, `path`
FROM $wpdb->blogs
WHERE
( domain = %s AND path != '/' ) OR -- Match city/year format.
Expand All @@ -540,7 +644,7 @@ function get_canonical_year_url( $domain, $path ) {
"%.{$domain}"
) );

return $latest ? 'https://' . $latest->domain . $latest->path : false;
return $latest;
}

/**
Expand Down
18 changes: 18 additions & 0 deletions public_html/wp-content/themes/wporg-flagship-landing/.stylelintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"extends": "@wordpress/stylelint-config",
"rules": {
"max-line-length": null,
"no-duplicate-selectors": null,
"no-descending-specificity": null,
"rule-empty-line-before": [
"always-multi-line",
{
"except": [
"first-nested",
"after-single-line-comment"
]
}
],
"selector-class-pattern": null
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# wporg-flagship-landing

You must run the `build` task for this to be recognized as a valid theme by WP.
Loading

0 comments on commit 13c002d

Please sign in to comment.