Rethink the WP-CLI approach

未关闭
#153 0 条评论 3 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
5/5
预计耗时
一周以上
新手友好度
25/100
Issue 类型
功能
描述清晰度
基本清楚
活跃度
停滞
技术栈
php, wordpress
领域
cli

调研方向

首先审查当前的 WP-CLI 集成,以及 object-cache.php 如何作为 hook 使用。将该方法与提议的独立 WP-CLI package、条件式 plugin 命令和版本检查进行比较。完成的要求是:就 package 的设计、plugin 的回退行为、更新检测以及必要的 repository 边界达成一致。

由索引模型根据 Issue 内容生成。

描述

[Type] Enhancement Needs Discussion WP-CLI
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.

  1. Create a WP-CLI package that provides a plugin check command. This package is a separate repository and can be installed via something like wp 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 using WP_CLI::add_wp_hook().
  2. From within the plugin, conditionally add a WP-CLI plugin check only if that command is not yet registered (to avoid overriding the already installed WP-CLI package). This plugin check command 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
  1. 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
主要语言
PHP
星标
365
派生
135
平均合并
1 天 8 小时
30 天内合并 PR
20

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

WordPress/plugin-check 的其他 Issue

查看 WordPress/plugin-check 的全部 Issue

相似的 Issue

更多 PHP Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。