Making WordPress.org


Ignore:
Timestamp:
01/04/2021 11:41:06 PM (5 years ago)
Author:
iandunn
Message:

Events: Pin online WordCamps for their entire country.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/api.wordpress.org/public_html/events/1.0/index.php

    r10548 r10549  
    235235        );
    236236
    237         $events = pin_next_online_wordcamp( $events, $_SERVER['HTTP_USER_AGENT'], time() );
     237        $events = pin_next_online_wordcamp( $events, $_SERVER['HTTP_USER_AGENT'], time(), $location['country'] ?? '' );
    238238        $events = pin_next_workshop_discussion_group( $events, $_SERVER['HTTP_USER_AGENT'] );
    239239        $events = pin_one_off_events( $events, time() );
     
    13551355 * @param string $user_agent
    13561356 * @param int    $current_time
     1357 * @param string $user_country
    13571358 *
    13581359 * @return array
    13591360 */
    1360 function pin_next_online_wordcamp( $events, $user_agent, $current_time ) {
     1361function pin_next_online_wordcamp( $events, $user_agent, $current_time, $user_country ) {
    13611362    global $wpdb, $cache_group, $cache_life;
    13621363
     
    13821383                status   = 'scheduled' AND
    13831384                location = 'online'    AND
    1384                 date_utc BETWEEN CURDATE() AND CURDATE() + INTERVAL 2 WEEK
     1385                date_utc BETWEEN CURDATE() AND CURDATE() + INTERVAL 1 MONTH
    13851386            ORDER BY `date_utc` ASC
    13861387            LIMIT 1"
     
    14291430
    14301431    if ( isset( $next_online_camp['url'] ) ) {
    1431         array_unshift( $events, $next_online_camp );
     1432        $camp_is_in_users_country = $user_country === $next_online_camp['location']['country'];
     1433
     1434        $camp_is_in_next_two_weeks = is_within_date_range(
     1435            $current_time,
     1436            $next_online_camp['start_unix_timestamp'] - ( 2 * WEEK_IN_SECONDS ),
     1437            $next_online_camp['start_unix_timestamp']
     1438        );
     1439
     1440        /*
     1441         * Online WordCamps often represent the entire country, in contrast to offline camps, which are local
     1442         * events. Because of that, they should be promoted to the entire country, even if that's outside the
     1443         * normal `$event_distances['wordcamp']` range.
     1444         *
     1445         * If it's not the user's country, then 2 weeks is a good balance between promoting a
     1446         * potentially-interesting event, and crowding out local events.
     1447         */
     1448        if ( $camp_is_in_users_country || $camp_is_in_next_two_weeks ) {
     1449            array_unshift( $events, $next_online_camp );
     1450        }
    14321451    }
    14331452
Note: See TracChangeset for help on using the changeset viewer.