Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setup Pilot Events network and URL support #907

Merged
merged 9 commits into from Jun 21, 2023
1 change: 1 addition & 0 deletions .docker/config/nginx.conf
Expand Up @@ -52,6 +52,7 @@ server {
if ( $host = "events.wordpress.test" ) {
rewrite "/[\w-]+/\d{4}/[\w-]+/wp-(admin|content|includes)(.*)" /wp-$1$2 last;
rewrite "/[\w-]+/\d{4}/[\w-]+/wp-(.*).php(.*)" /wp-$1.php$2 last;
rewrite "/[\w-]+/\d{4}/[\w-]+/xmlrpc\.php" /xmlrpc.php last;
}

location ~* /wp-content/.*\.(js|css|png|jpg|jpeg|gif|ico|svg|woff|ttf)$ {
Expand Down
10 changes: 6 additions & 4 deletions .docker/wp-config.php
Expand Up @@ -38,13 +38,15 @@
/*
* Multisite
*/
const WORDCAMP_NETWORK_ID = 1;
const WORDCAMP_ROOT_BLOG_ID = 5;
const EVENTS_NETWORK_ID = 2;
const EVENTS_ROOT_BLOG_ID = 47;

switch ( $_SERVER['HTTP_HOST'] ) {
case 'events.wordpress.test':
define( 'SITE_ID_CURRENT_SITE', 2 );
define( 'BLOG_ID_CURRENT_SITE', EVENTS_ROOT_BLOG_ID ); // events.wordpress.test.
define( 'SITE_ID_CURRENT_SITE', EVENTS_NETWORK_ID );
define( 'BLOG_ID_CURRENT_SITE', EVENTS_ROOT_BLOG_ID );
define( 'DOMAIN_CURRENT_SITE', 'events.wordpress.test' );
define( 'SUBDOMAIN_INSTALL', false );
define( 'NOBLOGREDIRECT', 'https://events.wordpress.test' );
Expand All @@ -54,8 +56,8 @@
case 'wordcamp.test':
case 'buddycamp.test':
default:
define( 'SITE_ID_CURRENT_SITE', 1 );
define( 'BLOG_ID_CURRENT_SITE', WORDCAMP_ROOT_BLOG_ID ); // central.wordcamp.test.
define( 'SITE_ID_CURRENT_SITE', WORDCAMP_NETWORK_ID );
define( 'BLOG_ID_CURRENT_SITE', WORDCAMP_ROOT_BLOG_ID );
define( 'DOMAIN_CURRENT_SITE', 'buddycamp.test' === $_SERVER['HTTP_HOST'] ? 'buddycamp.test' : 'wordcamp.test' );
define( 'SUBDOMAIN_INSTALL', true );
define( 'NOBLOGREDIRECT', 'https://central.wordcamp.test' );
Expand Down
1 change: 1 addition & 0 deletions phpcs.xml.dist
Expand Up @@ -78,6 +78,7 @@
<!-- Exclude 3rd-party files -->
<exclude-pattern>*/vendor/*</exclude-pattern>
<exclude-pattern>*/node_modules/*</exclude-pattern>
<exclude-pattern>./public_html/mu/*</exclude-pattern>

<!-- Scan all (php) files in the current folder and subfolders -->
<file>.</file>
Expand Down
6 changes: 6 additions & 0 deletions phpunit-bootstrap.php
Expand Up @@ -5,6 +5,12 @@
require_once __DIR__ . '/vendor/autoload.php';
}

const WORDCAMP_NETWORK_ID = 1;
const WORDCAMP_ROOT_BLOG_ID = 5;
const EVENTS_NETWORK_ID = 2;
const EVENTS_ROOT_BLOG_ID = 47;
const SITE_ID_CURRENT_SITE = WORDCAMP_NETWORK_ID;

define( 'WP_PLUGIN_DIR', __DIR__ . '/public_html/wp-content/plugins' );
define( 'SUT_WPMU_PLUGIN_DIR', __DIR__ . '/public_html/wp-content/mu-plugins' ); // WPMU_PLUGIN_DIR will be in `WP_TESTS_DIR`.

Expand Down
8 changes: 7 additions & 1 deletion public_html/wp-content/mu-plugins/latest-site-hints.php
Expand Up @@ -2,11 +2,17 @@

namespace WordCamp\Latest_Site_Hints;
use function WordCamp\Sunrise\get_top_level_domain;

use const WordCamp\Sunrise\{ PATTERN_YEAR_DOT_CITY_DOMAIN_PATH, PATTERN_CITY_SLASH_YEAR_DOMAIN_PATH };

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

if ( EVENTS_NETWORK_ID === SITE_ID_CURRENT_SITE ) {
// @todo Remove this once https://github.com/WordPress/wordcamp.org/issues/906 is fixed.
// If it's needed on the Events network, the constants above will need to be moved to `sunrise.php`, or
// defined in `sunrise-events.php` with a pattern designed for Events sites.
return;
}

// Hook in before `WordPressdotorg\SEO\Canonical::rel_canonical_link()`, so that callback can be removed.
add_action( 'wp_head', __NAMESPACE__ . '\canonical_link_past_home_pages_to_current_year', 9 );

Expand Down
2 changes: 1 addition & 1 deletion public_html/wp-content/mu-plugins/lets-encrypt-helper.php
Expand Up @@ -53,7 +53,7 @@ public static function get_domains() {
`public` = 1 AND
`deleted` = 0
ORDER BY `blog_id` ASC",
1
WORDCAMP_NETWORK_ID
),
ARRAY_A
);
Expand Down
6 changes: 6 additions & 0 deletions public_html/wp-content/mu-plugins/load-other-mu-plugins.php
Expand Up @@ -2,6 +2,12 @@

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

if ( EVENTS_NETWORK_ID === SITE_ID_CURRENT_SITE ) {
// @todo Remove this once https://github.com/WordPress/wordcamp.org/issues/906 is fixed.
// In the meantime it causes problems because of switch_to_blog().
return;
}

wcorg_include_individual_mu_plugins();
wcorg_include_mu_plugin_folders();

Expand Down
63 changes: 63 additions & 0 deletions public_html/wp-content/sunrise-events.php
@@ -0,0 +1,63 @@
<?php

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

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

/*
* Matches URLs of regular sites, but not the root site.
*
* For example, `events.wordpress.org/vancouver/2023/diversity-day/`.
*
*/
const PATTERN_EVENT_SITE = '
@ ^
/
( [\w-]+ ) # Capture the city.
/
( \d{4} ) # Capture the year.
/
( [\w-]+ ) # Capture the event type.
/?
@ix
';

set_network_and_site();


/**
* Determine the current network and site.
*
* This is needed to achieve the `events.wordpress.org/{year}/{event-type}{city}` URL structure.
*
* @see https://paulund.co.uk/wordpress-multisite-with-nested-folder-paths
*
* phpcs:disable WordPress.WP.GlobalVariablesOverride.Prohibited -- WP is designed in a way that requires this.
* That's the whole point of `sunrise.php`.
*/
function set_network_and_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( EVENTS_NETWORK_ID );
$site_id = $current_site->id;
$path = stripslashes( $_SERVER['REQUEST_URI'] );

if ( 1 === preg_match( PATTERN_EVENT_SITE, $path ) ) {
if ( is_admin() ) {
$path = preg_replace( '#(.*)/wp-admin/.*#', '$1/', $path );
}

list( $path ) = explode( '?', $path );

$current_blog = get_site_by_path( DOMAIN_CURRENT_SITE, $path, 3 );

} else {
$current_blog = WP_Site::get_instance( EVENTS_ROOT_BLOG_ID );
}

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