Skip to content

Commit e8de3cc

Browse files
mrabbaniclaude
andauthored
Add BaseSettingsRESTController for plugin-ui settings (#3)
* Add BaseSettingsRESTController for schema-driven settings management Introduces an abstract REST controller compatible with @wedevs/plugin-ui <Settings> component. Includes variant-aware validation and sanitization, permission checks with WP_Error, deep-merge persistence to wp_options, and comprehensive apply_filters/do_action hooks for extensibility. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * Add Settings controller documentation to developer guide Documents BaseSettingsRESTController usage: creating a controller, defining schemas, supported field variants, translatable messages, extending settings via hooks, and the full hook reference table. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * Add CLAUDE.md config and exclude dev files from composer exports Adds project context for Claude Code, .gitattributes with export-ignore for CLAUDE.md, .claude/, tests/, docs/, and config files so consumer plugins don't receive them via composer install. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * Fix PHPCS violations in BaseSettingsRESTController Add file doc comment, fix Yoda conditions, multi-line function call formatting, short ternary usage, and missing doc comment descriptions. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * Fix number sanitization to preserve decimal values Use floatval() for decimal numbers and intval() for integers instead of always truncating with intval(). Also remove file doc comment. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * Add file doc comment to BaseSettingsRESTController Required by PHPCS Squiz.Commenting.FileComment rule. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 47d86d1 commit e8de3cc

5 files changed

Lines changed: 1049 additions & 2 deletions

File tree

.gitattributes

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Exclude from composer archive/install (export-ignore)
2+
/.gitattributes export-ignore
3+
/.gitignore export-ignore
4+
/CLAUDE.md export-ignore
5+
/.claude/ export-ignore
6+
/tests/ export-ignore
7+
/docs/ export-ignore
8+
/.phpcs.xml.dist export-ignore
9+
/phpunit.xml export-ignore
10+
/phpunit.xml.dist export-ignore

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
composer.lock
33
.phpunit.cache/
44
.phpunit.result.cache
5+
.claude/

CLAUDE.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# WPKit - Claude Code Configuration
2+
3+
## Project Overview
4+
5+
**wedevs/wp-kit** is a standalone WordPress PHP toolkit providing DataLayer, Cache, Migration, Admin Notification, and Settings components. It is a Composer library consumed by WordPress plugins (e.g., Dokan). It has no WooCommerce dependency.
6+
7+
- **Namespace:** `WeDevs\WPKit\`
8+
- **Source:** `src/`
9+
- **Tests:** `tests/phpunit/tests/`
10+
- **Docs:** `docs/developer-guide.md`
11+
- **PHP:** 7.4+
12+
13+
## Architecture
14+
15+
- This is a **library package**, not a plugin. It must never hardcode text domains, plugin slugs, or assume a specific consumer.
16+
- All translatable strings must be overridable by consumers via methods or filters. Never use `__()` or `esc_html__()` directly — provide overridable methods instead.
17+
- All WordPress hooks use the consumer-provided prefix (e.g., `option_prefix`). No library-level hook prefixes.
18+
- Classes are abstract base classes meant to be extended by consumer plugins.
19+
20+
## Coding Standards
21+
22+
- Follow WordPress Coding Standards (WPCS). Run `composer phpcs` to check.
23+
- Use WordPress PHP functions for sanitization (`sanitize_text_field`, `sanitize_key`, `absint`, etc.) and escaping (`esc_html`, `esc_attr`, etc.).
24+
- Use tabs for indentation (WordPress standard).
25+
- PHPDoc blocks on all public and protected methods.
26+
- Type hints on parameters and return types where PHP 7.4 allows.
27+
28+
## Key Conventions
29+
30+
- **Hooks:** Use `apply_filters` and `do_action` at key extension points. Namespace hooks with the consumer's prefix property (e.g., `"{$this->option_prefix}_settings_schema"`).
31+
- **REST Controllers:** Extend `WP_REST_Controller`. Permission callbacks must return `true` or `WP_Error` (never bare `false`). Provide overridable methods for error messages.
32+
- **Options Storage:** Use `wp_options` with consumer-defined prefixes. Always `sanitize_key()` user-provided keys before building option names.
33+
- **Validation:** Provide sensible default validation. Allow consumers to override via subclass methods and filters.
34+
35+
## Commands
36+
37+
- `composer test` — Run PHPUnit tests
38+
- `composer phpcs` — Run PHP CodeSniffer
39+
- `composer phpcbf` — Auto-fix coding standards
40+
- `composer lint` — Alias for phpcs
41+
42+
## Testing
43+
44+
- Tests use PHPUnit 9/10 with Brain\Monkey for WordPress function mocking.
45+
- Test namespace: `WeDevs\WPKit\Tests\`
46+
- Test directory: `tests/phpunit/tests/`
47+
48+
## File Structure
49+
50+
```
51+
src/
52+
├── AdminNotification/ # Notice system (providers, manager, REST)
53+
├── Cache/ # Caching layer
54+
├── DataLayer/ # Models, DataStores, SQL builder
55+
├── Migration/ # Schema migrations, background processing
56+
└── Settings/ # Schema-driven settings REST controller
57+
docs/
58+
└── developer-guide.md # Comprehensive developer documentation
59+
tests/
60+
└── phpunit/
61+
└── tests/ # PHPUnit test files
62+
```

0 commit comments

Comments
 (0)