Add API to get events#1108
Open
cjyabraham wants to merge 5 commits into
Open
Conversation
Signed-off-by: Chris Abraham <cjyabraham@gmail.com>
There was a problem hiding this comment.
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_APIclass registering/lfevents/v1/eventswith parameter validation and meta-query–based status filtering. - Existing
LFEventsplugin class wires up the API file include and therest_api_initaction.
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; |
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>
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>
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 ), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
See issue #1107 and #1114
get_events API Quick Reference
Endpoint
GET /wp-json/lfevents/v1/eventsQuery Params
status(optional):upcoming(default),past,alls(optional): free-text search on event title onlyWhat You Get
200 OKwith a JSON array of events{ "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
upcomingandall: earliest start date firstpast: latest start date firsturlisexternal_urlwhen set; otherwise it falls back to the event permalink.Example calls on dev site: