refactor: architectural cleanup — dead guards + long-deprecated shims (−593 LOC)#1173
Merged
refactor: architectural cleanup — dead guards + long-deprecated shims (−593 LOC)#1173
Conversation
Plugin header requires WP 6.9 where WP_Ability and WP_Abilities_Registry
both ship in core — every `if ( ! class_exists( 'WP_Ability' ) ) return;`
bootstrap guard in inc/Abilities/ and adjacent is unreachable, same for
`class_exists( 'WP_Abilities_Registry' ) ? ...::get_instance() : null`
ternaries in the tool/action policy resolvers.
Mechanical sweep via `homeboy refactor transform` — transform set persisted
to homeboy.json (`drop_wp_ability_dead_guards`) so the pattern is reusable.
Three rules total:
- simple_guard: remove standalone `if ( ! class_exists( 'WP_Ability' ) )`
bootstrap guards (83 hits across inc/Abilities).
- combined_guard_registered: drop the WP_Ability half of combined
`if ( ! class_exists(...) || self::$registered )` guards (18 hits,
including one in inc/Engine via a separate rule).
- ternary_registry_guard: collapse unreachable ternaries in
ToolPolicyResolver + ActionPolicyResolver (4 hits).
Plus a few hand-fixes the transform couldn't reach cleanly:
- inc/Abilities/SEO/IndexNowAbilities.php had an inverted guard-intent that
the transform correctly refused to rewrite; simplified by hand so the
registered-guard early-return actually matches the rest of the file.
- inc/Engine/Actions/Handlers/LogHandler.php had a positive-form
`if ( class_exists( 'WP_Ability' ) ) { ... }` wrapper with a dead
fallback; unindented the body, removed the fallback.
- inc/Abilities/File/ScaffoldAbilities::get_ability() collapsed the
now-redundant registry presence check.
- inc/Engine/AI/Tools/ToolPolicyResolver::filterByAbilityPermissions() had
an inverted `function_exists('WP_Abilities_Registry')` check that can
never be true (it's a class, not a function) — simplified to a direct
registry call.
Net: 106 files, −303 LOC with zero behavior change.
…licateDetection, ToolExecutor::getAvailableTools, ToolManager::getAvailableToolsForChat) Five shims deprecated between 0.39.0 and 0.48.0 with zero live callers in DM core or consumer plugins (data-machine-events, data-machine-socials, intelligence). Plugin is now on 0.78 — dragging these along any longer is pure noise. - `DataMachine\Core\WordPress\SiteContext` Site context moved to SITE.md auto-regeneration in 0.48.0 (#871). The class was a no-op wrapper over a cleared transient. No callers. - `DataMachine\Engine\AI\Directives\SiteContextDirective` Same migration — the directive was unregistered in 0.48.0 and left behind as a no-op stub. No callers. - `DataMachine\Core\WordPress\DuplicateDetection` Replaced by `DuplicateCheckAbility` + `SimilarityEngine` in 0.39.0. The only remaining caller (inc/Core/Steps/Publish/Handlers/WordPress) was running the legacy `findExistingPostByTitle()` as a fallback after `datamachine/check-duplicate` already returned no match — pure belt- and-suspenders since the ability's published-post strategy is a byte-for-byte superset of the legacy query. Migrated the handler to rely on the ability exclusively and inlined the 14-day default. data-machine-events's EventDuplicateStrategy already registers on `datamachine_duplicate_strategies` — unaffected. - `ToolExecutor::getAvailableTools()` - `ToolManager::getAvailableToolsForChat()` Both deprecated in 0.39.0 in favor of `ToolPolicyResolver::resolve()`. Only callers were two delegation tests that verified they still delegated — removed tests and shims together. Updated three docs (`docs/ai-tools/tools-overview.md`, `docs/core-system/tool-execution.md`, `docs/development/hooks/core-filters.md`) to stop recommending the removed method in executable examples. Net: 10 files, −290 LOC.
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.
Summary
Architectural cleanup sweep — removes ~600 LOC of dead code that should have been gone a long time ago. No behavior change, zero external-plugin breakage.
Shipped as two reviewable commits:
Why now
Kicked off from a broader architectural-cleanup audit. Homeboy's existing audit detectors (#674, #675, #676, #677, #776, #957) already do a great job on duplicate functions, god files, repeated fields, parallel implementations, etc. — but don't detect either of these two classes of issue:
Both patterns suggested as new homeboy audit detectors — issues will link back here.
Commit 1 — dead-guard sweep
Mechanical pass via `homeboy refactor transform`. The transform set is persisted in `homeboy.json` as `drop_wp_ability_dead_guards` so the pattern is reusable (and re-runnable if new dead guards creep back in).
Three rules:
Plus a few hand-fixes the transform couldn't reach cleanly:
Commit 2 — long-deprecated shims
Five shims deprecated between 0.39.0 and 0.48.0. All have zero live callers in DM core or consumer plugins.
Verified downstream: greppedboth `data-machine-events`, `data-machine-socials`, and `intelligence` — none reference any of the removed symbols. Events already uses the unified `datamachine/check-duplicate` ability and registers `EventDuplicateStrategy` on the `datamachine_duplicate_strategies` filter, so it's unaffected by the `DuplicateDetection` class removal.
Validation
Follow-ups not in this PR
These are the things I deliberately didn't tackle, because they want their own review thread:
AI assistance