|
1 | 1 | # CLAUDE.md |
2 | 2 |
|
3 | | -This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 3 | +This document provides guidance for Claude Code (claude.ai/code) **and developers** working with code in this repository. |
| 4 | + |
| 5 | +--- |
4 | 6 |
|
5 | 7 | ## Project Overview |
6 | 8 |
|
7 | | -This is a WordPress plugin that integrates with ColorMe Shop (カラーミーショップ) API to display product information and generate product pages within WordPress. The plugin uses OAuth2 authentication and provides shortcodes for embedding product information. |
| 9 | +This is a WordPress plugin that integrates with the ColorMe Shop (カラーミーショップ) API to display product information and generate product pages within WordPress. |
| 10 | +It uses OAuth2 authentication and provides WordPress shortcodes for embedding product details. |
| 11 | + |
| 12 | +--- |
8 | 13 |
|
9 | 14 | ## Development Commands |
10 | 15 |
|
11 | 16 | ### Setup |
| 17 | + |
12 | 18 | ```bash |
13 | 19 | # Copy environment file and start Docker containers |
14 | 20 | cp wp.env.sample wp.env |
15 | 21 | docker-compose up -d |
| 22 | + |
| 23 | +# Install PHP dependencies via Composer |
| 24 | +docker-compose run --rm composer install |
16 | 25 | ``` |
17 | 26 |
|
| 27 | +> After setup, activate the plugin from the WordPress admin dashboard. |
| 28 | +
|
| 29 | +--- |
| 30 | + |
18 | 31 | ### Testing |
| 32 | + |
19 | 33 | ```bash |
20 | 34 | # Run unit tests |
21 | 35 | ./tests/run.sh |
22 | 36 |
|
23 | | -# Run tests using Docker |
24 | | -docker-compose run --rm wordpress bash -c "cd /var/www/html/wp-content/plugins/colormeshop-wp-plugin && ./vendor/bin/phpunit" |
| 37 | +# Run tests using Docker (WordPress environment) |
| 38 | +docker-compose run --rm wordpress bash -c "cd /var/www/html/wp-content/plugins/colormeshop-wp-plugin && ./vendor/bin/phpunit" |
25 | 39 | ``` |
26 | 40 |
|
| 41 | +- Tests use the WordPress test framework and VCR for recording/replaying HTTP requests |
| 42 | +- VCR fixtures are stored in `tests/fixtures/` |
| 43 | +- New API interactions can be recorded by switching VCR to record mode |
| 44 | +- Coverage reports exclude generated Swagger code |
| 45 | + |
| 46 | +--- |
| 47 | + |
27 | 48 | ### Code Quality |
| 49 | + |
28 | 50 | ```bash |
29 | 51 | # Check coding standards (WordPress Coding Standards) |
30 | 52 | docker-compose run composer vendor/bin/phpcs --standard=ruleset.xml |
31 | 53 |
|
32 | | -# Auto-fix code formatting issues |
| 54 | +# Auto-fix formatting issues |
33 | 55 | docker-compose run composer vendor/bin/phpcbf --standard=ruleset.xml |
34 | 56 | ``` |
35 | 57 |
|
| 58 | +> Note: This plugin follows WordPress coding standards and naming conventions. |
| 59 | +> Claude should preserve these when suggesting code changes. |
| 60 | +
|
| 61 | +--- |
| 62 | + |
36 | 63 | ### Build and Deployment |
| 64 | + |
37 | 65 | ```bash |
38 | | -# Generate API client from ColorMe Shop API |
| 66 | +# Generate API client from ColorMe Shop API (Swagger/OpenAPI) |
39 | 67 | make generate_api_client |
40 | 68 |
|
41 | | -# Build plugin zip file for distribution |
| 69 | +# Build plugin zip for distribution (output: ./dist/colormeshop-wp-plugin.zip) |
42 | 70 | make |
43 | 71 |
|
44 | 72 | # Update autoload classmap after adding new classes |
45 | 73 | docker-compose run --rm composer dump-autoload |
46 | 74 | ``` |
47 | 75 |
|
| 76 | +--- |
| 77 | + |
48 | 78 | ## Architecture |
49 | 79 |
|
50 | 80 | ### Core Components |
51 | 81 |
|
52 | | -- **Plugin**: Main plugin class that handles WordPress hooks, shortcode registration, and DI container setup |
53 | | -- **Admin**: WordPress admin interface for plugin configuration (OAuth settings, product page ID) |
54 | | -- **Models**: Data models for Settings and Sitemap generation |
55 | | -- **API Layer**: Wrapper around generated Swagger API client for ColorMe Shop API |
56 | | -- **Shortcodes**: WordPress shortcodes for displaying products, images, options, and cart buttons |
| 82 | +- **Plugin**: Main orchestrator that registers hooks, shortcodes, and DI container |
| 83 | +- **Admin**: WordPress admin UI for plugin settings (OAuth credentials, page IDs) |
| 84 | +- **Models**: Internal models for plugin settings and sitemap generation |
| 85 | +- **API Layer**: Wrapper around Swagger-generated client for ColorMe Shop API |
| 86 | +- **Shortcodes**: Functions to embed product data, images, cart buttons via shortcodes |
| 87 | + |
| 88 | +--- |
| 89 | + |
| 90 | +### Key File Structure |
57 | 91 |
|
58 | | -### Key Files |
| 92 | +| Path | Purpose | |
| 93 | +|-----------------------------|--------------------------------------------| |
| 94 | +| `src/class-plugin.php` | Plugin bootstrap and DI setup | |
| 95 | +| `src/class-admin.php` | Admin UI and setting page | |
| 96 | +| `src/Swagger/` | Auto-generated ColorMe API client | |
| 97 | +| `src/shortcodes/` | Shortcode definitions | |
| 98 | +| `src/models/` | Data models and logic | |
| 99 | +| `templates/` | PHP templates used in rendering | |
59 | 100 |
|
60 | | -- `src/class-plugin.php`: Main plugin orchestrator with DI container |
61 | | -- `src/class-admin.php`: WordPress admin interface |
62 | | -- `src/Swagger/`: Auto-generated API client from ColorMe Shop API |
63 | | -- `src/shortcodes/`: WordPress shortcodes for product display |
64 | | -- `src/models/`: Data models and business logic |
65 | | -- `templates/`: PHP templates for rendering |
| 101 | +> Note: Filenames like `class-plugin.php` follow WordPress conventions — do not rename them. |
66 | 102 |
|
67 | | -### DI Container Structure |
| 103 | +--- |
68 | 104 |
|
69 | | -The plugin uses Pimple for dependency injection. Key services: |
70 | | -- `oauth2_client`: OAuth2 authentication client |
71 | | -- `api.product_api`: Product API wrapper |
72 | | -- `model.setting`: Plugin settings management |
73 | | -- `swagger.configuration`: API configuration with access token |
| 105 | +### Dependency Injection (DI) |
| 106 | + |
| 107 | +- The plugin uses [Pimple](https://pimple.symfony.com/) as a DI container. |
| 108 | +- Key service bindings: |
| 109 | + - `oauth2_client`: OAuth2 client instance |
| 110 | + - `api.product_api`: Product API abstraction |
| 111 | + - `model.setting`: WordPress options access wrapper |
| 112 | + - `swagger.configuration`: Swagger client configuration (access token injected) |
| 113 | + |
| 114 | +--- |
74 | 115 |
|
75 | 116 | ### Database Integration |
76 | 117 |
|
77 | | -Settings are stored using WordPress options API under the key `colorme_wp_settings`. |
| 118 | +- Plugin settings are stored using the WordPress Options API under the key: |
| 119 | + |
| 120 | +``` |
| 121 | +colorme_wp_settings |
| 122 | +``` |
| 123 | + |
| 124 | +--- |
78 | 125 |
|
79 | 126 | ### API Integration |
80 | 127 |
|
81 | | -- Uses generated Swagger client for ColorMe Shop API v1 |
82 | | -- Implements OAuth2 flow with access token storage |
83 | | -- Provides abstraction layer over raw API responses |
84 | | -- Includes VCR fixtures for testing API interactions |
| 128 | +- Uses Swagger client generated from ColorMe Shop API v1 |
| 129 | +- Authenticated via OAuth2 access token (user-provided) |
| 130 | +- Abstraction layer wraps raw API client for safer access |
| 131 | +- VCR (PHP-VCR) used to record HTTP interactions during tests |
| 132 | + |
| 133 | +--- |
85 | 134 |
|
86 | 135 | ### WordPress Integration |
87 | 136 |
|
88 | | -- Registers custom rewrite rules for product pages and sitemaps |
89 | | -- Uses WordPress hooks for title filtering and template redirection |
90 | | -- Follows WordPress coding standards and file naming conventions |
91 | | -- Supports mobile detection and custom templates |
| 137 | +- Custom rewrite rules for product pages and sitemap XML |
| 138 | +- Uses hooks for title filtering and template redirection |
| 139 | +- Supports device detection for rendering mobile-specific views |
| 140 | +- Template override support via standard WordPress theme hierarchy |
| 141 | + |
| 142 | +--- |
| 143 | + |
| 144 | +## Claude Usage Tips |
| 145 | + |
| 146 | +- When modifying shortcodes, ensure arguments are processed using `shortcode_atts()` |
| 147 | +- Always retrieve settings via the `model.setting` service rather than accessing options directly |
| 148 | +- When adding templates, place them in the `templates/` directory and reference with `include()` |
| 149 | +- When working on OAuth2 logic, ensure secure token storage using WP options and proper sanitization |
| 150 | +- Avoid modifying files in `src/Swagger/` directly — these are auto-generated |
| 151 | + |
| 152 | +--- |
| 153 | + |
| 154 | +## Appendix |
| 155 | + |
| 156 | +### External Dependencies |
| 157 | + |
| 158 | +- WordPress ≥ 5.0 |
| 159 | +- Composer (for dependency management) |
| 160 | +- Docker (for development environment) |
| 161 | + |
| 162 | +--- |
92 | 163 |
|
93 | | -## Testing |
| 164 | +## License |
94 | 165 |
|
95 | | -- PHPUnit with WordPress test framework |
96 | | -- VCR for recording and replaying HTTP requests |
97 | | -- Separate test classes mirror the source structure |
98 | | -- Coverage reporting excludes generated Swagger code |
| 166 | +See `LICENSE` file in the root of this repository. |
0 commit comments