WP Drive and Maintenance Toolkit
A WordPress plugin that integrates Google Drive with a modern, React-powered admin interface and provides automated content maintenance through background post scanning, WP-CLI commands, and Action Scheduler tasks. Built with PSR-4 autoloading, Composer, secure REST APIs, and a fully testable architecture.
by Muhammad Hafee Imran · github.com/muhammad-hafee-imran/wp-drive-and-maintenance-toolkit
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/muhammad-hafee-imran/wp-drive-and-maintenance-toolkit/archive/refs/heads/main.zipA WordPress plugin focused on asynchronous background processing, external API integration, and maintainable admin tooling, implemented using modern WordPress engineering practices.
Design Goals
This plugin is structured to reflect production-grade WordPress development practices:
- Clear separation of concerns across PHP, REST, and React layers
- Explicit handling of asynchronous workflows using Action Scheduler
- Dependency isolation to avoid conflicts in shared plugin environments
- Maintainable architecture optimized for long-lived systems rather than short-term demos
Features
- Google Drive Integration: OAuth 2.0 authentication with secure file upload, download, and folder management
- Posts Maintenance: Automated background scanning of posts and pages with Action Scheduler
- React Admin Interface: Modern React-based admin UI using WordPress Scripts and Components
- WP-CLI Support: Command-line interface for running maintenance scans
- Background Processing: Asynchronous task processing via Action Scheduler
- Dependency Isolation: PHP Scoper for vendor dependency isolation
- PSR-4 Autoloading: Modern PHP structure with Composer autoloading
Requirements
- WordPress 6.1 or higher
- PHP 7.4 or higher
- Node.js 14+ and npm (for development)
- Composer (for PHP dependencies)
Installation
For End Users
- Download or clone this repository
- Upload the plugin folder to
/wp-content/plugins/ - Activate the plugin through the WordPress admin panel
- Navigate to Google Drive Test or Posts Maintenance in the admin menu
For Developers
-
Clone the repository:
git clone <repository-url> cd wp-drive-and-maintenance-toolkit -
Install PHP dependencies:
composer install -
Install Node.js dependencies:
npm install -
Build the plugin assets:
npm run build
Development
Available Commands
NPM Scripts
| Command | Description |
|---|---|
npm install |
Install Node.js dependencies |
npm run build |
Build production-ready assets (compiles React, SCSS, and outputs to /build/) |
npm run start |
Start development mode with watch (recompiles on file changes) |
npm run translate |
Generate translation template file (languages/hafee-utility-plugin.pot) |
npm run package |
Create a distributable zip file (builds assets, optimizes Composer, creates zip) |
Composer Scripts
| Command | Description |
|---|---|
composer install |
Install PHP dependencies |
composer build |
Build plugin (runs npm run build and PHP Scoper) |
composer test |
Run PHPUnit tests |
Development Workflow
-
Start development mode:
npm run startThis watches for changes and automatically recompiles assets.
-
Make your changes to files in
src/ -
Build for production:
npm run build -
Run tests:
composer test
Project Structure
wp-drive-and-maintenance-toolkit/
├── src/ # Source code
│ ├── App/ # Application classes
│ │ └── AdminPages/ # Admin page controllers
│ ├── CLI/ # WP-CLI commands
│ ├── Encryption/ # Encryption utilities
│ ├── Endpoints/ # REST API endpoints
│ │ └── V1/ # API version 1
│ ├── React/ # React components and UI
│ │ ├── google-drive-ui/ # Google Drive interface
│ │ └── posts-maintenance-ui/ # Posts maintenance interface
│ ├── Base.php # Base class
│ ├── Loader.php # Plugin loader
│ └── Singleton.php # Singleton pattern
├── tests/ # PHPUnit tests
├── languages/ # Translation files
├── build/ # Compiled assets (generated)
├── vendor/ # Composer dependencies (generated)
├── wp-drive-maintenance-toolkit.php # Main plugin file
├── composer.json # PHP dependencies
├── package.json # Node.js dependencies
└── webpack.config.js # Webpack configuration
Usage
Google Drive Integration
- Navigate to Google Drive Test in WordPress admin
- Enter your Google Cloud Console OAuth credentials (Client ID and Client Secret)
- Click Authenticate with Google Drive
- Once authenticated, you can:
- Upload files to Google Drive
- Download files from Google Drive
- Create folders
- View and manage your Drive files
Posts Maintenance
- Navigate to Posts Maintenance in WordPress admin
- Select content type (Posts, Pages, or Both)
- Click Run Scan to scan immediately, or
- Enable Scheduled Scans for automatic daily scanning
WP-CLI Commands
Run maintenance scans from the command line:
# Scan all posts and pages
wp hafee posts scan --type=all_posts_pages
# Scan only posts
wp hafee posts scan --type=all_posts
# Scan only pages
wp hafee posts scan --type=all_pages
Building for Distribution
To create a production-ready zip file:
npm run package
This will:
- Build all assets (
npm run build) - Install production Composer dependencies
- Create a zip file excluding development files
Testing
Run the PHPUnit test suite:
composer test
Or directly with PHPUnit:
vendor/bin/phpunit
Code Standards
This plugin follows WordPress Coding Standards. Run code quality checks:
vendor/bin/phpcs
REST API Endpoints
Google Drive Endpoints
POST /wp-json/hafee/v1/drive/save-credentials- Save OAuth credentialsPOST /wp-json/hafee/v1/drive/auth- Get OAuth authorization URLGET /wp-json/hafee/v1/drive/callback- OAuth callback handlerGET /wp-json/hafee/v1/drive/files- List Drive filesPOST /wp-json/hafee/v1/drive/upload- Upload file to DriveGET /wp-json/hafee/v1/drive/download- Download file from DrivePOST /wp-json/hafee/v1/drive/create-folder- Create folder in Drive
Posts Maintenance Endpoints
POST /wp-json/hafee/v1/posts/scan-now- Trigger immediate scanPOST /wp-json/hafee/v1/posts/schedule-scan- Enable/disable scheduled scansGET /wp-json/hafee/v1/posts/get-scan-data- Get scan history and statusGET /wp-json/hafee/v1/posts/schedule-status- Get schedule status
License
GPL-2.0-or-later
Author
Muhammad Hafee Imran