-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Events: Show upcoming events on home page
- Loading branch information
Showing
8 changed files
with
131 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
public_html/wp-content/themes/wporg-events-2023/inc/event-getters.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
namespace WordPressdotorg\Events_2023; | ||
|
||
defined( 'WPINC' ) || die(); | ||
|
||
|
||
/** | ||
* Get a list of all upcoming events across all sites. | ||
*/ | ||
function get_all_upcoming_events(): array { | ||
global $wpdb; | ||
|
||
$events = $wpdb->get_results( ' | ||
SELECT | ||
id, `type`, title, url, meetup, location, latitude, longitude, date_utc, | ||
date_utc_offset AS tz_offset | ||
FROM `wporg_events` | ||
WHERE | ||
status = "scheduled" AND | ||
( | ||
( "wordcamp" = type AND date_utc BETWEEN NOW() AND ADDDATE( NOW(), 180 ) ) OR | ||
( "meetup" = type AND date_utc BETWEEN NOW() AND ADDDATE( NOW(), 60 ) ) | ||
) | ||
ORDER BY date_utc ASC | ||
LIMIT 400' | ||
); | ||
|
||
foreach ( $events as $event ) { | ||
// `capital_P_dangit()` won't work here because the current filter isn't `the_title` and there isn't a safelisted prefix before `$text`. | ||
$event->title = str_replace( 'Wordpress', 'WordPress', $event->title ); | ||
|
||
// `date_utc` is a misnomer, the value is actually in the local timezone of the event. So, convert to a true Unix timestamp (UTC). | ||
// Can't do this reliably in the query because MySQL converts it to the server timezone. | ||
$event->timestamp = strtotime( $event->date_utc ) - $event->tz_offset; | ||
|
||
unset( $event->date_utc ); | ||
} | ||
|
||
return $events; | ||
} |
20 changes: 20 additions & 0 deletions
20
public_html/wp-content/themes/wporg-events-2023/patterns/front-page-map.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
/** | ||
* Title: Event Map | ||
* Slug: wporg-events-2023/event-map | ||
* Inserter: no | ||
*/ | ||
|
||
namespace WordPressdotorg\Events_2023; | ||
|
||
defined( 'WPINC' ) || die(); | ||
|
||
$map_options = array( | ||
'id' => 'all-upcoming-events', | ||
'markers' => get_all_upcoming_events(), | ||
); | ||
|
||
?> | ||
|
||
<!-- wp:wporg/google-map <?php echo wp_json_encode( $map_options ); ?> /--> |
21 changes: 21 additions & 0 deletions
21
public_html/wp-content/themes/wporg-events-2023/patterns/local-navigation.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
/** | ||
* Title: Local Navigation | ||
* Slug: wporg-events-2023/local-navigation | ||
* Inserter: no | ||
* | ||
* This nav bar also has the site title, so it should be used on interior pages. | ||
*/ | ||
|
||
namespace WordPressdotorg\Events_2023; | ||
|
||
defined( 'WPINC' ) || die(); | ||
|
||
?> | ||
|
||
<!-- wp:wporg/local-navigation-bar {"backgroundColor":"charcoal-2","style":{"spacing":{"padding":{"right":"var:preset|spacing|edge-space","left":"var:preset|spacing|edge-space","top":"16px","bottom":"16px"}},"position":{"type":"sticky"},"elements":{"link":{"color":{"text":"var:preset|color|white"},":hover":{"color":{"text":"var:preset|color|white"}}}},"border":{"top":{"color":"var:preset|color|charcoal-3","style":"solid","width":"1px"},"right":{},"bottom":{},"left":{}}},"textColor":"white","fontSize":"small"} --> | ||
<!-- wp:site-title {"level":0,"fontSize":"small"} /--> | ||
|
||
<!-- wp:navigation {"ref":7206,"textColor":"white","hasIcon":false,"layout":{"type":"flex","orientation":"horizontal"},"fontSize":"small"} /--> | ||
<!-- /wp:wporg/local-navigation-bar --> |
11 changes: 11 additions & 0 deletions
11
public_html/wp-content/themes/wporg-events-2023/templates/front-page.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<!-- wp:wporg/global-header /--> | ||
|
||
<!-- wp:pattern {"slug":"wporg-events-2023/local-navigation"} /--> | ||
|
||
<!-- wp:group {"tagName":"main","className":"entry-content"} --> | ||
<main class="wp-block-group entry-content"> | ||
<!-- wp:pattern {"slug":"wporg-events-2023/event-map"} /--> | ||
</main> | ||
<!-- /wp:group --> | ||
|
||
<!-- wp:wporg/global-footer /--> |