|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Plugin Overview |
| 6 | + |
| 7 | +WebberZone Knowledge Base is a free WordPress plugin (namespace `WebberZone\Knowledge_Base`) that creates a multi-product knowledge base system. This is the standalone free version — there is no `includes/pro/` directory here. The companion premium plugin (knowledgebase-pro) is a separate repository that extends this codebase with pro features. |
| 8 | + |
| 9 | +- **Plugin entry**: `knowledgebase.php` (defines constants, loads Freemius, triggers autoloader) |
| 10 | +- **PHP**: 7.4+ | **WordPress**: 6.7+ |
| 11 | +- **Custom post type**: `wz_knowledgebase` | **Taxonomies**: `wzkb_category`, `wzkb_product`, `wzkb_tag` |
| 12 | +- **Constants**: `WZKB_VERSION`, `WZKB_PLUGIN_DIR`, `WZKB_PLUGIN_URL`, `WZKB_PLUGIN_FILE`, `WZKB_DEFAULT_THUMBNAIL_URL` |
| 13 | + |
| 14 | +## Build & Development Commands |
| 15 | + |
| 16 | +### PHP |
| 17 | + |
| 18 | +```bash |
| 19 | +composer install # Install dependencies |
| 20 | +composer test # Run phpcs + phpcompat + phpstan |
| 21 | +composer phpcs # WordPress coding standards check |
| 22 | +composer phpcbf # Auto-fix coding standards |
| 23 | +composer phpstan # Static analysis (Level 5) |
| 24 | +composer phpcompat # PHP 7.4–8.5 compatibility check |
| 25 | +vendor/bin/phpunit # Run unit tests |
| 26 | +vendor/bin/phpunit --filter TestName # Run a single test by name |
| 27 | +WP_MULTISITE=1 vendor/bin/phpunit # Run multisite unit tests |
| 28 | +``` |
| 29 | + |
| 30 | +### JavaScript / Blocks |
| 31 | + |
| 32 | +```bash |
| 33 | +npm run build # Build all blocks (runs build:free + build:pro) |
| 34 | +npm run build:free # Build all free blocks |
| 35 | +npm run build:assets # Minify CSS/JS and generate RTL |
| 36 | +npm run start # Watch mode for free blocks |
| 37 | +npm run lint:js # Lint JavaScript |
| 38 | +npm run lint:css # Lint CSS |
| 39 | +npm run format # Auto-format JS and CSS |
| 40 | +``` |
| 41 | + |
| 42 | +Individual block builds: `npm run build:[kb|articles|sections|products|search|breadcrumb|related|alerts]` |
| 43 | + |
| 44 | +Note: `package.json` also contains `build:pro` and `build:rating` scripts that reference `includes/pro/` — these are irrelevant in this repository and will fail if run here. |
| 45 | + |
| 46 | +### Distribution |
| 47 | + |
| 48 | +```bash |
| 49 | +composer zip # Create PHP distribution zip |
| 50 | +npm run zip # Create full plugin zip (wp-scripts plugin-zip) |
| 51 | +``` |
| 52 | + |
| 53 | +## Architecture |
| 54 | + |
| 55 | +### Main Bootstrap Flow |
| 56 | + |
| 57 | +1. `plugins_loaded` hook → `Main::get_instance()` (singleton) |
| 58 | +2. `Main::init()` instantiates all component handlers and registers their hooks |
| 59 | +3. Admin components only load on `is_admin()` (deferred to `init` action for translation readiness) |
| 60 | +4. `Main` has `$pro` and `$is_pro_enabled` properties defined but they are never set in this repository — those are only used by the pro plugin |
| 61 | + |
| 62 | +### Key Patterns |
| 63 | + |
| 64 | +**Autoloader** (`includes/autoloader.php`): PSR-4 style. Converts `WebberZone\Knowledge_Base\Admin\Settings` → `includes/admin/class-settings.php`. |
| 65 | + |
| 66 | +**Hook Registry** (`includes/util/class-hook-registry.php`): Custom wrapper around WordPress actions/filters with duplicate prevention and closure support. All components register hooks through this instead of calling `add_action()`/`add_filter()` directly. |
| 67 | + |
| 68 | +**Settings**: Global `$wzkb_settings` populated at plugin load. Read via `wzkb_get_option( $key )` or `wzkb_get_settings()`. Settings page in `includes/admin/class-settings.php`. Stored as a single serialized array under option key `wzkb_settings`. All settings filters use the prefix `wzkb_` (e.g. `wzkb_get_option_{$key}`). |
| 69 | + |
| 70 | +**Caching** (`includes/util/class-cache.php`): Term meta-based caching (not transients) with expiry timestamps. AJAX endpoint for admin cache clearing. |
| 71 | + |
| 72 | +**Free/Pro coexistence**: The plugin includes deactivation logic in `knowledgebase.php` — activating either the free or pro plugin automatically deactivates the other and shows an admin notice. |
| 73 | + |
| 74 | +### Component Map |
| 75 | + |
| 76 | +| Directory | Responsibility | |
| 77 | +|---|---| |
| 78 | +| `includes/admin/` | Settings UI, columns, wizard, notices, activation | |
| 79 | +| `includes/frontend/` | Templates, display, shortcodes, styles, search, breadcrumbs, related articles, feeds, patterns | |
| 80 | +| `includes/blocks/` | 8 free Gutenberg blocks (React in `src/`, compiled to `build/`) | |
| 81 | +| `includes/rest/` | REST API under `/wzkb/v1/` namespace | |
| 82 | +| `includes/widgets/` | 4 classic WordPress widgets (Articles, Sections, Breadcrumb, Products) | |
| 83 | +| `includes/util/` | Hook registry, caching utilities, helpers | |
| 84 | + |
| 85 | +### Block Development |
| 86 | + |
| 87 | +Blocks are in `includes/blocks/src/[block-name]/`. Each block has its own `block.json`, React `edit.js`, and server-side render via PHP. After editing block source, run `npm run build:[block-name]` — never edit files in `build/` directly. |
| 88 | + |
| 89 | +### Public Helper Functions |
| 90 | + |
| 91 | +`includes/functions.php` exposes the plugin's public API. Key functions: |
| 92 | +- `wzkb_knowledge()` — render the full KB output |
| 93 | +- `wzkb_get_option( $key )` / `wzkb_get_settings()` — read settings (prefer over `get_option()` directly) |
| 94 | +- `wzkb_get_breadcrumb()`, `wzkb_get_search_form()`, `wzkb_get_alert()`, `wzkb_related_articles()` — frontend rendering helpers |
| 95 | +- `wzkb_get_the_post_thumbnail()` — thumbnail retrieval (supports ACF image fields) |
| 96 | +- `wzkb_get_kb_url()`, `wzkb_get_product_sections_list()`, `wzkb_get_term_hierarchy_path()` — URL and taxonomy helpers |
| 97 | + |
| 98 | +### REST API |
| 99 | + |
| 100 | +Endpoints under `/wzkb/v1/`: `/sections` (product sections), `/knowledgebase` (list), `/knowledgebase/{id}` (single). Responses are object-cached under group `wzkb_rest` (300 s TTL); cache is invalidated on post save/delete and term changes. |
| 101 | + |
| 102 | +## Code Quality Configuration |
| 103 | + |
| 104 | +- **PHPCS**: `phpcs.xml.dist` — WordPress coding standards |
| 105 | +- **PHPStan**: `phpstan.neon.dist` — Level 5 strict analysis; baseline in `phpstan-baseline.neon` |
| 106 | +- **PHPUnit**: `phpunit.xml.dist` — test configuration, tests in `phpunit/tests/` |
0 commit comments