Watcher
WordPress plugin that watches external dev directories and auto-syncs files into your plugins/themes folders — built for Bedrock/Composer workflows.
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/mzeahmed/watcher/archive/refs/heads/main.zipWatcher Plugin
Overview
The Watcher plugin is designed to help developers monitor and synchronize files between development and the WordPress plugins and themes
directories in a Bedrock or WordPlate environment. Plugins and themes are installed via Composer, and if the local composer.json mirrors
the production configuration, this plugin allows developers to work outside plugins and themes directories, ensuring changes are
synchronized without directly modifying plugins or themes in the WordPress directory.
Features
- Monitors specified directories for changes.
- Automatically synchronizes updated or new files to their target destinations.
- Supports excluding specific directories (e.g.,
vendor,node_modules) to optimize performance. - Allows configuration via a constant (
DIRECTORIES_TO_WATCH) or through the WordPress admin panel.
Requirements
- PHP 8.3 or higher.
- WordPress installation.
- Bedrock (optional) for configuration management.
Installation
- Clone the repository or download the plugin zip file.
- Place the plugin folder in the
/pluginsdirectory. - Activate the plugin via the WordPress admin dashboard.
Configuration
Option 1: Define Directories via a Constant (Recommended for Development Environments)
To use the Watcher plugin, you need to define the DIRECTORIES_TO_WATCH constant in your configuration file (e.g., wp-config.php or
config/environments/development.php if using Bedrock).
Example Configuration
Config::define('DIRECTORIES_TO_WATCH', [
'paths' => [
'plugins' => [
[
'source' => dirname(__DIR__, 2) . '/dev/plugins/my-plugin',
'destination' => dirname(__DIR__, 2) . '/web/app/plugins/my-plugin',
'exclude' => ['vendor', 'node_modules', 'resources/i18n'],
],
],
'themes' => [
[
'source' => dirname(__DIR__, 2) . '/dev/themes/my-theme',
'destination' => dirname(__DIR__, 2) . '/web/app/themes/my-theme',
'exclude' => ['vendor', 'node_modules', 'bin'],
],
],
],
]);
Option 2: Configure via WordPress Admin Panel
Watcher also provides an admin settings page where you can dynamically add, modify, or remove directories to monitor.
Steps to Use the Admin Panel:
- Navigate to Settings > Watcher in the WordPress admin dashboard.
- Add new directories to watch under the Plugins or Themes sections.
- Specify the source and destination paths.
- Optionally, add directories to exclude from synchronization.
- Click Save Changes to apply your configuration.
If the DIRECTORIES_TO_WATCH constant is defined, it will take priority over the settings saved in the admin panel.
Usage
- Activate the plugin.
- The plugin will automatically monitor the specified directories and synchronize files as defined in either the
DIRECTORIES_TO_WATCHconstant or the WordPress admin settings.
How It Works
- Initialization: The Watcher class is instantiated when the plugin is activated.
- Directory Monitoring: The plugin reads the paths defined either via the constant or the admin settings.
- File Synchronization: Using the
Utils::listFilesWithRecursiveIteratorIteratormethod, it scans the source directories for files matching the specified extensions and synchronizes them to the destination directories. - Exclusions: Any files or directories listed in the
excludeparameter are ignored.
Troubleshooting
If the plugin does not work as expected:
- Verify that the
DIRECTORIES_TO_WATCHconstant is correctly defined if using this method. - Check that the directories have been properly set in the Watcher settings panel.
- Ensure proper file and directory permissions.
- Look for PHP errors in the WordPress debug log.
License
This plugin is open-source and distributed under the MIT License.