Following up on the previous post where I defined the vision for v0.2.0, integrating a “Save to GitHub” feature, today was all about building the necessary foundation, both in the plugin’s code and in my own development environment.
1. Solidifying the Local Workflow
Before diving into the new feature, I addressed a critical fragility in my local Docker setup. My previous configuration, managing multiple WordPress sites in a single docker-compose.yml file, had already led to accidental data loss.
Today, I refactored the environment completely:
- Each project (
oneoffboss,) now lives in its own directory with a dedicatedwp-dev-habitdocker-compose.yml. *Renamed to daily-devhabit - Named volumes ensure database and file isolation for each site.
- Daily automated backups (
mysqldumpvia cron) are now running for added redundancy.
This isolated setup is crucial for safely developing and testing the new plugin features locally.
2. Building the Backend for v0.2.0
With the local environment stable, I focused on the PHP backend for the GitHub integration:
- Settings Page: I used the WordPress Settings API to create a new “Settings” submenu under “Daily Dev Habit.” This page securely saves the user’s GitHub Personal Access Token (PAT), username, target repository, and default file path.
- AJAX Handler: I built the core PHP function (
devhabit_ajax_save_log_to_github) that handles the request from the plugin’s interface. This function verifies security (nonce, user capability), retrieves the saved settings, formats the log content, and useswp_remote_requestto make an authenticated PUT request to the GitHub API, creating the log file in the specified repository.
3. Updating the Frontend (JavaScript & CSS)
Finally, I updated the plugin’s user interface (admin.js and admin.css):
- A new “Save to GitHub” button was added to the results screen.
- JavaScript logic was added to:
- Send the log content via AJAX to the new PHP handler using
fetch. - Display status messages (“Saving…”, “Success!”, “Error…”) to the user.
- Handle responses and potential errors from the GitHub API call.
- Send the log content via AJAX to the new PHP handler using
- The interactive demo page (
/demo/) was updated with simulated versions of these new UI elements and functions.
Next Steps
The core code for the GitHub integration (v0.2.0) is now in place. The immediate next step is thorough testing of the “Save to GitHub” feature in the local environment against a real GitHub repository. After confirming it works reliably, I can deploy this updated version to the live dailydevhabit.com site and finally install it on oneoffboss.com to begin dogfooding it for real-world documentation.