get_events example


function wp_ajax_get_community_events() {
    require_once ABSPATH . 'wp-admin/includes/class-wp-community-events.php';

    check_ajax_referer( 'community_events' );

    $search         = isset( $_POST['location'] ) ? wp_unslash( $_POST['location'] ) : '';
    $timezone       = isset( $_POST['timezone'] ) ? wp_unslash( $_POST['timezone'] ) : '';
    $user_id        = get_current_user_id();
    $saved_location = get_user_option( 'community-events-location', $user_id );
    $events_client  = new WP_Community_Events( $user_id$saved_location );
    $events         = $events_client->get_events( $search$timezone );
    $ip_changed     = false;

    if ( is_wp_error( $events ) ) {
        wp_send_json_error(
            array(
                'error' => $events->get_error_message(),
            )
        );
    } else {
        if ( empty( $saved_location['ip'] ) && ! empty( $events['location']['ip'] ) ) {
            $ip_changed = true;
        }
Home | Imprint | This part of the site doesn't use cookies.