Skip to content

Add API to get events#1108

Open
cjyabraham wants to merge 3 commits into
mainfrom
api
Open

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

Conversation

@cjyabraham
Copy link
Copy Markdown
Collaborator

@cjyabraham cjyabraham commented May 17, 2026

See issue #1107
Call url: /wp-json/lfevents/v1/events?s=<text>&status=upcoming|past|all

Example 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:

 {
    "id": 278373,
    "name": "Open Source Summit North America",
    "start_date": "2026/05/18",
    "end_date": "2026/05/20",
    "location": {
      "city": "Minneapolis",
      "country": "United States",
      "virtual": false
    },
    "url": "https://pr-1108-lfeventsci.pantheonsite.io/open-source-summit-north-america/",
    "menu_background_color": "#325560",
    "menu_gradient_color": "#003942",
    "menu_dropdown_color": "#003942"
  }

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
Copy link
Copy Markdown

Copilot AI left a comment

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
Copy link
Copy Markdown

Copilot AI left a comment

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 ),
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