Skip to content

Add API to get events#1108

Open
cjyabraham wants to merge 5 commits into
mainfrom
api
Open

Add API to get events#1108
cjyabraham wants to merge 5 commits into
mainfrom
api

Conversation

@cjyabraham

@cjyabraham cjyabraham commented May 17, 2026

Copy link
Copy Markdown
Collaborator

See issue #1107 and #1114

get_events API Quick Reference

Endpoint

  • GET /wp-json/lfevents/v1/events
  • Public endpoint (no auth required)

Query Params

  • status (optional): upcoming (default), past, all
  • s (optional): free-text search on event title only

What You Get

  • 200 OK with a JSON array of events
  • Full event object shape:
{
  "id": 12345,
  "name": "Example Event",
  "description": "Event summary",
  "date_start": "2026-09-10",
  "date_end": "2026-09-12",
  "external_url": "https://events.example.org/event",
  "white_logo": "https://events.example.org/wp-content/uploads/white-logo.png",
  "black_logo": "https://events.example.org/wp-content/uploads/black-logo.png",
  "menu_color": "#0f172a",
  "menu_color_2": "#1e293b",
  "menu_color_3": "#334155",
  "menu_text_color": "#ffffff",
  "featured_image": "https://events.example.org/wp-content/uploads/hero.jpg",
  "start_date": "2026-09-10",
  "end_date": "2026-09-12",
  "location": {
    "city": "Chicago",
    "region": "IL",
    "country": "United States",
    "virtual": false
  },
  "cfp_active": true,
  "cfp_date_start": "2026-03-01",
  "cfp_date_end": "2026-04-15",
  "cta_speak_url": "https://events.example.org/cfp",
  "cta_register_url": "https://events.example.org/register",
  "cta_sponsor_url": "https://events.example.org/sponsor",
  "cta_sponsor_date_end": "2026-07-31",
  "cta_schedule_url": "https://events.example.org/schedule",
  "cta_videos_url": "https://events.example.org/videos",
  "url": "https://events.example.org/event"
}

Behavior That Matters

  • Hidden events are excluded.
  • Events missing a start date are excluded.
  • Sorting:
    • upcoming and all: earliest start date first
    • past: latest start date first
  • url is external_url when set; otherwise it falls back to the event permalink.
  • Results are not paginated (returns all matching events).
  • Note that for events that exist on the https://www.lfopensource.cn/ site, this call will list the event but won't be able to get at the meta values.

Example calls on dev site:

Signed-off-by: Chris Abraham <cjyabraham@gmail.com>
Copilot AI review requested due to automatic review settings May 17, 2026 00:29
@cjyabraham cjyabraham changed the title Add API to get events (#1107) Add API to get events May 17, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new public read-only REST API endpoint (GET /lfevents/v1/events) that lists Events with a small set of fields (id, name, dates, location, url, menu colors), supports a free-text search (s) and a status filter (upcoming/past/all). A new LFEvents_API class is loaded by the main plugin class and registered via rest_api_init.

Changes:

  • New LFEvents_API class registering /lfevents/v1/events with parameter validation and meta-query–based status filtering.
  • Existing LFEvents plugin class wires up the API file include and the rest_api_init action.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
web/wp-content/mu-plugins/custom/lfevents/includes/class-lfevents-api.php New REST API class exposing the events listing endpoint and response formatting.
web/wp-content/mu-plugins/custom/lfevents/includes/class-lfevents.php Loads the new API class and hooks register_routes into rest_api_init.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +102 to +112
$args = array(
'post_type' => $post_types,
'post_status' => 'publish',
'post_parent' => 0,
'posts_per_page' => -1,
'no_found_rows' => true,
'meta_query' => $meta_query, //phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query
'orderby' => 'meta_value',
'meta_key' => 'lfes_date_start', //phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_key
'order' => 'past' === $status ? 'DESC' : 'ASC',
);
Comment on lines +59 to +61
if ( ! in_array( $status, array( 'upcoming', 'past', 'all' ), true ) ) {
$status = 'upcoming';
}
$country_name = '';
$country_terms = get_the_terms( $post_id, 'lfevent-country' );
if ( is_array( $country_terms ) && ! empty( $country_terms ) ) {
$country_name = $country_terms[0]->name;
cjyabraham and others added 2 commits May 16, 2026 17:57
Co-authored-by: Copilot <copilot@github.com>
Signed-off-by: Chris Abraham <cjyabraham@gmail.com>
Co-authored-by: Copilot <copilot@github.com>
Signed-off-by: Chris Abraham <cjyabraham@gmail.com>
Copilot AI review requested due to automatic review settings May 17, 2026 01:07

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

Comment on lines +107 to +117
$args = array(
'post_type' => $post_types,
'post_status' => 'publish',
'post_parent' => 0,
'posts_per_page' => -1,
'no_found_rows' => true,
'meta_query' => $meta_query, //phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query
'orderby' => 'meta_value',
'meta_key' => 'lfes_date_start', //phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_key
'order' => 'past' === $status ? 'DESC' : 'ASC',
);
Comment on lines +59 to +61
if ( ! in_array( $status, array( 'upcoming', 'past', 'all' ), true ) ) {
$status = 'upcoming';
}
Comment on lines +168 to +183
$virtual = get_post_meta( $post_id, 'lfes_virtual', true );

return array(
'id' => $post_id,
'name' => html_entity_decode( get_the_title( $post ), ENT_QUOTES, 'UTF-8' ),
'start_date' => (string) get_post_meta( $post_id, 'lfes_date_start', true ),
'end_date' => (string) get_post_meta( $post_id, 'lfes_date_end', true ),
'location' => array(
'city' => (string) get_post_meta( $post_id, 'lfes_city', true ),
'country' => (string) $country_name,
'virtual' => (bool) $virtual,
),
'url' => $url,
'menu_background_color' => (string) get_post_meta( $post_id, 'lfes_menu_color', true ),
'menu_gradient_color' => (string) get_post_meta( $post_id, 'lfes_menu_color_2', true ),
'menu_dropdown_color' => (string) get_post_meta( $post_id, 'lfes_menu_color_3', true ),
Signed-off-by: Chris Abraham <cjyabraham@gmail.com>
Signed-off-by: Chris Abraham <cjyabraham@gmail.com>
Copilot AI review requested due to automatic review settings June 20, 2026 15:54

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

Comment on lines +30 to +45
'args' => array(
's' => array(
'description' => 'Free text search on event name.',
'type' => 'string',
'required' => false,
'sanitize_callback' => 'sanitize_text_field',
),
'status' => array(
'description' => 'Filter by event status.',
'type' => 'string',
'required' => false,
'default' => 'upcoming',
'enum' => array( 'upcoming', 'past', 'all' ),
'sanitize_callback' => 'sanitize_key',
),
),
Comment on lines +107 to +117
$args = array(
'post_type' => $post_types,
'post_status' => 'publish',
'post_parent' => 0,
'posts_per_page' => -1,
'no_found_rows' => true,
'meta_query' => $meta_query, //phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query
'orderby' => 'meta_value',
'meta_key' => 'lfes_date_start', //phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_key
'order' => 'past' === $status ? 'DESC' : 'ASC',
);
Comment on lines +176 to +188
'description' => (string) get_post_meta( $post_id, 'lfes_description', true ),
'date_start' => (string) get_post_meta( $post_id, 'lfes_date_start', true ),
'date_end' => (string) get_post_meta( $post_id, 'lfes_date_end', true ),
'external_url' => $external_url,
'white_logo' => $white_logo_url,
'black_logo' => $black_logo_url,
'menu_color' => (string) get_post_meta( $post_id, 'lfes_menu_color', true ),
'menu_color_2' => (string) get_post_meta( $post_id, 'lfes_menu_color_2', true ),
'menu_color_3' => (string) get_post_meta( $post_id, 'lfes_menu_color_3', true ),
'menu_text_color' => (string) get_post_meta( $post_id, 'lfes_menu_text_color', true ),
'featured_image' => $featured_image_url,
'start_date' => (string) get_post_meta( $post_id, 'lfes_date_start', true ),
'end_date' => (string) get_post_meta( $post_id, 'lfes_date_end', true ),
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants