From ad8b27e94dd2fedd00daa6d917b0d241d9d33c8c Mon Sep 17 00:00:00 2001 From: Hideaki Terai Date: Wed, 2 Jul 2025 20:12:09 +0900 Subject: [PATCH 1/3] Add CLAUDE.md --- CLAUDE.md | 98 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 CLAUDE.md diff --git a/CLAUDE.md b/CLAUDE.md new file mode 100644 index 0000000..7836a27 --- /dev/null +++ b/CLAUDE.md @@ -0,0 +1,98 @@ +# CLAUDE.md + +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. + +## Project Overview + +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. + +## Development Commands + +### Setup +```bash +# Copy environment file and start Docker containers +cp wp.env.sample wp.env +docker-compose up -d +``` + +### Testing +```bash +# Run unit tests +./tests/run.sh + +# Run tests using Docker +docker-compose run --rm wordpress bash -c "cd /var/www/html/wp-content/plugins/colormeshop-wp-plugin && ./vendor/bin/phpunit" +``` + +### Code Quality +```bash +# Check coding standards (WordPress Coding Standards) +docker-compose run composer vendor/bin/phpcs --standard=ruleset.xml + +# Auto-fix code formatting issues +docker-compose run composer vendor/bin/phpcbf --standard=ruleset.xml +``` + +### Build and Deployment +```bash +# Generate API client from ColorMe Shop API +make generate_api_client + +# Build plugin zip file for distribution +make + +# Update autoload classmap after adding new classes +docker-compose run --rm composer dump-autoload +``` + +## Architecture + +### Core Components + +- **Plugin**: Main plugin class that handles WordPress hooks, shortcode registration, and DI container setup +- **Admin**: WordPress admin interface for plugin configuration (OAuth settings, product page ID) +- **Models**: Data models for Settings and Sitemap generation +- **API Layer**: Wrapper around generated Swagger API client for ColorMe Shop API +- **Shortcodes**: WordPress shortcodes for displaying products, images, options, and cart buttons + +### Key Files + +- `src/class-plugin.php`: Main plugin orchestrator with DI container +- `src/class-admin.php`: WordPress admin interface +- `src/Swagger/`: Auto-generated API client from ColorMe Shop API +- `src/shortcodes/`: WordPress shortcodes for product display +- `src/models/`: Data models and business logic +- `templates/`: PHP templates for rendering + +### DI Container Structure + +The plugin uses Pimple for dependency injection. Key services: +- `oauth2_client`: OAuth2 authentication client +- `api.product_api`: Product API wrapper +- `model.setting`: Plugin settings management +- `swagger.configuration`: API configuration with access token + +### Database Integration + +Settings are stored using WordPress options API under the key `colorme_wp_settings`. + +### API Integration + +- Uses generated Swagger client for ColorMe Shop API v1 +- Implements OAuth2 flow with access token storage +- Provides abstraction layer over raw API responses +- Includes VCR fixtures for testing API interactions + +### WordPress Integration + +- Registers custom rewrite rules for product pages and sitemaps +- Uses WordPress hooks for title filtering and template redirection +- Follows WordPress coding standards and file naming conventions +- Supports mobile detection and custom templates + +## Testing + +- PHPUnit with WordPress test framework +- VCR for recording and replaying HTTP requests +- Separate test classes mirror the source structure +- Coverage reporting excludes generated Swagger code From a2a5531bbe9c1d12b86bfb818e8f81aa1137787d Mon Sep 17 00:00:00 2001 From: Hideaki Terai Date: Fri, 4 Jul 2025 10:05:32 +0900 Subject: [PATCH 2/3] =?UTF-8?q?=E3=82=B3=E3=83=A1=E3=83=B3=E3=83=88?= =?UTF-8?q?=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CLAUDE.md | 146 +++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 107 insertions(+), 39 deletions(-) diff --git a/CLAUDE.md b/CLAUDE.md index 7836a27..2307271 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -1,98 +1,166 @@ # CLAUDE.md -This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. +This document provides guidance for Claude Code (claude.ai/code) **and developers** working with code in this repository. + +--- ## Project Overview -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. +This is a WordPress plugin that integrates with the ColorMe Shop (カラーミーショップ) API to display product information and generate product pages within WordPress. +It uses OAuth2 authentication and provides WordPress shortcodes for embedding product details. + +--- ## Development Commands ### Setup + ```bash # Copy environment file and start Docker containers cp wp.env.sample wp.env docker-compose up -d + +# Install PHP dependencies via Composer +docker-compose run --rm composer install ``` +> After setup, activate the plugin from the WordPress admin dashboard. + +--- + ### Testing + ```bash # Run unit tests ./tests/run.sh -# Run tests using Docker -docker-compose run --rm wordpress bash -c "cd /var/www/html/wp-content/plugins/colormeshop-wp-plugin && ./vendor/bin/phpunit" +# Run tests using Docker (WordPress environment) +docker-compose run --rm wordpress bash -c "cd /var/www/html/wp-content/plugins/colormeshop-wp-plugin && ./vendor/bin/phpunit" ``` +- Tests use the WordPress test framework and VCR for recording/replaying HTTP requests +- VCR fixtures are stored in `tests/fixtures/` +- New API interactions can be recorded by switching VCR to record mode +- Coverage reports exclude generated Swagger code + +--- + ### Code Quality + ```bash # Check coding standards (WordPress Coding Standards) docker-compose run composer vendor/bin/phpcs --standard=ruleset.xml -# Auto-fix code formatting issues +# Auto-fix formatting issues docker-compose run composer vendor/bin/phpcbf --standard=ruleset.xml ``` +> Note: This plugin follows WordPress coding standards and naming conventions. +> Claude should preserve these when suggesting code changes. + +--- + ### Build and Deployment + ```bash -# Generate API client from ColorMe Shop API +# Generate API client from ColorMe Shop API (Swagger/OpenAPI) make generate_api_client -# Build plugin zip file for distribution +# Build plugin zip for distribution (output: ./dist/colormeshop-wp-plugin.zip) make # Update autoload classmap after adding new classes docker-compose run --rm composer dump-autoload ``` +--- + ## Architecture ### Core Components -- **Plugin**: Main plugin class that handles WordPress hooks, shortcode registration, and DI container setup -- **Admin**: WordPress admin interface for plugin configuration (OAuth settings, product page ID) -- **Models**: Data models for Settings and Sitemap generation -- **API Layer**: Wrapper around generated Swagger API client for ColorMe Shop API -- **Shortcodes**: WordPress shortcodes for displaying products, images, options, and cart buttons +- **Plugin**: Main orchestrator that registers hooks, shortcodes, and DI container +- **Admin**: WordPress admin UI for plugin settings (OAuth credentials, page IDs) +- **Models**: Internal models for plugin settings and sitemap generation +- **API Layer**: Wrapper around Swagger-generated client for ColorMe Shop API +- **Shortcodes**: Functions to embed product data, images, cart buttons via shortcodes + +--- + +### Key File Structure -### Key Files +| Path | Purpose | +|-----------------------------|--------------------------------------------| +| `src/class-plugin.php` | Plugin bootstrap and DI setup | +| `src/class-admin.php` | Admin UI and setting page | +| `src/Swagger/` | Auto-generated ColorMe API client | +| `src/shortcodes/` | Shortcode definitions | +| `src/models/` | Data models and logic | +| `templates/` | PHP templates used in rendering | -- `src/class-plugin.php`: Main plugin orchestrator with DI container -- `src/class-admin.php`: WordPress admin interface -- `src/Swagger/`: Auto-generated API client from ColorMe Shop API -- `src/shortcodes/`: WordPress shortcodes for product display -- `src/models/`: Data models and business logic -- `templates/`: PHP templates for rendering +> Note: Filenames like `class-plugin.php` follow WordPress conventions — do not rename them. -### DI Container Structure +--- -The plugin uses Pimple for dependency injection. Key services: -- `oauth2_client`: OAuth2 authentication client -- `api.product_api`: Product API wrapper -- `model.setting`: Plugin settings management -- `swagger.configuration`: API configuration with access token +### Dependency Injection (DI) + +- The plugin uses [Pimple](https://pimple.symfony.com/) as a DI container. +- Key service bindings: + - `oauth2_client`: OAuth2 client instance + - `api.product_api`: Product API abstraction + - `model.setting`: WordPress options access wrapper + - `swagger.configuration`: Swagger client configuration (access token injected) + +--- ### Database Integration -Settings are stored using WordPress options API under the key `colorme_wp_settings`. +- Plugin settings are stored using the WordPress Options API under the key: + +``` +colorme_wp_settings +``` + +--- ### API Integration -- Uses generated Swagger client for ColorMe Shop API v1 -- Implements OAuth2 flow with access token storage -- Provides abstraction layer over raw API responses -- Includes VCR fixtures for testing API interactions +- Uses Swagger client generated from ColorMe Shop API v1 +- Authenticated via OAuth2 access token (user-provided) +- Abstraction layer wraps raw API client for safer access +- VCR (PHP-VCR) used to record HTTP interactions during tests + +--- ### WordPress Integration -- Registers custom rewrite rules for product pages and sitemaps -- Uses WordPress hooks for title filtering and template redirection -- Follows WordPress coding standards and file naming conventions -- Supports mobile detection and custom templates +- Custom rewrite rules for product pages and sitemap XML +- Uses hooks for title filtering and template redirection +- Supports device detection for rendering mobile-specific views +- Template override support via standard WordPress theme hierarchy + +--- + +## Claude Usage Tips + +- When modifying shortcodes, ensure arguments are processed using `shortcode_atts()` +- Always retrieve settings via the `model.setting` service rather than accessing options directly +- When adding templates, place them in the `templates/` directory and reference with `include()` +- When working on OAuth2 logic, ensure secure token storage using WP options and proper sanitization +- Avoid modifying files in `src/Swagger/` directly — these are auto-generated + +--- + +## Appendix + +### External Dependencies + +- WordPress ≥ 5.0 +- Composer (for dependency management) +- Docker (for development environment) + +--- -## Testing +## License -- PHPUnit with WordPress test framework -- VCR for recording and replaying HTTP requests -- Separate test classes mirror the source structure -- Coverage reporting excludes generated Swagger code +See `LICENSE` file in the root of this repository. From 35a05b7c2934347eae72ce482e5964b5a2dc9c56 Mon Sep 17 00:00:00 2001 From: Hideaki Terai Date: Fri, 4 Jul 2025 19:12:28 +0900 Subject: [PATCH 3/3] Fix CI: Install subversion for WordPress test setup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The CI was failing because the bin/install-wp-tests.sh script requires svn command to checkout WordPress test files, but subversion is not installed by default in GitHub Actions Ubuntu environment. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- .github/workflows/php.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index b41f359..85c41d7 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -52,5 +52,8 @@ jobs: - run: composer install + - name: Install subversion + run: sudo apt-get update && sudo apt-get install -y subversion + - run: bin/install-wp-tests.sh test root root-password 127.0.0.1:${{ job.services.mysql.ports['3306'] }} - run: ./vendor/bin/phpunit