WP-CLI 3.0: the activation redirect silently ends the next `wp plugin` / `wp theme` command
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
调研方向
从 inc/admin.php 中的 Admin::maybe_redirect() 开始;这是 issue 中提到的激活后重定向,检查它如何读取并清除重定向标志。使用 issue 中的两个 WP-CLI 命令复现问题,然后添加其中描述的提前返回,并验证下一个命令能够运行,同时重定向在第一个 wp-admin 页面上仍然有效。
由索引模型根据 Issue 内容生成。
描述
What happens
WP-CLI 3.0 (stable since 2026-12-01) changed its default context from cli to auto, which runs wp plugin … and wp theme … commands as a wp-admin page load for an administrator, so admin_init fires. Optimole's one-time redirect after activation, Admin::maybe_redirect() (https://github.com/Codeinwp/optimole-wp/blob/31e2a5c8d039998cfd2921544d3655d1878fb316/inc/admin.php#L1137), then calls wp_safe_redirect() and exit. WP-CLI suppresses the redirect header (wp-cli/wp-cli#6279) but not the exit, so the first such command after activating Optimole ends with exit code 0, no output, and having done nothing.
A deploy or provisioning script that activates Optimole and then runs another plugin or theme command silently skips that step: an install that never happens, a theme that is not activated, a deactivation that does not happen, or wp plugin is-installed answering success for a missing plugin. Only one command is affected, because the redirect clears its flag.
Reproduce
wp plugin activate optimole-wp
wp plugin install hello-dolly # WP-CLI 3.0.x: prints nothing, exit 0, nothing installed
Measured on a local WordPress site with the current release of Optimole: under WP-CLI 3.0.1 the wp plugin install above printed nothing, exited 0 and installed nothing; under WP-CLI 2.12.0 the same steps installed the plugin.
Suggested fix
Return before the flag is read or cleared when running under WP-CLI, so the redirect still happens on the administrator's first wp-admin page:
if ( defined( 'WP_CLI' ) && WP_CLI ) {
return;
}
This is how Easy MCP AI fixed the same bug in App_Page::maybe_redirect() (Codeinwp/wp-plugin-easy-mcp@c2ef3e341, with a unit test). Other Codeinwp products were checked the same way; the same issue is open in each affected one:
- Codeinwp/hyve-lite#325
- Codeinwp/optimole-wp#1259
- Codeinwp/otter-blocks#3238
- Codeinwp/redirection-for-contact-form-7#332
- Codeinwp/sparks-for-woocommerce#441
- Codeinwp/templates-patterns-collection#554
- Codeinwp/WP-Cloudflare-Super-Page-Cache#899
- Codeinwp/wp-full-stripe#853
- Codeinwp/wp-maintenance-mode#615
- 主要语言
- PHP
- 星标
- 75
- 派生
- 14
- 平均合并
- 1 天 6 小时
- 30 天内合并 PR
- 31
环境准备
- 提供 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
Codeinwp/optimole-wp 的其他 Issue
-
bug-report bug-report-triage customer report
难度 2/5 1-3 小时 新手友好度 69/100
Codeinwp/optimole-wp#1255 ·
维护者通常 1 天内回复
-
Lazyload SVG placeholder runs uncached attachment lookups with JSON-escaped URLs on REST responses未关闭customer report
难度 2/5 1-3 小时 新手友好度 72/100
Codeinwp/optimole-wp#1253 ·
维护者通常 1 天内回复
-
customer report feature-request-triage
难度 2/5 1-3 小时 新手友好度 72/100
Codeinwp/optimole-wp#1239 ·
维护者通常 1 天内回复
-
Throttle and optimize `/wp-json/optml/v1/optimizations` REST API endpoint execution and validation未关闭customer report feature-request-triage
难度 3/5 1-2 天 新手友好度 45/100
Codeinwp/optimole-wp#1250 ·
维护者通常 1 天内回复
-
Cache `attachment_url_to_postid()` lookups in `Optml_Lazyload_Replacer` to reduce database overhead未关闭customer report feature-request-triage
难度 3/5 1-2 天 新手友好度 65/100
Codeinwp/optimole-wp#1249 · 1 条评论 ·
维护者通常 1 天内回复
查看 Codeinwp/optimole-wp 的全部 Issue