Restore pre-4.7.0 global class names as backward-compat aliases#320
Merged
Conversation
The 4.7.0 namespace refactoring removed all global classes, which broke third-party plugins that check for them — most notably Micropub, which gates its whole initialization (including its REST route registration) on class_exists( 'IndieAuth_Plugin' ). Register the old names as aliases of their namespaced replacements: IndieAuth_Plugin eagerly, so checks with autoloading disabled also work, and the rest lazily via spl_autoload_register. Fixes #319 Claude-Session: https://claude.ai/code/session_0126gxnmr2SMc4X4J1Y6yf71
Contributor
There was a problem hiding this comment.
Pull request overview
This PR restores backward compatibility for pre-4.7.0 global class names by introducing a compatibility layer that aliases legacy class names to their new namespaced equivalents, unblocking third-party plugins (notably Micropub) that detect IndieAuth via class_exists( 'IndieAuth_Plugin' ).
Changes:
- Add
includes/compat.phpto register legacy-to-namespaced class aliases (withIndieAuth_Pluginintended to be available eagerly). - Load the compatibility layer during plugin bootstrap.
- Add PHPUnit coverage asserting legacy class names resolve correctly, and document the change in the changelog.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
includes/compat.php |
Defines the legacy→namespaced class map and registers aliasing via an autoloader + eager alias for IndieAuth_Plugin. |
indieauth.php |
Loads the new compat layer during plugin startup. |
tests/phpunit/tests/includes/class-test-compat.php |
Adds tests to validate legacy class alias behavior and Micropub detection expectations. |
readme.md |
Adds a changelog entry describing the restored legacy class aliases. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Lazily aliased legacy classes now trigger _deprecated_class() on first use. IndieAuth_Plugin stays eagerly aliased and notice-free, because plugins like Micropub use it for feature detection. _deprecated_class() requires WordPress 6.4, so the minimum required version is raised from 6.2 to 6.4. Claude-Session: https://claude.ai/code/session_0126gxnmr2SMc4X4J1Y6yf71
The WP 6.4 requirement bump was meant for the WebFinger plugin, not for IndieAuth. Claude-Session: https://claude.ai/code/session_0126gxnmr2SMc4X4J1Y6yf71
ClassicPress does not have _deprecated_class(), so the compat autoloader's function_exists() guard correctly skips the notice there. Mirror that condition in the test instead of expecting the notice unconditionally, which failed the ClassicPress CI matrix. Claude-Session: https://claude.ai/code/session_0126gxnmr2SMc4X4J1Y6yf71
Guard the eager IndieAuth_Plugin alias against the name being already defined (e.g. by a site-level workaround for the 4.7.0 breakage). The lazy autoloader path needs no guard, because PHP never invokes autoloaders for defined classes. Add an assertion that COMPAT_CLASS_MAP and the test data provider cover the same classes, while keeping the provider as an independent pin of the pre-4.7.0 surface. Claude-Session: https://claude.ai/code/session_0126gxnmr2SMc4X4J1Y6yf71
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The 4.7.0 namespace refactoring (#306) removed all global classes without backward-compat aliases. Third-party plugins that check for the old names broke — most notably Micropub, which gates its whole initialization on
class_exists( 'IndieAuth_Plugin' )and therefore never registers its REST routes under 4.7.0 (rest_no_route404).Fixes #319
Solution
New
includes/compat.phpregisters the old global class names as aliases of their namespaced replacements:IndieAuth_Pluginis aliased eagerly and notice-free, soclass_exists( 'IndieAuth_Plugin', false )checks work and feature detection doesn't spam debug logs.spl_autoload_register(); first use triggers_deprecated_class()(guarded byfunction_exists(), since the plugin supports WP 6.2 and_deprecated_class()needs 6.4) pointing to the namespaced replacement.IndieAuth_Endpoint, whose functionality moved to theIndieAuth\Rest\Token_Managementtrait (a class alias cannot represent a trait), and the seven*_Endpointclasses (authorization, introspection, metadata, revocation, ticket, token, userinfo), whose legacyget_endpoint()API was static while the replacement controller methods are not — an alias would not restore the old calling convention.Verification
Test_Compatsuite asserts every legacy name resolves to its namespaced replacement, that lazy aliases trigger the expected deprecation, and that the excluded endpoint classes stay unaliased (30 tests, written first and watched fail).GET /?rest_route=/micropub/1.0/endpointreturns 404rest_no_route; with this patch → 403 (route registered, auth required), matching 4.6.0 behavior. Eager/lazy alias semantics,IndieAuth_Client_Taxonomy::get_client()callability andToken_Userinstantiation verified at runtime viawp eval.Companion change for WebFinger: pfefferle/wordpress-webfinger#58