Weather Logger
A WordPress plugin for logging weather data with OOP architecture, REST API endpoints, and Gutenberg blocks.
by Almir Santos · github.com/almirsantos99/weather-logger · website
Install
No release zip yet. The repository archive installs, but the folder name will carry the branch suffix and updates will not flow:
wp plugin install https://github.com/almirsantos99/weather-logger/archive/refs/heads/main.zipReadme
Weather Logger Plugin
A WordPress plugin for logging weather data with OOP architecture, REST API endpoints, and Gutenberg blocks. Built with best practices including proper namespacing, secure data handling, and developer-friendly hooks for customization.
Features
- Weather Post Type — Dedicated custom post type for storing weather data with metadata (date, location, weather type)
- REST API Endpoints — Secure endpoints for fetching and saving weather data:
GET /wp-json/weather/v1/get— Retrieve weather entries with optional filteringPOST /wp-json/weather/v1/save— Save new weather entries (requires authentication)
- Gutenberg Blocks — Two dynamic blocks for front-end integration:
- Weather Form Block — AJAX-driven form for authenticated users to submit weather data
- Weather Display Block — Display and filter weather entries by date, location, and weather type
- Admin Interface — Manage weather entries in WordPress admin with custom columns and meta boxes
- Duplicate Prevention — Automatically prevents duplicate entries for the same date/location combination
- Data Validation — Validates weather types against predefined options (hail, hurricane, overcast, rain, snow, sunny, thunderstorm, tornado)
Requirements
- PHP 8.1 or higher
- WordPress 6.0 or later
- MySQL 5.7 or higher
Installation
- Download or clone this plugin into your
wp-content/plugins/directory - Activate the plugin through the WordPress admin dashboard
- The weather post type will be automatically registered
Usage
REST API — Saving Weather Data
curl -X POST https://yoursite.com/wp-json/weather/v1/save \
-H "Content-Type: application/json" \
-H "X-WP-Nonce: $(wp eval 'echo wp_create_nonce("wp_rest");')" \
--user "username:password" \
-d '{
"date": "2024-01-15",
"location": "New York",
"weather": "sunny"
}'
REST API — Fetching Weather Data
curl https://yoursite.com/wp-json/weather/v1/get?location=New%20York&date=2024-01-15
Gutenberg Blocks
- Add the Weather Form block to any page/post to allow users to submit weather data
- Add the Weather Display block to show a filterable list of weather entries
- Both blocks are configurable in the block editor
Architecture
This plugin follows Object-Oriented Programming (OOP) principles with the following structure:
src/
├── Bootstrap/ — Plugin initialization and hooks
├── Providers/ — Service providers (post type registration)
├── Controllers/ — REST API controllers
├── UseCases/ — Business logic (RegisterWeather, GetWeather)
├── Admin/ — WordPress admin customizations
│ ├── Columns/ — Custom admin columns
│ └── Post_Types/ — Post type meta boxes
└── Blocks/ — Block provider for registration
Namespace: Weather\*
Hooks for Customization
Developers can extend this plugin using WordPress hooks:
// Filter allowed weather types
apply_filters( 'weather_allowed_types', $weather_list );
// Action after weather data is saved
do_action( 'weather_saved', $post_id, $params );
// Filter REST endpoint response
apply_filters( 'weather_rest_response', $response );
Security
- All user input is sanitized using WordPress sanitization functions
- POST endpoints require user authentication (
edit_postscapability) - Nonce verification is implemented for meta box operations
- Output is properly escaped to prevent XSS vulnerabilities
Testing
The plugin includes Codeception tests. Run tests with:
composer run test:analysis
Code Quality
This plugin follows:
- WordPress Coding Standards
- PSR-4 autoloading for clean namespace organization
- OOP principles with single responsibility
- Type hints for better code clarity
- Proper documentation blocks
Compatibility
- Tested with PHP 8.1+
- Compatible with WordPress 6.0+
- Works with all modern WordPress themes
Support & Contributing
Found a bug or have a feature request? Open an issue on GitHub.
License
This plugin is open source and available under the GPL v2+ license, same as WordPress.
Changelog
Version 1.0.1
- Initial stable release
- REST API endpoints for weather data management
- Gutenberg blocks for front-end interaction
- Admin interface with custom columns and meta boxes
- Full documentation and code examples
Author: Almir Santos
Website: https://almirsantos99.com
GitHub: https://github.com/almirsantos99/weather-logger