Weather Logger
The Weather Logger is a robust, object-oriented WordPress plugin designed to seamlessly log, manage, and display meteorological data. Built with modern WordPress development standards, it leverages the Gutenberg block editor, React, and custom REST API endpoints to provide a frictionless experience for both end-users and third-party developers.
by Sarfarz Kazi · github.com/sarfaraz-kazi/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/sarfaraz-kazi/weather-logger/archive/refs/heads/main.zipWeather Logger is a WordPress plugin for collecting and displaying weather entries.
It stores submissions in a custom weather post type, exposes custom REST endpoints,
and provides Gutenberg blocks for submitting and listing entries.
Features
- Registers a private
weathercustom post type with an admin UI. - Provides a
weather/formblock for submitting weather entries. - Provides a
weather/listblock for rendering saved entries. - Saves and retrieves entries through custom REST API routes.
- Loads a simple frontend script for Ajax form submission and list refresh.
- Displays a current forecast panel sourced from
api.weather.gov.
Requirements
- PHP 8.1+
- WordPress
- Composer for installing development dependencies and generating
vendor/autoload.php
Installation
- Copy this plugin into your WordPress plugins directory, for example:
wp-content/plugins/weather-logger
- Install dependencies:
composer install
- Activate the plugin from the WordPress admin.
How It Works
Data Storage
Weather entries are stored as weather posts with the following post meta:
datelocationweather
When a new entry is submitted for the same date and location, the plugin updates the existing record instead of creating a duplicate.
Gutenberg Blocks
The plugin registers two server-rendered blocks:
weather/form- Renders the frontend submission form.
- Supports a
requireLoginattribute. - Defaults to requiring a logged-in user for form access.
weather/list- Renders a list of saved weather entries.
- Supports
location,date_from, anddate_toattributes. - Includes a refresh button that reloads entries through the REST API.
Frontend Behavior
The form submits data asynchronously to the REST API using the localized endpoints in
src/assets/js/weather.js. The rendered form also shows:
- A "Current Weather in Monowi, Nebraska" section fetched from
https://api.weather.gov/gridpoints/TOP/31,80/forecast - A list of recent submissions
REST API
Namespace: weather/v1
POST /wp-json/weather/v1/save
Creates or updates a weather entry.
- Authentication: required
- Permission check: user must have
edit_posts - Required fields:
datelocationweather
Example:
curl -X POST http://example.com/wp-json/weather/v1/save \
-H "X-WP-Nonce: <nonce>" \
-d "date=2026-05-11" \
-d "location=Chicago" \
-d "weather=rain"
GET /wp-json/weather/v1/get
Returns weather entries.
- Authentication: public
- Query parameters:
date_fromdate_tolocationpageper_page
Example:
curl "http://example.com/wp-json/weather/v1/get?location=Chicago&per_page=5"
Response shape:
{
"dates": [
{
"date": "2026-05-11",
"location": "Chicago",
"weather": "rain"
}
]
}
GET /wp-json/weather/v1/group
Returns all saved entries grouped by date.
- Authentication: public
Example:
curl "http://example.com/wp-json/weather/v1/group"
Development
Project Layout
weather-logger/
├── docs/
├── src/
│ ├── admin-views/
│ ├── assets/
│ │ ├── css/
│ │ └── js/
│ ├── views/
│ └── Weather/
│ ├── Endpoints/
│ ├── REST/
│ ├── Assets.php
│ ├── Blocks.php
│ ├── Current_Weather.php
│ ├── Plugin.php
│ └── Post_Type.php
├── tests/
├── composer.json
├── phpstan.neon.dist
├── readme.md
└── weather.php
Useful Commands
Install dependencies:
composer install
Run static analysis:
composer run test:analysis
Testing
The repository includes Codeception/wp-browser test scaffolding under tests/.
The current test suite covers plugin bootstrap and REST route registration.
The wpunit suite expects WordPress test environment variables, including:
WP_ROOT_FOLDERWP_TEST_DB_NAMEWP_TEST_DB_HOSTWP_TEST_DB_USERWP_TEST_DB_PASSWORDWP_TABLE_PREFIXWP_DOMAIN
Notes
- The main plugin file is
weather.php. - Composer autoloading maps the
Weather\\namespace tosrc/Weather/. - The current weather panel uses a hard-coded Weather.gov forecast endpoint.