|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This document provides guidance for Claude Code (claude.ai/code) **and developers** working with code in this repository. |
| 4 | + |
| 5 | +--- |
| 6 | + |
| 7 | +## Project Overview |
| 8 | + |
| 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 | +--- |
| 13 | + |
| 14 | +## Development Commands |
| 15 | + |
| 16 | +### Setup |
| 17 | + |
| 18 | +```bash |
| 19 | +# Copy environment file and start Docker containers |
| 20 | +cp wp.env.sample wp.env |
| 21 | +docker-compose up -d |
| 22 | + |
| 23 | +# Install PHP dependencies via Composer |
| 24 | +docker-compose run --rm composer install |
| 25 | +``` |
| 26 | + |
| 27 | +> After setup, activate the plugin from the WordPress admin dashboard. |
| 28 | +
|
| 29 | +--- |
| 30 | + |
| 31 | +### Testing |
| 32 | + |
| 33 | +```bash |
| 34 | +# Run unit tests |
| 35 | +./tests/run.sh |
| 36 | + |
| 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" |
| 39 | +``` |
| 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 | + |
| 48 | +### Code Quality |
| 49 | + |
| 50 | +```bash |
| 51 | +# Check coding standards (WordPress Coding Standards) |
| 52 | +docker-compose run composer vendor/bin/phpcs --standard=ruleset.xml |
| 53 | + |
| 54 | +# Auto-fix formatting issues |
| 55 | +docker-compose run composer vendor/bin/phpcbf --standard=ruleset.xml |
| 56 | +``` |
| 57 | + |
| 58 | +> Note: This plugin follows WordPress coding standards and naming conventions. |
| 59 | +> Claude should preserve these when suggesting code changes. |
| 60 | +
|
| 61 | +--- |
| 62 | + |
| 63 | +### Build and Deployment |
| 64 | + |
| 65 | +```bash |
| 66 | +# Generate API client from ColorMe Shop API (Swagger/OpenAPI) |
| 67 | +make generate_api_client |
| 68 | + |
| 69 | +# Build plugin zip for distribution (output: ./dist/colormeshop-wp-plugin.zip) |
| 70 | +make |
| 71 | + |
| 72 | +# Update autoload classmap after adding new classes |
| 73 | +docker-compose run --rm composer dump-autoload |
| 74 | +``` |
| 75 | + |
| 76 | +--- |
| 77 | + |
| 78 | +## Architecture |
| 79 | + |
| 80 | +### Core Components |
| 81 | + |
| 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 |
| 91 | + |
| 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 | |
| 100 | + |
| 101 | +> Note: Filenames like `class-plugin.php` follow WordPress conventions — do not rename them. |
| 102 | +
|
| 103 | +--- |
| 104 | + |
| 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 | +--- |
| 115 | + |
| 116 | +### Database Integration |
| 117 | + |
| 118 | +- Plugin settings are stored using the WordPress Options API under the key: |
| 119 | + |
| 120 | +``` |
| 121 | +colorme_wp_settings |
| 122 | +``` |
| 123 | + |
| 124 | +--- |
| 125 | + |
| 126 | +### API Integration |
| 127 | + |
| 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 | +--- |
| 134 | + |
| 135 | +### WordPress Integration |
| 136 | + |
| 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 | +--- |
| 163 | + |
| 164 | +## License |
| 165 | + |
| 166 | +See `LICENSE` file in the root of this repository. |
0 commit comments