WP_Community_Events example


    if ( $saved_ip_address && $current_ip_address && $current_ip_address !== $saved_ip_address ) {
        $saved_location['ip'] = $current_ip_address;
        update_user_meta( $user_id, 'community-events-location', $saved_location );
    }

    $events_client = new WP_Community_Events( $user_id$saved_location );

    wp_localize_script(
        'dashboard',
        'communityEventsData',
        array(
            'nonce'       => wp_create_nonce( 'community_events' ),
            'cache'       => $events_client->get_cached_events(),
            'time_format' => get_option( 'time_format' ),
        )
    );
}


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'] ) ) {
            
Home | Imprint | This part of the site doesn't use cookies.