Skip to content

Commit 9150364

Browse files
authored
Events: Ensure that online events never have a lat/lon returned, such that it defaults to the group location. (#706)
1 parent 4d2e4c4 commit 9150364

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

mu-plugins/utilities/class-meetup-client.php

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1129,26 +1129,30 @@ protected function apply_backcompat_fields( $type, $result ) {
11291129
)->getOffset();
11301130
}
11311131

1132-
// Back-compat for the old 'venue' field.
1133-
if ( ! empty( $result['venues'] ) ) {
1132+
// Remove Lat/Lon for online events.
1133+
$result['venues'] ??= [];
1134+
foreach ( $result['venues'] as &$venue ) {
1135+
if ( is_numeric( $venue['id'] ) ) {
1136+
$venue['id'] = (int) $venue['id'];
1137+
}
1138+
1139+
if ( self::ONLINE_VENUE_ID === $venue['id'] ) {
1140+
$venue['lat'] = '';
1141+
$venue['lon'] = '';
1142+
} elseif ( empty( $result['venue'] ) ) {
1143+
// Default to first non-online venue if there's multiple.
1144+
$result['venue'] = $venue;
1145+
}
1146+
}
1147+
1148+
// If we didn't find a venue above, but there's venues, use the first one even if online.
1149+
if ( empty( $result['venue'] ) && ! empty( $result['venues'] ) ) {
11341150
$result['venue'] = $result['venues'][0];
11351151
}
11361152

11371153
if ( ! empty( $result['venue'] ) ) {
1138-
if ( is_numeric( $result['venue']['id'] ) ) {
1139-
$result['venue']['id'] = (int) $result['venue']['id'];
1140-
}
1141-
11421154
$result['venue']['localized_location'] = $this->localise_location( $result['venue'] );
11431155
$result['venue']['localized_country_name'] = $this->localised_country_name( $result['venue']['country'] );
1144-
1145-
// For online events, disregard the Venue lat/lon. It's not correct. In back-compat methods to allow for BC for existing uses of the class.
1146-
if ( ! empty( $result['venue']['lng'] ) && self::ONLINE_VENUE_ID == $result['venue']['id'] ) {
1147-
$result['venue']['lat'] = '';
1148-
$result['venue']['lng'] = '';
1149-
}
1150-
1151-
$result['venue']['lon'] ??= $result['venue']['lng'];
11521156
}
11531157

11541158
if ( ! empty( $result['group'] ) ) {

0 commit comments

Comments
 (0)