Deletion Handling
When posts are deleted from the WordPress dashboard, the plugin automatically manages the corresponding .md files and _index.json entries to keep everything in sync.
Supported Actions
| WordPress Action | Plugin Response |
|---|---|
| Trash a post | Deletes .md file, removes from _index.json, commits + pushes to Git |
| Permanently delete | Deletes .md file, removes from _index.json, commits + pushes to Git |
| Untrash (restore) | Re-exports the .md file, re-adds to _index.json, commits + pushes to Git |
How It Works
Trashing a Post
When a post is moved to trash:
- The AutoExporter's
wp_trash_posthook fires - Locates the corresponding
.mdfile by slug - Deletes the
.mdfile from the content directory - Calls
IndexManager::remove()to update_index.json - Stages the deletion with
git add -A(which stages file removals) - Commits with message:
Deleted: {post_slug} - Pushes to the configured Git remote
Permanent Deletion
Same flow as trashing — the before_delete_post hook fires and handles cleanup.
Restoring from Trash
When a post is restored:
- The AutoExporter's
untrash_posthook fires - Re-exports the post content to a new
.mdfile - Calls
IndexManager::addOrUpdate()to re-add to_index.json - Commits and pushes to Git
Git Staging
The plugin uses git add -A instead of git add . to ensure:
- File additions are staged ✅
- File modifications are staged ✅
- File deletions are staged ✅
This was a critical fix — previously, deletions were not staged because git add . only handles additions and modifications.
Deletion from Git Side
When a .md file is deleted via Git (and pushed/webhook triggers a pull):
- SyncManager runs
git pull - Parses
git diff --name-statusoutput - Detects
D(Deleted) status for the file - Calls
IndexManager::remove()to update_index.json - The post is no longer served on the frontend
Safety
- No database changes: Deletion only affects
.mdfiles and_index.json - Git history: All deletions are tracked in Git history and can be reverted
- Concurrency safe:
flock()prevents index corruption during parallel deletions