WordPress.org

Make WordPress Core


Ignore:
Timestamp:
05/10/2017 08:03:01 PM (13 months ago)
Author:
azaozz
Message:

Dashboard: Update the existing WordPress News dashboard widget to also include upcoming meetup events and WordCamps near the current user’s location.

Props @afercia, @andreamiddleton, @azaozz, @camikaos, @coreymckrill, @chanthaboune, @courtneypk, @dd32, @iandunn, @iseulde, @mapk, @mayukojpn, @melchoyce, @nao, @obenland, @pento, @samuelsidler, @stephdau, @tellyworth.
See #40702.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/ajax-actions.php

    r40476 r40607  
    295295
    296296    wp_die( wp_json_encode( $return ) );
     297}
     298
     299/**
     300 * Handles AJAX requests for community events
     301 *
     302 * @since 4.8.0
     303 */
     304function wp_ajax_get_community_events() {
     305    require_once( ABSPATH . 'wp-admin/includes/class-wp-community-events.php' );
     306
     307    check_ajax_referer( 'community_events' );
     308
     309    $search         = isset( $_POST['location'] ) ? wp_unslash( $_POST['location'] ) : '';
     310    $timezone       = isset( $_POST['timezone'] ) ? wp_unslash( $_POST['timezone'] ) : '';
     311    $user_id        = get_current_user_id();
     312    $saved_location = get_user_option( 'community-events-location', $user_id );
     313    $events_client  = new WP_Community_Events( $user_id, $saved_location );
     314    $events         = $events_client->get_events( $search, $timezone );
     315
     316    if ( is_wp_error( $events ) ) {
     317        wp_send_json_error( array(
     318            'error' => $events->get_error_message(),
     319        ) );
     320    } else {
     321        if ( isset( $events['location'] ) ) {
     322            // Send only the data that the client will use.
     323            $events['location'] = $events['location']['description'];
     324
     325            // Store the location network-wide, so the user doesn't have to set it on each site.
     326            update_user_option( $user_id, 'community-events-location', $events['location'], true );
     327        }
     328
     329        wp_send_json_success( $events );
     330    }
    297331}
    298332
Note: See TracChangeset for help on using the changeset viewer.