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

Migrate to event filters #1109

Merged
merged 2 commits into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

48 changes: 1 addition & 47 deletions public_html/wp-content/themes/wporg-events-2023/functions.php
Original file line number Diff line number Diff line change
@@ -1,59 +1,13 @@
<?php

namespace WordPressdotorg\Events_2023;
use WP;

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

require_once __DIR__ . '/blocks/events-landing-page/events-landing-page.php';
require_once __DIR__ . '/inc/city-landing-pages.php';

add_filter( 'parse_request', __NAMESPACE__ . '\add_city_landing_page_query_vars' );
add_action( 'wp_enqueue_scripts', __NAMESPACE__ . '\enqueue_assets' );
add_filter( 'wporg_block_navigation_menus', __NAMESPACE__ . '\add_site_navigation_menus' );

/**
* Override the current query vars so that the city landing page loads instead.
*/
function add_city_landing_page_query_vars( WP $wp ): void {
if ( ! wp_using_themes() || ! is_main_query() || ! is_city_landing_page() ) {
return;
}

// This assumes there's a placeholder page in the database with this slug.
$wp->set_query_var( 'page', '' );
$wp->set_query_var( 'pagename', 'city-landing-page' );
}

/**
* Determine if the current request is for a city landing page.
*
* See `get_city_landing_sites()` for examples of request URIs.
*/
function is_city_landing_page() {
global $wp, $wpdb;

// The landing page formats will always match the rewrite rule for pages, which sets `page` and `pagename`.
if ( empty( $wp->query_vars['page'] ) && empty( $wp->query_vars['pagename'] ) ) {
return false;
}

$city = explode( '/', $wp->request );
$city = $city[0] ?? false;

// Using this instead of `get_sites()` so that the search doesn't match false positives.
$sites = $wpdb->get_results( $wpdb->prepare( "
SELECT blog_id
FROM {$wpdb->blogs}
WHERE
site_id = %d AND
path REGEXP %s
LIMIT 1",
EVENTS_NETWORK_ID,
"^/$city/\d{4}/[a-z-]+/$"
) );

return ! empty( $sites );
}

/**
* Enqueue scripts and styles.
Expand Down
Loading
Loading