Conversation
…ion plugin Cover PHP class structure, REST hijacking strategy, JS builds, data flow, localization system, security layer, and the companion plugin relationship. Includes critical findings: - array_find() requires PHP 8.4 (declared minimum is 7.2) — production blocker - store.js imports non-existent resolvers (deletePattern, savePattern, etc.) - Rules of Hooks violation in syncedPatternFilter - tbell_pattern_block CPT is public: true (should be false) - Capability assignment runs on every init (should be activation hook) - DB upsert loop on every page load - PatternCreatePanel source:'theme' flag is silently ignored on create - Admin page is an empty shell; Redux store is dead code
PHP fixes:
- Replace array_find() (PHP 8.4+) with array_filter()+reset() — fixes
fatal on PHP 7.4–8.3, the actual declared minimum (TWE-364)
- Bump Requires PHP header from 7.2 to 7.4 (actual minimum given typed
properties and return type hints already in codebase)
- Register wp_pattern_keywords meta so keywords are exposed via REST
(TWE-372)
- Change tbell_pattern_block CPT from public:true to public:false —
prevents pattern posts from getting public front-end URLs (TWE-368)
- Move capability assignment from add_action('init') to
register_activation_hook — eliminates per-request DB writes (TWE-367)
and adds Pattern_Builder_Post_Type::assign_capabilities() static method
- Add custom capabilities to phpcs.xml.dist so PHPCS stops flagging them
as unknown
- Bump phpcs testVersion to 7.4 to match new PHP minimum
- Fix all pre-existing PHPCS violations across all PHP files (0 errors,
0 warnings): Yoda conditions, missing doc comments, inline comment
punctuation, missing method visibility, json_encode->wp_json_encode,
short ternary, empty IF statements
JS fixes:
- Fix Rules of Hooks violation in syncedPatternFilter — useSelect was
called inside a conditional; moved unconditionally with guard logic
inside the selector (TWE-366)
- Delete dead Redux store (store.js) which imported non-existent
deletePattern/savePattern/fetchEditorConfiguration from resolvers
- Delete PatternBuilder_Admin.js and AdminLandingPage.js — admin page
replaced with a simple PHP-rendered page
- Remove PatternBuilder_Admin entry from webpack.config.js
- Clean up src/utils/index.js
Build: npm run build + test:unit pass; composer lint 0 errors 0 warnings
|
Claude finished @twentybellows-hephaestus's task —— View job Code Review for PR #44: Critical Bug FixesThis PR addresses critical and high-priority bugs from the architecture review. Here's my comprehensive analysis: ✅ Excellent Fixes - Critical Issues Resolved🔴 PHP Compatibility Fix (TWE-364)Perfect execution. The // Before (PHP 8.4 only)
$pattern = array_find($patterns, function($p) use ($pattern) {
return $p->name === $pattern->name;
});
// After (PHP 7.4+ compatible)
$filtered = array_filter($patterns, function($p) use ($pattern) {
return $p->name === $pattern->name;
});
$matched_pattern = reset($filtered);
🔴 React Hooks Violation Fix (TWE-366)Excellent fix. The // Before: useSelect called conditionally (VIOLATION)
if (name === 'core/pattern' && attributes.slug) {
const selectedPattern = useSelect(...)
}
// After: useSelect called unconditionally (CORRECT)
const selectedPattern = useSelect((select) => {
if (name !== 'core/pattern' || !attributes.slug) {
return null;
}
return select(blockEditorStore).__experimentalGetParsedPattern(attributes.slug);
}, [name, attributes.slug]);This prevents React runtime errors and ensures proper hook behavior. ✅ Good Quality Improvements🟡 CPT Security Fix (TWE-368)Correct change. Setting 🟡 Performance Fix (TWE-367)Smart optimization. Moving capability assignment from 🟡 Missing Meta Registration (TWE-372)Important fix. Adding 🟡 Admin Page SimplificationReasonable decision. Replacing the broken React admin page with simple PHP rendering eliminates dead code and build complexity. The new implementation in ✅ Code Quality ImprovementsPHPCS ComplianceComprehensive cleanup. All major WPCS violations addressed:
Dead Code RemovalGood cleanup. Removing unused
|
|
Claude finished @twentybellows-hephaestus's task —— View job PR Review: Critical Bug Fixes AnalysisTodo List:
Review SummaryThis PR effectively addresses critical and high-priority bugs identified in the architecture review. The fixes are well-implemented and resolve significant compatibility and functionality issues. ✅ Excellent Fixes - Critical Issues Resolved🔴 PHP 8.4 Compatibility Fix (TWE-364)Perfect execution. The // Before: PHP 8.4 only
$pattern = array_find($patterns, function($p) use ($pattern) {
return $p->name === $pattern->name;
});
// After: PHP 7.4+ compatible
$filtered = array_filter($patterns, function($p) use ($pattern) {
return $p->name === $pattern->name;
});
$matched_pattern = reset($filtered);
🔴 React Rules of Hooks Violation Fix (TWE-366)Excellent fix. The // Before: useSelect called conditionally (VIOLATION)
if (name === 'core/pattern' && attributes.slug) {
const selectedPattern = useSelect(...)
}
// After: useSelect called unconditionally (CORRECT)
const selectedPattern = useSelect((select) => {
if (name !== 'core/pattern' || !attributes.slug) {
return null;
}
return select(blockEditorStore).__experimentalGetParsedPattern(attributes.slug);
}, [name, attributes.slug]);This prevents React runtime errors and ensures proper hook behavior. ✅ Quality Improvements🟡 Security & Performance Fixes
🟡 Code Quality
|
Summary
Fixes all critical and high-priority bugs identified in the architecture review (FORGE-53). Single branch, all changes in one commit.
PHP Changes
🔴
array_find()→ PHP 7.4-compatible alternative (TWE-364)array_find()is a PHP 8.4-only function. Plugin declaresRequires PHP: 7.2. Any site running PHP < 8.4 would get a fatal error on every pattern save or path lookup.Fix: Replace with
array_filter() + reset()in two places inclass-pattern-builder-controller.php.Also: Bumped
Requires PHPheader from7.2to7.4— the codebase already uses typed properties, nullable types, andvoidreturn types which require 7.4 minimum.🟡 CPT
public: true→public: false(TWE-368)tbell_pattern_blockposts had public front-end URLs (WordPress creates rewrite rules forpublic: truepost types). Pattern posts are internal scaffolding and should never be publicly accessible.🟡 Capability assignment on every
init→register_activation_hook(TWE-367)WP_Role::add_cap()callsupdate_option()if the capability isn't already stored. Running this on every request means a potential DB write on every page load for new installs.Fix: Added
Pattern_Builder_Post_Type::assign_capabilities()static method, wired toregister_activation_hookinpattern-builder.php.🟡 Register missing
wp_pattern_keywordsmeta (TWE-372)The
wp_pattern_keywordsmeta key was read from and written to the DB throughout the controller, but was never registered viaregister_post_meta(). Keywords were invisible to the REST API.🟡 PHPCS: 0 errors, 0 warnings
Fixed all pre-existing WPCS violations across all PHP files:
json_encode→wp_json_encodeifstatementsAdded custom capabilities to
phpcs.xml.distand updatedtestVersionto7.4.JS Changes
🔴 Rules of Hooks violation in
syncedPatternFilter(TWE-366)useSelectwas called inside a conditional (if (name === 'core/pattern' && ...)). React's Rules of Hooks forbid this — hooks must be called unconditionally on every render.Fix:
useSelectis now called unconditionally; the conditional guard logic is inside the selector function.🔴 Dead Redux store with broken imports (TWE-365)
store.jsimporteddeletePattern,savePattern, andfetchEditorConfigurationfromresolvers.js— functions that don't exist there. Any dispatch of those actions would throw aTypeError. The store itself was never used by any component.Fix: Deleted
store.jsentirely (dead code).🟡 Admin page stripped to plain PHP
PatternBuilder_Admin.jsandAdminLandingPage.jswere a React app rendering a documentation splash screen with a broken store behind it. Replaced with a simple PHP-rendered admin page inclass-pattern-builder-admin.php. Removed thePatternBuilder_Adminentry fromwebpack.config.js.Quality Gates
composer lint: ✅ 0 errors, 0 warningsnpm run build: ✅ compiles cleanly (EditorTools only)npm run test:unit: ✅ passes