-
Notifications
You must be signed in to change notification settings - Fork 2
Add REST API Endpoints for Events and Speakers #31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Add REST API Endpoints for Events and Speakers #31
Conversation
Added includes/class-wpfa-rest.php to encapsulate all REST API logic in a modular structure.
|
🧙 Sourcery has finished reviewing your pull request! Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR introduces REST API endpoints to the WPFA Event plugin, enabling programmatic access to speakers and events data. The implementation follows WordPress REST API standards with proper authentication, caching, and modular code structure.
Key changes:
- Created a new
WPFA_RESTclass to handle REST API routes for speakers (GET/POST) and events (GET) - Integrated transient caching (1 hour TTL) for improved performance on read operations
- Updated the plugin loader to initialize the REST API component
Reviewed Changes
Copilot reviewed 2 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| includes/class-wpfa-rest.php | New REST API handler providing endpoints for speakers and events with caching and permission controls |
| includes/class-wpfa-loader.php | Updated to load and initialize the new WPFA_REST class |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| private function get_speaker_schema() { | ||
| return [ | ||
| 'name' => [ | ||
| 'required' => true, | ||
| 'type' => 'string', | ||
| 'sanitize_callback' => 'sanitize_text_field', | ||
| ], | ||
| 'bio' => [ | ||
| 'required' => false, | ||
| 'type' => 'string', | ||
| ], | ||
| 'organization' => [ | ||
| 'required' => false, | ||
| 'type' => 'string', | ||
| ], | ||
| 'role' => [ | ||
| 'required' => false, | ||
| 'type' => 'string', | ||
| ], | ||
| 'photo_url' => [ | ||
| 'required' => false, | ||
| 'type' => 'string', | ||
| 'format' => 'uri', | ||
| ], | ||
| ]; | ||
| } |
Copilot
AI
Oct 26, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The schema defines sanitize_callback for 'name' but not for other fields. The 'bio', 'organization', and 'role' fields should also have sanitize callbacks to ensure consistent input sanitization. Add 'sanitize_callback' => 'sanitize_text_field' for 'organization' and 'role', and 'sanitize_callback' => 'sanitize_textarea_field' for 'bio'.
| 'required' => false, | ||
| 'type' => 'string', | ||
| 'format' => 'uri', |
Copilot
AI
Oct 26, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The 'photo_url' field in the schema lacks a sanitize_callback. Add 'sanitize_callback' => 'esc_url_raw' to ensure URLs are properly sanitized, matching the sanitization used in create_speaker() at line 128.
| 'required' => false, | |
| 'type' => 'string', | |
| 'format' => 'uri', | |
| 'required' => false, | |
| 'type' => 'string', | |
| 'format' => 'uri', | |
| 'sanitize_callback' => 'esc_url_raw', |
| $query = new WP_Query( | ||
| [ | ||
| 'post_type' => 'wpfa_speaker', | ||
| 'posts_per_page' => -1, | ||
| 'post_status' => 'publish', | ||
| ] | ||
| ); |
Copilot
AI
Oct 26, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using 'posts_per_page' => -1 retrieves all speakers without pagination, which could cause performance issues with a large number of speakers. Consider implementing pagination parameters in the REST endpoint or setting a reasonable upper limit to prevent memory exhaustion.
| $query = new WP_Query( | ||
| [ | ||
| 'post_type' => 'wpfa_event', | ||
| 'posts_per_page' => -1, | ||
| 'post_status' => 'publish', | ||
| ] | ||
| ); |
Copilot
AI
Oct 26, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using 'posts_per_page' => -1 retrieves all events without pagination, which could cause performance issues with a large number of events. Consider implementing pagination parameters in the REST endpoint or setting a reasonable upper limit to prevent memory exhaustion.
Added includes/class-wpfa-rest.php to encapsulate all REST API logic in a modular structure.
Summary by Sourcery
Add a new REST API component to serve event and speaker data and integrate it into the plugin initialization
New Features:
Enhancements:
Chores: