Skip to content

Nullable singletons, WP-CLI alias & notices - #259

Open
murshed wants to merge 2 commits into
WordPress:trunkfrom
murshed:trunk
Open

Nullable singletons, WP-CLI alias & notices#259
murshed wants to merge 2 commits into
WordPress:trunkfrom
murshed:trunk

Conversation

@murshed

@murshed murshed commented Jul 27, 2026

Copy link
Copy Markdown

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 mcp WP-CLI command alias alongside wp mcp-adapter, and improves the missing Abilities API dependency notice accessibility for Multisite installs.

Why?

  • PHP 8+ Type Refinement: Uninitialized typed static properties can cause static analysis warnings or initialization ambiguities under strict PHP 8.0+ environments. Declaring $instance as private static ?self $instance = null; and performing explicit null === self::$instance checks ensures clean initialization across PHP 7.4 - 8.4+.
  • WP-CLI Usability & Alignment: Documentation and examples reference wp mcp serve and wp mcp list, but previously only wp mcp-adapter was registered with \WP_CLI::add_command. Centralizing command metadata and registering both mcp-adapter and mcp aliases ensures user expectations and docs match CLI behavior.
  • Admin & Multisite Accessibility: When the required Abilities API plugin is missing, network admins on Multisite setups did not receive the warning, and the message lacked clear actionable guidance.

How?

  1. Singleton Initialization: Updated Plugin::$instance and McpAdapter::$instance to private static ?self $instance = null; and updated initialization checks to null === self::$instance.
  2. WP-CLI Command Registration: Refactored McpAdapter::register_wp_cli_commands() to centralize command metadata array and register both mcp-adapter and mcp aliases.
  3. Dependency Notices: Updated Plugin::has_dependencies() to use a reusable static closure for displaying the admin notice, providing a clearer user-facing message, and hooking into both admin_notices and network_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

  1. Run PHPStan static analysis: ./vendor/bin/phpstan analyse --memory-limit=1G and verify 0 errors.
  2. Run PHP CodeSniffer: ./vendor/bin/phpcs and verify 100% compliance.
  3. In WP-CLI, verify both wp mcp list / wp mcp serve and wp mcp-adapter list / wp mcp-adapter serve execute correctly.
  4. Deactivate the Abilities API plugin and load both single-site Admin (/wp-admin/) and Network Admin (/wp-admin/network/); verify the error notice appears clearly on both dashboards.

Screenshots or screencast

Before After
wp mcp command not found (only wp mcp-adapter was registered) Both wp mcp and wp mcp-adapter commands work as expected
Admin notice only shown on single-site admin Admin notice shown on both single-site and network admin

Changelog Entry

Developer - Refine singleton typing for PHP 8+ compatibility, add wp mcp WP-CLI command alias, and improve dependency notices for Multisite installs.

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.
Copilot AI review requested due to automatic review settings July 27, 2026 15:45
@github-actions

github-actions Bot commented Jul 27, 2026

Copy link
Copy Markdown

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 props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: murshed <fahimmurshed@git.wordpress.org>
Co-authored-by: galatanovidiu <ovidiu-galatan@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) with null defaults and null === self::$instance checks.
  • Centralize WP-CLI command metadata and register both mcp-adapter and mcp commands.
  • Improve missing-dependency notices by reusing a single callback and hooking into both admin_notices and network_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.

Comment thread includes/Core/McpAdapter.php Outdated
Comment on lines +150 to +151
\WP_CLI::add_command( 'mcp-adapter', McpCommand::class, $command_info );
\WP_CLI::add_command( 'mcp', McpCommand::class, $command_info );
@codecov

codecov Bot commented Jul 27, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 11.76471% with 15 lines in your changes missing coverage. Please review.
✅ Project coverage is 87.97%. Comparing base (4d19d22) to head (9ad05cb).

Files with missing lines Patch % Lines
includes/Plugin.php 9.09% 10 Missing ⚠️
includes/Core/McpAdapter.php 16.66% 5 Missing ⚠️
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     
Flag Coverage Δ
unit 87.97% <11.76%> (+0.02%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@galatanovidiu

Copy link
Copy Markdown
Contributor

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. Plugin::has_dependencies() only hooks admin_notices, while WordPress has a separate network_admin_notices hook. I think this should be a focused change with a Multisite reproduction and test.

I couldn’t verify the singleton problem. Current trunk still uses the existing singleton properties, and its PHPStan Level 8 check passes. Could you provide the exact warning or runtime failure this change fixes? Otherwise, I think this is only a style cleanup and should be removed.

The CLI part looks like a documentation bug, not missing functionality. wp mcp-adapter is the registered command and is used throughout the maintained documentation. The five wp mcp examples are only in McpCommand PHPDoc. I think we should update those examples to use wp mcp-adapter and remove the new wp mcp alias from this PR. We should not change the public CLI commands to fix inconsistent documentation.

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.
@murshed

murshed commented Aug 13, 2026

Copy link
Copy Markdown
Author

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. Plugin::has_dependencies() only hooks admin_notices, while WordPress has a separate network_admin_notices hook. I think this should be a focused change with a Multisite reproduction and test.

I couldn’t verify the singleton problem. Current trunk still uses the existing singleton properties, and its PHPStan Level 8 check passes. Could you provide the exact warning or runtime failure this change fixes? Otherwise, I think this is only a style cleanup and should be removed.

The CLI part looks like a documentation bug, not missing functionality. wp mcp-adapter is the registered command and is used throughout the maintained documentation. The five wp mcp examples are only in McpCommand PHPDoc. I think we should update those examples to use wp mcp-adapter and remove the new wp mcp alias from this PR. We should not change the public CLI commands to fix inconsistent documentation.

Could you split these changes and keep each one focused on the problem it solves?

Please check.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants