Add API to get events#1108
Open
cjyabraham wants to merge 3 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 ), |
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
Call url:
/wp-json/lfevents/v1/events?s=<text>&status=upcoming|past|allExample calls on dev site:
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 for colors.
Example response: