Install
This is the repository archive. It installs, but the folder name will carry the branch suffix and updates will not flow.
Install straight from GitHub with WP-CLI:
wp plugin install https://github.com/heimer79/courses-grid-reporter/archive/refs/heads/main.zipNo built-in updater. New versions won't appear under Dashboard → Updates. Install new releases yourself, or let Git Updater track the repository.
Example block scaffolded with Create Block tool.
Description
Courses Grid Reporter Block Documentation
Overview
The Courses Grid Reporter is a custom WordPress block that fetches and displays a grid of courses from a specified API endpoint. It also provides functionality to generate and email a report about the available courses.
Block Structure
The block is composed of several key files:
block.json: Configuration file for the block.index.js: Contains the edit component for the Gutenberg editor.render.php: Handles the server-side rendering of the block on the frontend.view.js: Manages frontend interactivity.style.css: Defines styles for the block.
Key Features
- Dynamic course data fetching from a configurable API endpoint.
- Tabular display of course information.
- Report generation and email functionality.
- Configurable email address for receiving reports.
Technical Explanation
Data Fetching
- The block uses the WordPress REST API to fetch course data from a specified endpoint.
- In the editor, data is fetched using JavaScript's
fetchAPI, proxied through WordPress to avoid CORS issues. - On the frontend, PHP's
wp_remote_get()function is used to retrieve the data.
Rendering
- Editor: React is used to render a preview of the block in the Gutenberg editor.
- Frontend: PHP generates the HTML structure for the course grid table.
Report Generation
- A "Generate Report" button triggers the report generation process.
- An AJAX request is sent to a custom WordPress action (
send_courses_report). - The PHP function
send_courses_report()processes the request and sends an email usingwp_mail().
Block Attributes
endpointUrl: Stores the API endpoint URL for fetching course data.reportEmail: Stores the email address for sending reports.
Editor Interface
- The block's edit component (
CoursesGridEditinindex.js) provides UI for configuring the endpoint URL and report email. - It also displays a preview of the fetched data and the report generation button.
Styling
- Tailwind CSS classes are used for styling the block in both the editor and frontend.
- Additional custom styles can be added in
style.css.
Usage
- Add the "Courses Grid Reporter" block to a page or post.
- Configure the API endpoint URL in the block settings.
- Set the email address for receiving reports.
- The course data will automatically load and display in a table format.
- Users can click the "Generate Report" button to send a report to the specified email.
Development Considerations
- Error handling is implemented for API failures and email sending issues.
- The block uses WordPress coding standards and best practices for security (e.g., data escaping, nonce verification for AJAX calls).
- The block is designed to be responsive and should work well on various screen sizes.
Future Enhancements
- Implement pagination for large datasets.
- Add sorting and filtering options for the course table.
- Expand report customization options.