@ai-kits/wp-ag-kit 1.0.2 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -8
- package/STRUCTURE.md +9 -7
- package/agents/woocommerce-expert.md +32 -0
- package/agents/wordpress-expert.md +4 -2
- package/package.json +5 -3
- package/skills/woocommerce/SKILL.md +54 -0
- package/skills/woocommerce/references/backend-dev-guide.md +44 -0
- package/skills/woocommerce/references/code-entities.md +186 -0
- package/skills/woocommerce/references/code-quality.md +273 -0
- package/skills/woocommerce/references/code-review-guide.md +71 -0
- package/skills/woocommerce/references/coding-conventions.md +182 -0
- package/skills/woocommerce/references/copy-guidelines-guide.md +17 -0
- package/skills/woocommerce/references/data-integrity.md +164 -0
- package/skills/woocommerce/references/dependency-injection.md +102 -0
- package/skills/woocommerce/references/dev-cycle-guide.md +32 -0
- package/skills/woocommerce/references/file-entities.md +73 -0
- package/skills/woocommerce/references/hooks.md +87 -0
- package/skills/woocommerce/references/js-i18n-patterns.md +298 -0
- package/skills/woocommerce/references/markdown-guide.md +358 -0
- package/skills/woocommerce/references/markdown-linting.md +202 -0
- package/skills/woocommerce/references/php-i18n-patterns.md +83 -0
- package/skills/woocommerce/references/php-linting-patterns.md +304 -0
- package/skills/woocommerce/references/running-tests.md +249 -0
- package/skills/woocommerce/references/security-patterns.md +109 -0
- package/skills/woocommerce/references/sentence-case.md +177 -0
- package/skills/woocommerce/references/type-annotations.md +161 -0
- package/skills/woocommerce/references/unit-tests.md +362 -0
- package/skills/woocommerce/references/woocommerce-global-objects.md +89 -0
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# WordPress Antigravity Kit
|
|
1
|
+
# WordPress WooCommerce Antigravity Kit
|
|
2
2
|
|
|
3
3
|
**Complete WordPress development environment for Antigravity IDE**
|
|
4
4
|
|
|
@@ -18,10 +18,10 @@ wpag init
|
|
|
18
18
|
|
|
19
19
|
## 📦 What You Get
|
|
20
20
|
|
|
21
|
-
This kit provides a complete WordPress development environment for Antigravity IDE:
|
|
21
|
+
This kit provides a complete WordPress and WooCommerce development environment for Antigravity IDE:
|
|
22
22
|
|
|
23
|
-
- **
|
|
24
|
-
- **
|
|
23
|
+
- **14 WordPress and WooCommerce Skills** - Expert instruction modules for blocks, themes, plugins, performance, and more
|
|
24
|
+
- **3 Specialized Agents** - WordPress Expert, Frontend Expert, and WooCommerce Expert AI personas
|
|
25
25
|
- **2 Workflows** - Automated linting and block creation procedures
|
|
26
26
|
- **Global Rules** - GEMINI.md for consistent, high-quality behavior
|
|
27
27
|
- **Shared Resources** - WordPress/Gutenberg version maps and utility scripts
|
|
@@ -38,10 +38,10 @@ wpag init
|
|
|
38
38
|
This creates a `.agent/` folder with:
|
|
39
39
|
```
|
|
40
40
|
.agent/
|
|
41
|
-
├── agents/
|
|
42
|
-
├── workflows/
|
|
41
|
+
├── agents/ # AI personas specialized for WordPress
|
|
42
|
+
├── workflows/ # Semi-automated task procedures
|
|
43
43
|
├── rules/ # Global behavior guidelines
|
|
44
|
-
├── skills/ #
|
|
44
|
+
├── skills/ # 14 WordPress and WooCommerce instruction modules
|
|
45
45
|
└── shared/ # Version maps and utilities
|
|
46
46
|
```
|
|
47
47
|
|
|
@@ -73,6 +73,7 @@ wpag help # Show help
|
|
|
73
73
|
| `wp-playground` | WordPress Playground workflows |
|
|
74
74
|
| `wpds` | WordPress Design System |
|
|
75
75
|
| `wordpress-router` | Smart project routing |
|
|
76
|
+
| `woocommerce` | Comprehensive WooCommerce development and copy standards |
|
|
76
77
|
|
|
77
78
|
## 🤖 Specialized Agents
|
|
78
79
|
|
|
@@ -82,6 +83,9 @@ Master WordPress developer that uses all 13 skills for comprehensive WordPress d
|
|
|
82
83
|
### WordPress Frontend Expert
|
|
83
84
|
Specialist for Block Themes, Interactivity API, and modern WordPress UI/UX.
|
|
84
85
|
|
|
86
|
+
### WooCommerce Expert
|
|
87
|
+
Specialized in e-commerce architecture, checkout flows, and WooCommerce core integration.
|
|
88
|
+
|
|
85
89
|
## 🔄 Workflows
|
|
86
90
|
|
|
87
91
|
- `/wp-lint` - Run WordPress-specific linting (PHPStan + @wordpress/scripts)
|
|
@@ -126,4 +130,4 @@ MIT © Anikesh Kumar
|
|
|
126
130
|
|
|
127
131
|
---
|
|
128
132
|
|
|
129
|
-
**Made with ❤️ for the WordPress and Antigravity communities**
|
|
133
|
+
**Made with ❤️ for the WordPress, WooCommerce and Antigravity communities**
|
package/STRUCTURE.md
CHANGED
|
@@ -9,7 +9,7 @@ When a user runs `ag-agent init`, the following complete structure is copied to
|
|
|
9
9
|
├── agents/ ✅ WordPress-specialized AI personas
|
|
10
10
|
├── workflows/ ✅ Semi-automated task procedures
|
|
11
11
|
├── rules/ ✅ Global behavior guidelines (GEMINI.md)
|
|
12
|
-
├── skills/ ✅
|
|
12
|
+
├── skills/ ✅ 14 WordPress instruction modules
|
|
13
13
|
└── shared/ ✅ Common resources and utilities
|
|
14
14
|
├── references/ ✅ Version maps and data files
|
|
15
15
|
└── scripts/ ✅ Build and maintenance scripts
|
|
@@ -19,7 +19,7 @@ When a user runs `ag-agent init`, the following complete structure is copied to
|
|
|
19
19
|
|
|
20
20
|
## 📂 Kit Components Breakdown
|
|
21
21
|
|
|
22
|
-
### 1. **Skills** (
|
|
22
|
+
### 1. **Skills** (14 WordPress-specific modules)
|
|
23
23
|
Located in: `skills/`
|
|
24
24
|
|
|
25
25
|
Each skill contains:
|
|
@@ -41,6 +41,7 @@ Each skill contains:
|
|
|
41
41
|
11. `wp-phpstan` - Static analysis configuration
|
|
42
42
|
12. `wp-playground` - WordPress Playground workflows
|
|
43
43
|
13. `wpds` - WordPress Design System
|
|
44
|
+
14. `woocommerce` - Comprehensive WooCommerce development
|
|
44
45
|
|
|
45
46
|
---
|
|
46
47
|
|
|
@@ -48,8 +49,9 @@ Each skill contains:
|
|
|
48
49
|
Located in: `agents/`
|
|
49
50
|
|
|
50
51
|
**Current Agents:**
|
|
51
|
-
- `wordpress-expert.md` - Master WordPress developer (uses all
|
|
52
|
+
- `wordpress-expert.md` - Master WordPress developer (uses all 14 skills)
|
|
52
53
|
- `wp-frontend-expert.md` - Block Theme and Interactivity specialist
|
|
54
|
+
- `woocommerce-expert.md` - WooCommerce e-commerce logic specialist
|
|
53
55
|
|
|
54
56
|
**Agent Structure:**
|
|
55
57
|
```yaml
|
|
@@ -170,8 +172,8 @@ Generated by `skillpack-build.mjs`:
|
|
|
170
172
|
```
|
|
171
173
|
|
|
172
174
|
3. **Kit copies everything needed:**
|
|
173
|
-
- All
|
|
174
|
-
-
|
|
175
|
+
- All 14 skills → `.agent/skills/`
|
|
176
|
+
- 3 agents → `.agent/agents/`
|
|
175
177
|
- 2 workflows → `.agent/workflows/`
|
|
176
178
|
- GEMINI.md → `.agent/rules/`
|
|
177
179
|
- Shared resources → `.agent/shared/`
|
|
@@ -188,8 +190,8 @@ Generated by `skillpack-build.mjs`:
|
|
|
188
190
|
|
|
189
191
|
**YES, everything is used and properly integrated:**
|
|
190
192
|
|
|
191
|
-
✅ **Skills** - All
|
|
192
|
-
✅ **Agents** -
|
|
193
|
+
✅ **Skills** - All 14 WordPress modules are copied and functional
|
|
194
|
+
✅ **Agents** - 3 specialized personas (WordPress, Frontend, WooCommerce)
|
|
193
195
|
✅ **Workflows** - Linting and block creation procedures
|
|
194
196
|
✅ **Rules** - GEMINI.md for consistent behavior
|
|
195
197
|
✅ **Shared** - Version maps and utility scripts
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: woocommerce-expert
|
|
3
|
+
description: "Specialized WooCommerce developer focused on e-commerce logic, checkout flows, order processing, and performance."
|
|
4
|
+
skills:
|
|
5
|
+
- woocommerce
|
|
6
|
+
- wp-plugin-development
|
|
7
|
+
- wp-rest-api
|
|
8
|
+
- wp-performance
|
|
9
|
+
- wp-phpstan
|
|
10
|
+
- wp-project-triage
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
# WooCommerce Expert Agent
|
|
14
|
+
|
|
15
|
+
I am a specialized agent for WooCommerce development. I focus on building robust, high-conversion e-commerce solutions while ensuring data integrity and transaction safety.
|
|
16
|
+
|
|
17
|
+
## Core Directives
|
|
18
|
+
|
|
19
|
+
1. **Transaction Safety**: Never modify order or payment logic without verifying hook order and data persistence.
|
|
20
|
+
2. **Security First**: Always sanitize input and escape output. Use nonces for all state-changing operations.
|
|
21
|
+
3. **Deep i18n**: All user-facing strings must use WordPress translation functions with the correct text domain and translator comments for placeholders.
|
|
22
|
+
4. **Performance First**: Querying thousands of products can be slow. I use `wp-performance` strategies to optimize `WC_Product_Query` and meta lookups.
|
|
23
|
+
3. **Template Overrides**: I prefer hooks and filters over template overrides to ensure future compatibility.
|
|
24
|
+
4. **Copy Excellence**: I follow the WooCommerce UI copy guidelines (Sentence Case) for all user-facing strings.
|
|
25
|
+
5. **REST API**: I favor the WooCommerce REST API for headless integrations or AJAX operations.
|
|
26
|
+
|
|
27
|
+
## Specialized Skills
|
|
28
|
+
|
|
29
|
+
- **Backend logic**: I handle complex product types, shipping methods, and payment gateways.
|
|
30
|
+
- **REST API**: I extend WC endpoints and build custom controllers for decoupled frontends.
|
|
31
|
+
- **Auditing**: I use the WooCommerce Code Review checklist for every change.
|
|
32
|
+
- **Data Integrity**: I ensure that all CRUD operations follow the project's data safety guidelines.
|
|
@@ -14,6 +14,7 @@ skills:
|
|
|
14
14
|
- wp-phpstan
|
|
15
15
|
- wp-playground
|
|
16
16
|
- wpds
|
|
17
|
+
- woocommerce
|
|
17
18
|
---
|
|
18
19
|
|
|
19
20
|
# WordPress Expert Agent
|
|
@@ -24,8 +25,9 @@ I am a specialized agent for WordPress development. I follow modern WordPress st
|
|
|
24
25
|
|
|
25
26
|
1. **Triage First**: Always run `wp-project-triage` to understand the project structure and tooling.
|
|
26
27
|
2. **Block-First**: Prefer Block Themes and Gutenberg blocks over classic PHP templates when appropriate.
|
|
27
|
-
3. **Security**: Always escape output, validate/sanitize input, and use nonces for all actions.
|
|
28
|
-
4. **
|
|
28
|
+
3. **Security**: Always escape output, validate/sanitize input, and use nonces for all state-changing actions.
|
|
29
|
+
4. **Internationalization**: All strings must be translatable using `__()`, `_e()`, etc., with appropriate text domains and translator comments.
|
|
30
|
+
5. **Performance**: Use `wp-performance` to audit and optimize data fetching and database queries.
|
|
29
31
|
5. **Modern Build**: Use `@wordpress/scripts` and `block.json` for block development.
|
|
30
32
|
|
|
31
33
|
## Specialized Skills
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-kits/wp-ag-kit",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "WordPress Antigravity Kit - Complete WordPress development environment for Antigravity IDE with skills, agents, workflows, and rules.",
|
|
3
|
+
"version": "1.0.3",
|
|
4
|
+
"description": "WordPress WooCommerce Antigravity Kit - Complete WordPress and WooCommerce development environment for Antigravity IDE with skills, agents, workflows, and rules.",
|
|
5
5
|
"main": "bin/antigravity-agent.js",
|
|
6
6
|
"bin": {
|
|
7
7
|
"wpag": "bin/antigravity-agent.js"
|
|
@@ -26,7 +26,9 @@
|
|
|
26
26
|
"interactivity-api",
|
|
27
27
|
"wp-cli",
|
|
28
28
|
"phpstan",
|
|
29
|
-
"ai-kits"
|
|
29
|
+
"ai-kits",
|
|
30
|
+
"woocommerce",
|
|
31
|
+
"woo-marketplace"
|
|
30
32
|
],
|
|
31
33
|
"files": [
|
|
32
34
|
"bin/",
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: woocommerce
|
|
3
|
+
description: Comprehensive skill for WooCommerce development, covering backend PHP standards, code review, UI copy guidelines, development lifecycle, and documentation. Use for any WooCommerce-related project changes.
|
|
4
|
+
compatibility: "Targets WordPress 6.9+ (PHP 7.2.24+) and WooCommerce core conventions. Filesystem-based agent with bash + node."
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# WooCommerce Development
|
|
8
|
+
|
|
9
|
+
This skill provides comprehensive guidance for WooCommerce development, including architecture, coding standards, testing, and UI copy.
|
|
10
|
+
|
|
11
|
+
## Core Areas
|
|
12
|
+
|
|
13
|
+
### 1. Backend PHP Development
|
|
14
|
+
Guidelines for creating classes, methods, and hooks following WooCommerce core conventions.
|
|
15
|
+
- [General Backend Guide](references/backend-dev-guide.md)
|
|
16
|
+
- [Naming Conventions (Classes, Methods, Variables)](references/code-entities.md)
|
|
17
|
+
- [File Organization & PSR-4](references/file-entities.md)
|
|
18
|
+
- [Coding Standards (WP-based)](references/coding-conventions.md)
|
|
19
|
+
- [Dependency Injection](references/dependency-injection.md)
|
|
20
|
+
- [Managing Hooks & Callbacks](references/hooks.md)
|
|
21
|
+
- [Data Integrity & CRUD Operations](references/data-integrity.md)
|
|
22
|
+
- [WooCommerce Global Objects & Functions](references/woocommerce-global-objects.md)
|
|
23
|
+
- [PHP i18n Patterns](references/php-i18n-patterns.md)
|
|
24
|
+
- [Security Patterns (Sanitization/Escaping)](references/security-patterns.md)
|
|
25
|
+
- [PHPStan-aware Type Annotations](references/type-annotations.md)
|
|
26
|
+
|
|
27
|
+
### 2. Development Lifecycle & Automation
|
|
28
|
+
Tools and patterns for ensuring high-quality code.
|
|
29
|
+
- [Dev Cycle & General Best Practices](references/dev-cycle-guide.md)
|
|
30
|
+
- [PHP Linting Patterns](references/php-linting-patterns.md)
|
|
31
|
+
- [JS i18n Patterns](references/js-i18n-patterns.md)
|
|
32
|
+
- [Running & Writing Tests](references/running-tests.md)
|
|
33
|
+
- [Code Quality Checklist](references/code-quality.md)
|
|
34
|
+
|
|
35
|
+
### 3. Code Review Standards
|
|
36
|
+
Criteria for reviewing WooCommerce code changes.
|
|
37
|
+
- [Code Review Checklist](references/code-review-guide.md)
|
|
38
|
+
|
|
39
|
+
### 4. UI Copy & Guidelines
|
|
40
|
+
Standards for consistency in user-facing text.
|
|
41
|
+
- [UI Copy Principles](references/copy-guidelines-guide.md)
|
|
42
|
+
- [Sentence Case Guidelines](references/sentence-case.md)
|
|
43
|
+
|
|
44
|
+
### 5. Documentation & Markdown
|
|
45
|
+
- [Markdown Linting & Standards](references/markdown-guide.md)
|
|
46
|
+
- [Markdown Style Guide](references/markdown-linting.md)
|
|
47
|
+
|
|
48
|
+
## Key Principles
|
|
49
|
+
|
|
50
|
+
- **Automatic Verification**: Always run linting and tests before finalizing changes.
|
|
51
|
+
- **WP Coding Standards**: Strictly adhere to WordPress and WooCommerce specific coding standards.
|
|
52
|
+
- **Data Safety**: Validate state and permissions before performing destructive operations.
|
|
53
|
+
- **Consistency**: Follow existing naming and structural patterns in the codebase.
|
|
54
|
+
- **Documentation**: Provide appropriate `@since` and `@testdox` annotations.
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
|
|
2
|
+
# WooCommerce Backend Development
|
|
3
|
+
|
|
4
|
+
This skill provides guidance for developing WooCommerce backend PHP code according to project standards and conventions.
|
|
5
|
+
|
|
6
|
+
## When to Use This Skill
|
|
7
|
+
|
|
8
|
+
**ALWAYS invoke this skill before:**
|
|
9
|
+
|
|
10
|
+
- Writing new PHP unit tests (`*Test.php` files)
|
|
11
|
+
- Creating new PHP classes
|
|
12
|
+
- Modifying existing backend PHP code
|
|
13
|
+
- Adding hooks or filters
|
|
14
|
+
|
|
15
|
+
## Instructions
|
|
16
|
+
|
|
17
|
+
Follow WooCommerce project conventions when adding or modifying backend PHP code:
|
|
18
|
+
|
|
19
|
+
1. **Creating new code structures**: See [file-entities.md](file-entities.md) for conventions on creating classes and organizing files (but for new unit test files see [unit-tests.md](unit-tests.md)).
|
|
20
|
+
2. **Naming conventions**: See [code-entities.md](code-entities.md) for naming methods, variables, and parameters
|
|
21
|
+
3. **Coding style**: See [coding-conventions.md](coding-conventions.md) for general coding standards and best practices
|
|
22
|
+
4. **Type annotations**: See [type-annotations.md](type-annotations.md) for PHPStan-aware PHPDoc annotations
|
|
23
|
+
5. **Working with hooks**: See [hooks.md](hooks.md) for hook callback conventions and documentation
|
|
24
|
+
6. **Dependency injection**: See [dependency-injection.md](dependency-injection.md) for DI container usage
|
|
25
|
+
7. **Data integrity**: See [data-integrity.md](data-integrity.md) for ensuring data integrity when performing CRUD operations
|
|
26
|
+
8. **Writing tests**: See [unit-tests.md](unit-tests.md) for unit testing conventions
|
|
27
|
+
|
|
28
|
+
## Key Principles
|
|
29
|
+
|
|
30
|
+
- Always follow WordPress Coding Standards
|
|
31
|
+
- Use class methods instead of standalone functions
|
|
32
|
+
- Place new internal classes in `src/Internal/` by default
|
|
33
|
+
- Use PSR-4 autoloading with `Automattic\WooCommerce` namespace
|
|
34
|
+
- Write comprehensive unit tests for new functionality
|
|
35
|
+
- Run linting and tests before committing changes
|
|
36
|
+
|
|
37
|
+
## Version Information
|
|
38
|
+
|
|
39
|
+
To determine the next WooCommerce version number for `@since` annotations:
|
|
40
|
+
|
|
41
|
+
- Read the `$version` property in `includes/class-woocommerce.php` **on the trunk branch**
|
|
42
|
+
- Remove the `-dev` suffix if present
|
|
43
|
+
- Example: If trunk shows `10.4.0-dev`, use `@since 10.4.0`
|
|
44
|
+
- Note: When reviewing PRs against trunk, the version in trunk is correct even if it seems "future" relative to released versions
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
# Creating Code Entities (Methods, Variables, Parameters)
|
|
2
|
+
|
|
3
|
+
## Table of Contents
|
|
4
|
+
|
|
5
|
+
- [Naming Conventions](#naming-conventions)
|
|
6
|
+
- [Method Visibility](#method-visibility)
|
|
7
|
+
- [Static Methods](#static-methods)
|
|
8
|
+
- [Docblock Requirements](#docblock-requirements)
|
|
9
|
+
- [Public, Protected Methods, and Hooks](#public-protected-methods-and-hooks)
|
|
10
|
+
- [Private Methods and Internal Callbacks](#private-methods-and-internal-callbacks)
|
|
11
|
+
- [@internal Annotation Placement](#internal-annotation-placement)
|
|
12
|
+
- [Hook Docblocks](#hook-docblocks)
|
|
13
|
+
|
|
14
|
+
## Naming Conventions
|
|
15
|
+
|
|
16
|
+
Use snake_case for methods, variables, and hooks (not camelCase or PascalCase).
|
|
17
|
+
|
|
18
|
+
**Examples:**
|
|
19
|
+
|
|
20
|
+
```php
|
|
21
|
+
// Correct
|
|
22
|
+
public function calculate_order_total() { }
|
|
23
|
+
private $order_items;
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Method Visibility
|
|
27
|
+
|
|
28
|
+
New class methods should be `private` by default.
|
|
29
|
+
|
|
30
|
+
**Use `protected`** only if it's clear the method will be used in derived classes.
|
|
31
|
+
|
|
32
|
+
**Use `public`** only if the method will be called from outside the class.
|
|
33
|
+
|
|
34
|
+
**Examples:**
|
|
35
|
+
|
|
36
|
+
```php
|
|
37
|
+
class OrderProcessor {
|
|
38
|
+
// Default: private for internal helpers
|
|
39
|
+
private function validate_items( array $items ) { }
|
|
40
|
+
|
|
41
|
+
// Protected: for use in child classes
|
|
42
|
+
protected function get_tax_rate( string $country ) { }
|
|
43
|
+
|
|
44
|
+
// Public: external API
|
|
45
|
+
public function process_order( int $order_id ) { }
|
|
46
|
+
}
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Static Methods
|
|
50
|
+
|
|
51
|
+
Pure methods (output depends only on inputs, no external dependencies) must be `static`.
|
|
52
|
+
|
|
53
|
+
**Examples of pure methods (should be static):**
|
|
54
|
+
|
|
55
|
+
```php
|
|
56
|
+
// Mathematical calculations
|
|
57
|
+
public static function calculate_percentage( float $amount, float $percent ) {
|
|
58
|
+
return $amount * ( $percent / 100 );
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// String manipulations
|
|
62
|
+
public static function format_product_sku( string $sku ) {
|
|
63
|
+
return strtoupper( trim( $sku ) );
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// Data transformations
|
|
67
|
+
public static function normalize_address( array $address ) {
|
|
68
|
+
return array_map( 'trim', $address );
|
|
69
|
+
}
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
**Examples of non-pure methods (should NOT be static):**
|
|
73
|
+
|
|
74
|
+
```php
|
|
75
|
+
// Depends on database
|
|
76
|
+
public function get_order_total( int $order_id ) { }
|
|
77
|
+
|
|
78
|
+
// Depends on system time
|
|
79
|
+
public function is_order_recent( int $order_id ) { }
|
|
80
|
+
|
|
81
|
+
// Uses object state
|
|
82
|
+
public function calculate_with_tax( float $amount ) {
|
|
83
|
+
return $amount * $this->tax_rate;
|
|
84
|
+
}
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
**Exception:** Non-pure methods should not be `static` unless there's a specific architectural reason (e.g., singleton pattern, factory methods).
|
|
88
|
+
|
|
89
|
+
## Docblock Requirements
|
|
90
|
+
|
|
91
|
+
Add concise docblocks to all hooks and methods. One line is ideal.
|
|
92
|
+
|
|
93
|
+
### Public, Protected Methods, and Hooks
|
|
94
|
+
|
|
95
|
+
Must include a `@since` annotation with the next WooCommerce version number.
|
|
96
|
+
|
|
97
|
+
The `@since` annotation must be:
|
|
98
|
+
|
|
99
|
+
- The last line in the docblock
|
|
100
|
+
- Preceded by a blank comment line
|
|
101
|
+
- Use the version from `includes/class-woocommerce.php` on trunk, removing the `-dev` suffix
|
|
102
|
+
(e.g., if trunk shows `10.4.0-dev`, use `@since 10.4.0`)
|
|
103
|
+
|
|
104
|
+
**Good - Concise:**
|
|
105
|
+
|
|
106
|
+
```php
|
|
107
|
+
/**
|
|
108
|
+
* Process the order and update status.
|
|
109
|
+
*
|
|
110
|
+
* @param int $order_id The order ID.
|
|
111
|
+
* @return bool True if successful.
|
|
112
|
+
*
|
|
113
|
+
* @since 9.5.0
|
|
114
|
+
*/
|
|
115
|
+
public function process_order( int $order_id ) { }
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Fires after an order is processed.
|
|
119
|
+
*
|
|
120
|
+
* @param int $order_id The order ID.
|
|
121
|
+
*
|
|
122
|
+
* @since 9.5.0
|
|
123
|
+
*/
|
|
124
|
+
do_action( 'woocommerce_order_processed', $order_id );
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
**Avoid - Over-explained:**
|
|
128
|
+
|
|
129
|
+
```php
|
|
130
|
+
/**
|
|
131
|
+
* This method processes the order by validating the order data,
|
|
132
|
+
* checking inventory levels, processing payment, and then updating
|
|
133
|
+
* the order status to reflect the successful processing.
|
|
134
|
+
*
|
|
135
|
+
* @param int $order_id The unique identifier for the order that needs to be processed.
|
|
136
|
+
* @return bool Returns true if the order was processed successfully, false otherwise.
|
|
137
|
+
*
|
|
138
|
+
* @since 9.5.0
|
|
139
|
+
*/
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
For hooks, aim for a single descriptive line whenever possible.
|
|
143
|
+
|
|
144
|
+
### Private Methods and Internal Callbacks
|
|
145
|
+
|
|
146
|
+
Do NOT require a `@since` annotation if they are:
|
|
147
|
+
|
|
148
|
+
- Private methods
|
|
149
|
+
- Internal callbacks (marked with `@internal`)
|
|
150
|
+
|
|
151
|
+
**Example:**
|
|
152
|
+
|
|
153
|
+
```php
|
|
154
|
+
/**
|
|
155
|
+
* Internal helper to validate order items.
|
|
156
|
+
*
|
|
157
|
+
* @param array $items The items to validate.
|
|
158
|
+
* @return bool
|
|
159
|
+
*/
|
|
160
|
+
private function validate_items( array $items ) { }
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
### @internal Annotation Placement
|
|
164
|
+
|
|
165
|
+
When an `@internal` annotation is added, it must be:
|
|
166
|
+
|
|
167
|
+
- Placed after the method description
|
|
168
|
+
- Placed before the arguments list
|
|
169
|
+
- Have a blank comment line before and after
|
|
170
|
+
|
|
171
|
+
**Example:**
|
|
172
|
+
|
|
173
|
+
```php
|
|
174
|
+
/**
|
|
175
|
+
* Handle the woocommerce_init hook.
|
|
176
|
+
*
|
|
177
|
+
* @internal
|
|
178
|
+
*
|
|
179
|
+
* @param array $args Hook arguments.
|
|
180
|
+
*/
|
|
181
|
+
public function handle_woocommerce_init( array $args ) { }
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
## Hook Docblocks
|
|
185
|
+
|
|
186
|
+
For information about documenting hooks (including adding docblocks to existing hooks), see [hooks.md](hooks.md).
|