wp-cli/extension-command
WP-CLI extension-command adds wp plugin and wp theme management: install, activate/deactivate, update, delete, and more. Supports bulk actions, multisite network activation, exclusions, and forcing reactivation to rerun hooks.
Installation:
composer require wp-cli/extension-command
Ensure WP-CLI is installed globally (wp --version) and the package is autoloaded via Composer.
First Use Case: List installed plugins with their status:
wp plugin list --status=active
Verify output includes active plugins (e.g., akismet, hello).
Key Files:
src/Plugin.php: Core logic for plugin operations.src/PluginCommand.php: Command handler for CLI integration.tests/: Unit and Behat tests for validation.Plugin Lifecycle Management:
--activate to auto-activate post-install:
wp plugin install bbpress --activate
wp plugin install $(wp plugin list --field=name) --force
wp plugin delete $(wp plugin list --status=inactive --field=name)
Dependency Handling:
wp plugin install my-plugin --with-dependencies --activate
wp plugin install-dependencies my-plugin --activate
Multisite Support:
wp plugin activate hello --network
wp plugin deactivate --all --exclude=hello,jetpack
PluginCommand to add domain-specific logic (e.g., validate plugins against a whitelist).activated_plugin) to trigger post-install actions:
add_action('activated_plugin', function($plugin) {
// Custom logic after activation
});
wp plugin list --field=name --format=csv | xargs -I {} wp plugin get {} --field=version
Permission Issues:
chown -R www-data:www-data wp-content).--force cautiously; it bypasses safety checks (e.g., version conflicts).Multisite Quirks:
--network) require super-admin privileges.Caching:
wp cache flush) if commands fail unexpectedly:
wp cache flush --group=plugins
Plugin Conflicts:
--ignore-requirements sparingly; it may break functionality:
wp plugin install my-plugin --ignore-requirements
WP_CLI_DEBUG=1 wp plugin install my-plugin
wp plugin list --status=active --format=json | jq '.[] | select(.name == "akismet")'
Custom Fields:
PluginCommand::getFields() to add metadata (e.g., custom plugin tags):
protected function getFields() {
return array_merge(parent::getFields(), ['custom_tag']);
}
Pre/Post Hooks:
PluginCommand::activate() to inject logic:
protected function activate($plugins) {
// Custom activation logic
parent::activate($plugins);
}
Testing:
Given HTTP requests to "https://downloads.wordpress.org" will respond with:
"""
HTTP/1.1 200 OK
Content-Type: application/octet-stream
Content-Disposition: attachment; filename="plugin.zip"
"""
How can I help you explore Laravel packages today?