Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 5, 2026

  • Analyze the current wp_get_cache_type() function implementation in php/utils-wp.php
  • Add WP-Stash detection logic to the function
  • Enhance Unknown cache type to include the class name of the object cache
  • Create Behat tests to validate the changes
  • Run linter and code style checks (all passing)
  • Run static analysis (all passing)
  • Address code review feedback with proper error handling
  • Use \Throwable for broader exception handling
  • Ensure message is always set when WP-Stash class exists
  • Fix PHP namespace declaration errors and global variable scoping
  • All code quality checks passing (lint, phpcs, phpstan)
  • No regressions in PHPUnit tests

Summary

Successfully implemented support for WP-Stash cache type detection and enhanced unknown cache type reporting.

Latest Fix

Fixed two critical test issues:

  1. PHP Fatal Error: Moved namespace declaration to be the first statement (PHP requirement). The $_wp_using_ext_object_cache global is now set inside the namespace {} block for the WP-Stash test.
  2. Global Variable Scope: Added global $_wp_using_ext_object_cache; declaration to ensure the variable is properly accessible in the global scope, which is required for WordPress to detect external object caches.
Original prompt

This section details on the original issue you should resolve

<issue_title>Support WP-Stash in 'wp cache type'</issue_title>
<issue_description>Greetings.

I just looked around the wp cache type command after seeing it returns "Unknown" in our WP instances running WP Stash. I think it would be pretty useful if we could see that a site is indeed running WP-Stash - and possibly which driver is in use.

I see that determining the cache type is a "manual" process that checks for the specifics of several implementations. So would you be supportive of adding WP Stash to the list of implementations to check against?

The most basic check would probably be class_exists('Inpsyde\WpStash\WpStash') and it could return get_class( WpStash::instance()->driver() ). This would yield the FQCN of the StashPHP driver that is currently being used.

I hope you consider this a worthwhile addition - which I'd happily PR your way.

As a side note: Wouldn't it make sense to provide a generic way for implementations to TELL wp-cli what's being used? The ideal solution would be of course if WP-Core had such a thing on offer, but in the absence of this: is there an inherent problem with checking for the existence of $wp_object_cache->type - or maybe even calling wp_cache_type() if it exists?

In addition, maybe you could return 'Unknown: ' . get_class( $wp_object_cache ), so users with entirely custom solutions would at least get some result.</issue_description>

Comments on the Issue (you are @copilot in this section)

@danielbachhuber Thanks for the suggestion, @Biont !

I'd be happy to accept a PR for what you're suggesting.

As a side note: Wouldn't it make sense to provide a generic way for implementations to TELL wp-cli what's being used? The ideal solution would be of course if WP-Core had such a thing on offer, but in the absence of this: is there an inherent problem with checking for the existence of $wp_object_cache->type - or maybe even calling wp_cache_type() if it exists?

If a wp_cache_type() function existed in WordPress core, we could easily call it. I think it makes most sense to implement that formally first. It's not too much effort to maintain a list of object caches as there aren't many of them.

In addition, maybe you could return 'Unknown: ' . get_class( $wp_object_cache ), so users with entirely custom solutions would at least get some result.

Sure! Feel free to submit that as a second PR if you'd like.</comment_new>
<comment_new>@danielbachhuber
Related #5735</comment_new>
<comment_new>@danielbachhuber

  1. WP-CLI should do the if (defined) call pattern on $wp_object_cache->get_cache_type() to get its results...

I think this needs to exist in core first. I don't want to introduce support for something official-looking, only to have core implement some different approach.</comment_new>
<comment_new>@swissspidy
Opened https://core.trac.wordpress.org/ticket/58808 for that proposal</comment_new>
<comment_new>@swissspidy
Yeah https://github.com/rhubarbgroup/wp-object-cache-info-spec was just mentioned to me today. I think I'm the wrong one to collaborate on that though, as I am not really familiar with all the object cache stuff.</comment_new>


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@codecov
Copy link

codecov bot commented Jan 5, 2026

Codecov Report

❌ Patch coverage is 75.00000% with 3 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
php/utils-wp.php 75.00% 3 Missing ⚠️

📢 Thoughts on this report? Let us know!

Copilot AI and others added 4 commits January 5, 2026 17:38
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Copilot AI changed the title [WIP] Support WP-Stash in wp cache type command Add WP-Stash support and enhanced unknown cache detection to wp_get_cache_type() Jan 5, 2026
Copilot AI requested a review from swissspidy January 5, 2026 17:46
@swissspidy

This comment was marked as resolved.

…che.php

Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>

This comment was marked as resolved.

@swissspidy

This comment was marked as resolved.

Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>

This comment was marked as resolved.

@swissspidy

This comment was marked as resolved.

…bject_cache

Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>

This comment was marked as resolved.

@swissspidy swissspidy changed the title Add WP-Stash support and enhanced unknown cache detection to wp_get_cache_type() Detect WP-Stash in wp_get_cache_type() util Jan 5, 2026
@swissspidy swissspidy marked this pull request as ready for review January 5, 2026 21:44
@swissspidy swissspidy requested a review from a team as a code owner January 5, 2026 21:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support WP-Stash in 'wp cache type'

2 participants