Skip to content

Commit 533dedc

Browse files
authored
Merge pull request #226 from w3bdesign/develop
Add AGENTS.md with plugin architecture guidance
2 parents c68872d + c492c99 commit 533dedc

File tree

8 files changed

+83
-4
lines changed

8 files changed

+83
-4
lines changed

.github/workflows/phpcs-autofix.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ jobs:
4242
run: vendor/bin/phpcbf --standard=phpcs.xml --extensions=php . || true
4343

4444
- name: Commit and Push PHPCBF fixes
45+
env:
46+
HEAD_REF: ${{ github.head_ref }}
47+
REF_NAME: ${{ github.ref_name }}
4548
run: |
4649
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
4750
git config --local user.name "github-actions[bot]"
@@ -66,11 +69,10 @@ jobs:
6669
# Determine the branch to push to
6770
# For PRs, github.head_ref is the source branch name.
6871
# For workflow_dispatch, github.ref_name is the branch the workflow was run on.
69-
BRANCH_NAME=""
70-
if [[ -n "${{ github.head_ref }}" ]]; then
71-
BRANCH_NAME="${{ github.head_ref }}"
72+
if [[ -n "$HEAD_REF" ]]; then
73+
BRANCH_NAME="$HEAD_REF"
7274
else
73-
BRANCH_NAME="${{ github.ref_name }}"
75+
BRANCH_NAME="$REF_NAME"
7476
fi
7577
7678
echo "Pushing changes to branch: $BRANCH_NAME"

.github/workflows/phpcs.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
on: pull_request
22

33
name: Inspections
4+
5+
permissions:
6+
contents: read
7+
pull-requests: write
8+
checks: write
9+
410
jobs:
511
runPHPCSInspection:
612
name: Run PHPCS inspection

.roo/rules-architect/AGENTS.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Project Architecture Rules (Non-Obvious Only)
2+
3+
- Plugin follows WordPress plugin architecture, not MVC - all classes are utility/service classes
4+
- Singleton pattern required for main class to prevent multiple AJAX handler registrations
5+
- No dependency injection - classes access WordPress globals and functions directly
6+
- AJAX endpoints registered globally but handled by specific class methods (tight coupling by design)
7+
- Plugin settings stored as individual prefixed options (not single serialized array for performance)
8+
- Activation/deactivation hooks in main file, but actual logic delegated to class methods
9+
- No autoloader - classes included manually via `require_once` in main file
10+
- WordPress hooks used for integration points, not observer patterns or events
11+
- Algolia client instantiated fresh each time (no connection pooling or reuse)
12+
- Product data transformation happens in loops without caching (potential performance bottleneck)

.roo/rules-ask/AGENTS.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Project Documentation Rules (Non-Obvious Only)
2+
3+
- Main plugin file (`algolia-woo-indexer.php`) contains WordPress plugin headers but core logic is in `classes/` directory
4+
- `DOCS/repository_context.txt` contains comprehensive project context not found in README
5+
- Class files use WordPress naming convention (`class-name.php`) but implement PHP namespacing patterns
6+
- Plugin functionality is split across 4 separate classes with specific responsibilities (not MVC pattern)
7+
- Settings structure documented in code comments, not external docs
8+
- Composer is used for development tools only (PHPCS), not for plugin dependencies
9+
- Translation files in `languages/` directory use WordPress translation system, not standard gettext
10+
- Plugin header mentions PHP 8.1+ but error messages reference PHP 7.2+ (outdated messaging)
11+
- Constants are scattered: some in main class, others in `Send_Products` class
12+
- Product categories are required - plugin silently skips products without categories (undocumented behavior)

