WordPress / WordPress/plugin-check
Rethink the WP-CLI approach
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 362
- Forks
- 126
- Avg merge
- 1d 23h
- Merged PRs (30d)
- 22
Description
Is your enhancement related to a problem? Please describe.
Hi performance team!
@spacedmonkey pinged me to see if I have any input on improving the WP-CLI integration.
The current approach to integrating with WP-CLI is both cumbersome and can lead to side effects due to the use of object-cache.php as a "hook".
I would suggest a different approach that is safer to use and will ultimately provide a better user experience.
- Create a WP-CLI package that provides a
plugin checkcommand. This package is a separate repository and can be installed via something likewp package install 10up/plugin-check-cli. As a WP-CLI package, it is already loaded and active before WordPress is loaded, so there is no need for any special handling to get in early. The command can check for the existence of the plugin and make use of its files as required, or come with its own code where it makes sense. This allows for different handling in CLI than for the regular plugin, but also allows for code reuse where applicable (just ensure you can rely on a fixed set of interfaces!). It also gives full control over the WordPress environment and you can already hook into the WordPress lifecycle usingWP_CLI::add_wp_hook(). - From within the plugin, conditionally add a WP-CLI
plugin checkonly if that command is not yet registered (to avoid overriding the already installed WP-CLI package). Thisplugin checkcommand does not actually run any checks, though, it only produces a helpful message about the missing WP-CLI package and how the user can install it. It will show something like this:
$ wp plugin check akismet
Error: The necessary WP-CLI package for running performance checks has not yet been installed.
Please install it using the following command and then run your request again:
wp package install 10up/plugin-check-cli
- Add version numbers and update checks into both the WP-CLI package and the plugin to ensure that you can detect unmet requirements and prompt users to run updates when required.
The above should be a safer way to achieve a WP-CLI integration with a plugin that goes beyond the boundaries of what a plugin is supposed to do.
That being said, I'd like to note, that I'd generally not recommend have this type of checkers in a plugin, but would rather recommend building it CLI-first and then maybe wrap a plugin UI around it, not the other way around as it is happening here.
Designs
No response
Describe alternatives you've considered
No response
Code of Conduct
- I agree to follow this project's Code of Conduct
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing the current WP-CLI integration and how object-cache.php is used as a hook. Compare that approach with the proposed separate WP-CLI package, conditional plugin command, and version checks. Done would require an agreed design for the package, plugin fallback behavior, update detection, and the necessary repository boundaries.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php, wordpress
- Domain
- cli
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100