Nullable singletons, WP-CLI alias & notices - #259
Conversation
Make singleton instance properties nullable and use explicit null checks in McpAdapter and Plugin. McpAdapter now centralizes WP-CLI command info and registers both "mcp-adapter" and an "mcp" alias. Plugin improves dependency notices by using a reusable closure with a clearer message and hooks into both admin_notices and network_admin_notices. These are minor API/usability improvements and PHP typing refinements.
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
There was a problem hiding this comment.
Pull request overview
This PR refines singleton initialization typing for PHP 8+, improves WP-CLI usability by adding a wp mcp alias alongside wp mcp-adapter, and enhances dependency admin notices for Multisite by showing them in both site and network admin contexts.
Changes:
- Make singleton instance properties explicitly nullable (
?self) withnulldefaults andnull === self::$instancechecks. - Centralize WP-CLI command metadata and register both
mcp-adapterandmcpcommands. - Improve missing-dependency notices by reusing a single callback and hooking into both
admin_noticesandnetwork_admin_notices.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| includes/Plugin.php | Makes the plugin singleton nullable and improves missing Abilities API notices (including Multisite network admin). |
| includes/Core/McpAdapter.php | Makes the adapter singleton nullable and registers an additional WP-CLI command alias (mcp). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| \WP_CLI::add_command( 'mcp-adapter', McpCommand::class, $command_info ); | ||
| \WP_CLI::add_command( 'mcp', McpCommand::class, $command_info ); |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## trunk #259 +/- ##
============================================
+ Coverage 87.94% 87.97% +0.02%
Complexity 1257 1257
============================================
Files 53 53
Lines 4066 4065 -1
============================================
Hits 3576 3576
+ Misses 490 489 -1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
I don’t think we should review this PR as one change. It combines three unrelated changes, but there is no linked issue establishing the current problem, affected users, evidence, and success criteria. The Network Admin notice looks like a real gap. I couldn’t verify the singleton problem. Current The CLI part looks like a documentation bug, not missing functionality. Could you split these changes and keep each one focused on the problem it solves? |
Ensure the MCP adapter singleton initializes correctly without a nullable static property, register the WP-CLI command with explicit metadata, and simplify the missing Abilities API notice by removing the network admin notice hook.
Please check. |
Make singleton instance properties nullable and use explicit null checks in McpAdapter and Plugin. McpAdapter now centralizes WP-CLI command info and registers both "mcp-adapter" and an "mcp" alias. Plugin improves dependency notices by using a reusable closure with a clearer message and hooks into both admin_notices and network_admin_notices. These are minor API/usability improvements and PHP typing refinements.
What?
This PR refines PHP 8+ singleton initialization typing, adds a
wp mcpWP-CLI command alias alongsidewp mcp-adapter, and improves the missing Abilities API dependency notice accessibility for Multisite installs.Why?
$instanceasprivate static ?self $instance = null;and performing explicitnull === self::$instancechecks ensures clean initialization across PHP 7.4 - 8.4+.wp mcp serveandwp mcp list, but previously onlywp mcp-adapterwas registered with\WP_CLI::add_command. Centralizing command metadata and registering bothmcp-adapterandmcpaliases ensures user expectations and docs match CLI behavior.How?
Plugin::$instanceandMcpAdapter::$instancetoprivate static ?self $instance = null;and updated initialization checks tonull === self::$instance.McpAdapter::register_wp_cli_commands()to centralize command metadata array and register bothmcp-adapterandmcpaliases.Plugin::has_dependencies()to use a reusable static closure for displaying the admin notice, providing a clearer user-facing message, and hooking into bothadmin_noticesandnetwork_admin_notices.Use of AI Tools
AI assistance: Yes
Tool(s): Antigravity AI
Model(s): Gemini 3.6 Flash
Used for: Code analysis, PHP 8+ audit, static analysis verification, and drafting pull request description.
Testing Instructions
./vendor/bin/phpstan analyse --memory-limit=1Gand verify 0 errors../vendor/bin/phpcsand verify 100% compliance.wp mcp list/wp mcp serveandwp mcp-adapter list/wp mcp-adapter serveexecute correctly./wp-admin/) and Network Admin (/wp-admin/network/); verify the error notice appears clearly on both dashboards.Screenshots or screencast
wp mcpcommand not found (onlywp mcp-adapterwas registered)wp mcpandwp mcp-adaptercommands work as expectedChangelog Entry