.roo/rules-code/AGENTS.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Project Coding Rules (Non-Obvious Only)
2+
3+
- Always use singleton pattern for main plugin class via `get_instance()` method (not direct instantiation)
4+
- AJAX handlers must call `Verify_Nonces::verify_nonce()` instead of WordPress standard `wp_verify_nonce()` for consistency
5+
- Product data uses custom field mapping in `Send_Products::prepare_product_data()` - don't rely on WooCommerce defaults
6+
- Settings access must go through main class wrapper methods, not direct `get_option()` calls
7+
- Error responses use `wp_send_json_error()` with specific error codes matching the class error handling patterns
8+
- Plugin text domain is `algolia-woo-indexer` - must match directory name exactly for translations
9+
- Constants are defined in `Send_Products` class: `ALGOWOO_DB_OPTION`, `ALGOLIA_API_KEY`, `INDEX_NAME`, etc.
10+
- Database options use prefix pattern: `ALGOWOO_DB_OPTION . SUFFIX` (e.g., `_algolia_woo_indexer_application_id`)
11+
- All database operations assume WooCommerce is active - no fallback checks in core functionality
12+
- Product price extraction differs by type: use `get_variation_sale_price('min', true)` for variable products

.roo/rules-debug/AGENTS.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Project Debug Rules (Non-Obvious Only)
2+
3+
- WordPress debug logs are only location for error output - plugin doesn't write to separate log files
4+
- AJAX debugging requires checking both browser network tab AND WordPress debug log (errors split between both)
5+
- Plugin activation errors only visible in WordPress admin, not in server logs
6+
- Requirements check failures prevent plugin activation silently - check `Check_Requirements` class output
7+
- Algolia API errors are caught and logged but don't prevent page loading (silent failures possible)
8+
- Settings validation errors only show in WordPress admin notices, not AJAX responses
9+
- Uninstall process leaves no traces if `WP_UNINSTALL_PLUGIN` constant isn't properly set
10+
- Algolia connection test happens via `listApiKeys()` call - not a ping or simple connection check
11+
- Product indexing failures return `NullResponse` class - check `get_class($result)` for this specific string

AGENTS.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# AGENTS.md
2+
3+
This file provides guidance to agents when working with code in this repository.
4+
5+
## WordPress Plugin Architecture (Non-obvious patterns)
6+
7+
- Plugin initialization happens in two phases: main file registers hooks, then `Algolia_Woo_Indexer` class handles functionality via singleton pattern with `get_instance()`
8+
- All AJAX/form actions use custom nonce verification through `Verify_Nonces` class, not standard WordPress `wp_verify_nonce()` directly
9+
- Product indexing is batched via `Send_Products::send_products_to_algolia()` - processes arrays, not individual products
10+
- Settings stored as individual prefixed options (`ALGOWOO_DB_OPTION . SUFFIX`), accessed via wrapper methods, not direct `get_option()` calls
11+
- Constants defined in `Send_Products` class, not main file - `ALGOWOO_DB_OPTION`, `ALGOLIA_API_KEY`, etc.
12+
- Plugin requires PHP 8.1+ and WordPress 6.1+ (despite error message mentioning 7.2/5.0)
13+
- Uninstall process in `uninstall.php` requires `WP_UNINSTALL_PLUGIN` constant check before executing
14+
- All classes use manual loading via `require_once` - no autoloader used
15+
- Image extraction uses regex parsing: `preg_match('/<img(.*)src(.*)=(.*)"(.*)"/U', $product->get_image(), $result)`
16+
- WooCommerce product price logic differs by type: `simple` vs `variable` products use different getter methods
17+
18+
## Development Commands
19+
20+
- Run PHP_CodeSniffer: `vendor/bin/phpcs` (WordPress-Core, WordPress-Docs, WordPress-Extra rules)
21+
- Fix coding standards: `vendor/bin/phpcbf`
22+
- PHPCS excludes: file naming rules (`WordPress.Files.FileName.*`)
23+
- Plugin must be tested within WordPress environment (no standalone testing)

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ Note that this plugin is designed for developers developing headless Ecommerce s
3232
- All variables are properly sanitized to ensure that no security issues are present
3333
- AI Repository documentation located in `/DOCS/repository_context.txt`
3434
- PHPCS Autofix with Github actions
35+
- AI Assistant guidance files (`AGENTS.md` and `.roo/rules-*/AGENTS.md`) for immediate productivity with AI coding tools
3536

3637
## Requirements
3738

0 commit comments

Comments
 (0)