opencode-skills-collection 4.0.0 → 4.0.2
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/bundled-skills/.antigravity-install-manifest.json +28 -1
- package/bundled-skills/007/SKILL.md +2 -2
- package/bundled-skills/10-andruia-skill-smith/SKILL.md +1 -1
- package/bundled-skills/agent-squad/SKILL.md +5 -0
- package/bundled-skills/agent-squad/alex/SKILL.md +3 -0
- package/bundled-skills/agent-squad/aria/SKILL.md +3 -0
- package/bundled-skills/agent-squad/dep/SKILL.md +3 -0
- package/bundled-skills/agent-squad/luna/SKILL.md +4 -1
- package/bundled-skills/agent-squad/mason/SKILL.md +3 -0
- package/bundled-skills/agent-squad/max/SKILL.md +3 -0
- package/bundled-skills/agent-squad/quinn/SKILL.md +3 -0
- package/bundled-skills/agent-squad/rex/SKILL.md +3 -0
- package/bundled-skills/angular/metadata.json +1 -1
- package/bundled-skills/angular-best-practices/metadata.json +1 -1
- package/bundled-skills/angular-state-management/metadata.json +1 -1
- package/bundled-skills/angular-ui-patterns/metadata.json +1 -1
- package/bundled-skills/antigravity-skill-orchestrator/SKILL.md +2 -2
- package/bundled-skills/anywrite/SKILL.md +106 -0
- package/bundled-skills/apify-actor-development/SKILL.md +2 -2
- package/bundled-skills/apple-container/SKILL.md +165 -0
- package/bundled-skills/apple-container/references/commands.md +1593 -0
- package/bundled-skills/apple-container/references/concepts.md +294 -0
- package/bundled-skills/apple-container/references/configuration.md +499 -0
- package/bundled-skills/apple-container/references/workflows.md +498 -0
- package/bundled-skills/ask-copilot/SKILL.md +112 -0
- package/bundled-skills/auto-research/SKILL.md +126 -0
- package/bundled-skills/brooks-lint/SKILL.md +1 -1
- package/bundled-skills/browser-harness/references/install.md +3 -1
- package/bundled-skills/chrome-extension-developer/SKILL.md +1 -1
- package/bundled-skills/clean-code-guard/SKILL.md +184 -0
- package/bundled-skills/clean-code-guard/references/ai-failure-modes.md +345 -0
- package/bundled-skills/clean-code-guard/references/comments-and-formatting.md +115 -0
- package/bundled-skills/clean-code-guard/references/dry-kiss-yagni.md +133 -0
- package/bundled-skills/clean-code-guard/references/naming-and-functions.md +187 -0
- package/bundled-skills/clean-code-guard/references/review-checklist.md +150 -0
- package/bundled-skills/clean-code-guard/references/solid.md +280 -0
- package/bundled-skills/clean-code-guard/references/sources.md +47 -0
- package/bundled-skills/cloudflare-security-audit/SKILL.md +137 -0
- package/bundled-skills/cloudflare-security-audit/references/AI-AND-LLM.md +67 -0
- package/bundled-skills/cloudflare-security-audit/references/ATTACK-CLASSES.md +116 -0
- package/bundled-skills/cloudflare-security-audit/references/CLIENT-SIDE.md +67 -0
- package/bundled-skills/cloudflare-security-audit/references/HUNTING.md +110 -0
- package/bundled-skills/cloudflare-security-audit/references/MEMORY-SAFETY-AND-BINARY.md +58 -0
- package/bundled-skills/cloudflare-security-audit/references/RECONNAISSANCE.md +46 -0
- package/bundled-skills/cloudflare-security-audit/references/VALIDATION-AND-REPORTING.md +109 -0
- package/bundled-skills/cloudflare-security-audit/references/WEB-PROTOCOL-AND-AUTH.md +85 -0
- package/bundled-skills/cloudflare-security-audit/resources/report-schema.json +210 -0
- package/bundled-skills/comfyui-gateway/references/troubleshooting.md +1 -1
- package/bundled-skills/commit/SKILL.md +2 -1
- package/bundled-skills/deepapi/SKILL.md +6 -6
- package/bundled-skills/ditto/SKILL.md +173 -0
- package/bundled-skills/docs/README.md +1 -1
- package/bundled-skills/docs/contributors/quality-bar.md +1 -1
- package/bundled-skills/docs/contributors/security-guardrails.md +1 -1
- package/bundled-skills/docs/integrations/jetski-cortex.md +5 -5
- package/bundled-skills/docs/integrations/jetski-gemini-loader/README.md +3 -3
- package/bundled-skills/docs/maintainers/ci-drift-fix.md +7 -5
- package/bundled-skills/docs/maintainers/merge-batch.md +24 -7
- package/bundled-skills/docs/maintainers/pr-autonomy.md +89 -0
- package/bundled-skills/docs/maintainers/release-notes-7.2.0.md +1 -1
- package/bundled-skills/docs/maintainers/release-process.md +9 -9
- package/bundled-skills/docs/maintainers/repo-growth-seo.md +5 -5
- package/bundled-skills/docs/maintainers/skills-date-tracking.md +1 -1
- package/bundled-skills/docs/maintainers/skills-update-guide.md +2 -2
- package/bundled-skills/docs/users/{antigravity-awesome-skills-vs-awesome-claude-skills.md → agentic-awesome-skills-vs-awesome-claude-skills.md} +5 -5
- package/bundled-skills/docs/users/ai-agent-skills.md +4 -4
- package/bundled-skills/docs/users/best-claude-code-skills-github.md +3 -3
- package/bundled-skills/docs/users/best-cursor-skills-github.md +3 -3
- package/bundled-skills/docs/users/bundles.md +56 -57
- package/bundled-skills/docs/users/claude-code-skills.md +6 -6
- package/bundled-skills/docs/users/codex-cli-skills.md +5 -5
- package/bundled-skills/docs/users/cursor-skills.md +3 -3
- package/bundled-skills/docs/users/faq.md +27 -15
- package/bundled-skills/docs/users/gemini-cli-skills.md +4 -4
- package/bundled-skills/docs/users/getting-started.md +22 -12
- package/bundled-skills/docs/users/kiro-integration.md +7 -7
- package/bundled-skills/docs/users/plugins.md +8 -9
- package/bundled-skills/docs/users/security-skills.md +1 -1
- package/bundled-skills/docs/users/skills-vs-mcp-tools.md +1 -1
- package/bundled-skills/docs/users/specialized-plugin-roadmap.md +3 -4
- package/bundled-skills/docs/users/usage.md +9 -9
- package/bundled-skills/docs/users/visual-guide.md +7 -7
- package/bundled-skills/docs/users/windows-truncation-recovery.md +1 -1
- package/bundled-skills/docs/users/workflows.md +1 -1
- package/bundled-skills/docs/vietnamese/BUNDLES.vi.md +1 -1
- package/bundled-skills/docs/vietnamese/FAQ.vi.md +15 -8
- package/bundled-skills/docs/vietnamese/GETTING_STARTED.vi.md +12 -5
- package/bundled-skills/docs/vietnamese/QUALITY_BAR.vi.md +1 -1
- package/bundled-skills/docs/vietnamese/README.vi.md +21 -17
- package/bundled-skills/docs/vietnamese/SECURITY_GUARDRAILS.vi.md +1 -1
- package/bundled-skills/docs/vietnamese/SKILLS_README.vi.md +2 -2
- package/bundled-skills/docs/vietnamese/TRANSLATION_PLAN.vi.md +1 -1
- package/bundled-skills/docs/vietnamese/VISUAL_GUIDE.vi.md +8 -8
- package/bundled-skills/docs-guard/SKILL.md +109 -0
- package/bundled-skills/docs-guard/references/code-samples.md +46 -0
- package/bundled-skills/docs-guard/references/docstrings.md +60 -0
- package/bundled-skills/docs-guard/references/review-checklist.md +45 -0
- package/bundled-skills/docs-guard/references/sources.md +22 -0
- package/bundled-skills/docs-guard/references/verification.md +51 -0
- package/bundled-skills/efficient-web-research/SKILL.md +4 -0
- package/bundled-skills/electron-development/SKILL.md +1 -1
- package/bundled-skills/event-staffing-compliance/SKILL.md +3 -0
- package/bundled-skills/event-staffing-ordering/SKILL.md +3 -0
- package/bundled-skills/feature-tracking/SKILL.md +222 -0
- package/bundled-skills/flutter-expert/SKILL.md +6 -1
- package/bundled-skills/flutter-expert/resources/implementation-playbook.md +214 -0
- package/bundled-skills/gemini-deep-research/README.md +246 -0
- package/bundled-skills/gemini-deep-research/SKILL.md +136 -0
- package/bundled-skills/gemini-deep-research/requirements.txt +2 -0
- package/bundled-skills/gemini-deep-research/scripts/research.py +692 -0
- package/bundled-skills/git-pushing/SKILL.md +21 -4
- package/bundled-skills/git-pushing/scripts/smart_commit.sh +206 -11
- package/bundled-skills/go-in-depth/scripts/workflow-script.js +4 -1
- package/bundled-skills/grok-build/SKILL.md +167 -0
- package/bundled-skills/grok-build/references/cli.md +99 -0
- package/bundled-skills/huggingface-tool-builder/references/find_models_by_paper.sh +1 -1
- package/bundled-skills/idea-autopsy/SKILL.md +147 -0
- package/bundled-skills/it-manager-hospital/README.md +1 -1
- package/bundled-skills/it-manager-pro/README.md +1 -1
- package/bundled-skills/itil-expert/README.md +1 -1
- package/bundled-skills/langgraph/SKILL.md +1 -1
- package/bundled-skills/linkedin-content-generator/SKILL.md +1 -1
- package/bundled-skills/lint-and-validate/scripts/lint_runner.py +23 -23
- package/bundled-skills/lint-and-validate/scripts/type_coverage.py +30 -30
- package/bundled-skills/logic-lens/SKILL.md +1 -1
- package/bundled-skills/lore/LICENSE +21 -0
- package/bundled-skills/lore/README.md +386 -0
- package/bundled-skills/lore/README.zh-CN.md +386 -0
- package/bundled-skills/lore/SKILL.md +453 -0
- package/bundled-skills/lore/WORKFLOWS.md +216 -0
- package/bundled-skills/lore/WORKFLOWS.zh-CN.md +216 -0
- package/bundled-skills/lore/references/audit-template.md +60 -0
- package/bundled-skills/lore/references/compatibility.md +228 -0
- package/bundled-skills/lore/references/config.md +125 -0
- package/bundled-skills/lore/references/entry-format.md +70 -0
- package/bundled-skills/lore/references/history-command.md +106 -0
- package/bundled-skills/lore/references/monorepo-detection.md +78 -0
- package/bundled-skills/lore/references/platform-mirrors.md +377 -0
- package/bundled-skills/lore/references/stale-new-markers.md +62 -0
- package/bundled-skills/lore/references/summary-template.md +98 -0
- package/bundled-skills/lore/scripts/README.md +54 -0
- package/bundled-skills/lore/scripts/README.zh-CN.md +54 -0
- package/bundled-skills/lore/scripts/find_duplicates.py +211 -0
- package/bundled-skills/lore/scripts/find_stale.py +116 -0
- package/bundled-skills/lore/scripts/history.py +527 -0
- package/bundled-skills/lore/scripts/id_hash.py +32 -0
- package/bundled-skills/lore/scripts/list_entries.py +183 -0
- package/bundled-skills/lovable-cleanup/SKILL.md +3 -3
- package/bundled-skills/makepad-splash/SKILL.md +1 -1
- package/bundled-skills/mmx-cli/SKILL.md +14 -1
- package/bundled-skills/monopoly/SKILL.md +5 -0
- package/bundled-skills/monopoly/patterns/SKILL.md +4 -0
- package/bundled-skills/monopoly/scale-benchmarks/SKILL.md +4 -0
- package/bundled-skills/monopoly/security-checklist/SKILL.md +4 -0
- package/bundled-skills/monopoly/tech-matrix/SKILL.md +4 -0
- package/bundled-skills/mtls-configuration/SKILL.md +1 -1
- package/bundled-skills/network-101/SKILL.md +4 -5
- package/bundled-skills/nika/SKILL.md +270 -0
- package/bundled-skills/not-a-vibe-coder/SKILL.md +4 -0
- package/bundled-skills/ontoly-software-graph/SKILL.md +160 -0
- package/bundled-skills/openclaw-github-repo-commander/SKILL.md +1 -1
- package/bundled-skills/optim-agent/SKILL.md +78 -0
- package/bundled-skills/pilot-protocol/SKILL.md +6 -3
- package/bundled-skills/postgres-readonly-queries/README.md +77 -0
- package/bundled-skills/postgres-readonly-queries/SKILL.md +152 -0
- package/bundled-skills/postgres-readonly-queries/connections.example.json +34 -0
- package/bundled-skills/postgres-readonly-queries/requirements.txt +1 -0
- package/bundled-skills/postgres-readonly-queries/scripts/query.py +262 -0
- package/bundled-skills/pptx-deck-creation/SKILL.md +275 -0
- package/bundled-skills/pptx-deck-creation/references/audit-checklist.md +156 -0
- package/bundled-skills/pptx-deck-creation/references/design-profiles.md +96 -0
- package/bundled-skills/pptx-deck-creation/references/python-snippets.md +150 -0
- package/bundled-skills/pptx-deck-creation/references/reference-deck-analysis.md +91 -0
- package/bundled-skills/pptx-deck-creation/references/visual-asset-adapters.md +158 -0
- package/bundled-skills/privilege-escalation-methods/SKILL.md +1 -1
- package/bundled-skills/product-decision-agent/SKILL.md +94 -0
- package/bundled-skills/product-decision-agent/agents/openai.yaml +7 -0
- package/bundled-skills/product-decision-agent/references/methodology-basis.md +232 -0
- package/bundled-skills/product-decision-agent/references/product-playbooks.md +813 -0
- package/bundled-skills/product-decision-agent/references/reasoning-engine.md +289 -0
- package/bundled-skills/product-decision-agent/references/response-examples.md +279 -0
- package/bundled-skills/product-decision-agent/scripts/quality_gate.py +221 -0
- package/bundled-skills/product-decision-agent/scripts/test_quality_gate.py +94 -0
- package/bundled-skills/pytest-skill/reference/playbook.md +358 -0
- package/bundled-skills/quit-sponsor/SKILL.md +96 -0
- package/bundled-skills/rclone-cli/references/providers/s3.md +1 -1
- package/bundled-skills/security-and-hardening/SKILL.md +1 -1
- package/bundled-skills/semgrep-rule-creator/SKILL.md +6 -6
- package/bundled-skills/skill-creator/README.md +3 -3
- package/bundled-skills/skill-creator/SKILL.md +8 -4
- package/bundled-skills/skill-creator/scripts/quick_validate.py +1 -1
- package/bundled-skills/sql-injection-testing/SKILL.md +4 -4
- package/bundled-skills/sshepherd/SKILL.md +107 -0
- package/bundled-skills/subagent-orchestrator/README.md +1 -1
- package/bundled-skills/super-code/bash/SKILL.md +3 -0
- package/bundled-skills/super-code/c/SKILL.md +3 -0
- package/bundled-skills/super-code/cpp/SKILL.md +3 -0
- package/bundled-skills/super-code/csharp/SKILL.md +3 -0
- package/bundled-skills/super-code/dart/SKILL.md +3 -0
- package/bundled-skills/super-code/elixir/SKILL.md +3 -0
- package/bundled-skills/super-code/go/SKILL.md +3 -0
- package/bundled-skills/super-code/java/SKILL.md +3 -0
- package/bundled-skills/super-code/kotlin/SKILL.md +3 -0
- package/bundled-skills/super-code/php/SKILL.md +3 -0
- package/bundled-skills/super-code/python/SKILL.md +3 -0
- package/bundled-skills/super-code/ruby/SKILL.md +3 -0
- package/bundled-skills/super-code/rust/SKILL.md +3 -0
- package/bundled-skills/super-code/scala/SKILL.md +3 -0
- package/bundled-skills/super-code/swift/SKILL.md +3 -0
- package/bundled-skills/super-code/typescript/SKILL.md +3 -0
- package/bundled-skills/telegram-bot-messaging/README.md +185 -0
- package/bundled-skills/telegram-bot-messaging/SKILL.md +101 -0
- package/bundled-skills/telegram-bot-messaging/scripts/telegram.sh +420 -0
- package/bundled-skills/test-guard/SKILL.md +132 -0
- package/bundled-skills/test-guard/references/jest.md +50 -0
- package/bundled-skills/test-guard/references/llm-app-testing.md +40 -0
- package/bundled-skills/test-guard/references/phpunit.md +56 -0
- package/bundled-skills/test-guard/references/pytest.md +65 -0
- package/bundled-skills/trading-ledger/SKILL.md +11 -3
- package/bundled-skills/uizze-ui-research/SKILL.md +93 -0
- package/bundled-skills/vibe-code-auditor/SKILL.md +1 -1
- package/bundled-skills/vibecode-production-qa-validator/SKILL.md +1 -1
- package/bundled-skills/videodb/scripts/ws_listener.py +29 -15
- package/bundled-skills/voice-ai-engine-development/README.md +1 -1
- package/bundled-skills/vulnerability-scanner/SKILL.md +1 -1
- package/bundled-skills/warehouse/SKILL.md +154 -0
- package/bundled-skills/woo-guard/SKILL.md +113 -0
- package/bundled-skills/woo-guard/references/checkout-and-money.md +64 -0
- package/bundled-skills/woo-guard/references/hpos-and-crud.md +87 -0
- package/bundled-skills/woo-guard/references/review-checklist.md +44 -0
- package/bundled-skills/woo-guard/references/sources.md +17 -0
- package/bundled-skills/wp-guard/SKILL.md +119 -0
- package/bundled-skills/wp-guard/references/i18n.md +88 -0
- package/bundled-skills/wp-guard/references/performance.md +70 -0
- package/bundled-skills/wp-guard/references/review-checklist.md +57 -0
- package/bundled-skills/wp-guard/references/security.md +100 -0
- package/bundled-skills/wp-guard/references/sources.md +27 -0
- package/bundled-skills/writing-skills/gotchas.md +1 -1
- package/bundled-skills/writing-skills/references/standards/metadata-standard.md +1 -1
- package/bundled-skills/x-twitter-scraper/SKILL.md +14 -32
- package/bundled-skills/xss-html-injection/SKILL.md +3 -3
- package/bundled-skills/youtube-seo-optimizer/SKILL.md +1 -1
- package/bundled-skills/youtube-summarizer/CHANGELOG.md +2 -2
- package/package.json +2 -2
- package/skills_index.json +407 -0
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# Woo Guard — Checkout and Money Reference
|
|
2
|
+
|
|
3
|
+
## Contents
|
|
4
|
+
|
|
5
|
+
- Two checkouts, two hook surfaces
|
|
6
|
+
- Server-side validation
|
|
7
|
+
- Cart and session context guards
|
|
8
|
+
- Money handling
|
|
9
|
+
- Gateway and webhook callbacks
|
|
10
|
+
|
|
11
|
+
## Two checkouts, two hook surfaces
|
|
12
|
+
|
|
13
|
+
Modern stores run the Blocks checkout (Store API); legacy stores run the shortcode checkout (`woocommerce_checkout_*` hooks, `wp_ajax` fragments). The hook surfaces do not overlap:
|
|
14
|
+
|
|
15
|
+
- Legacy-only: `woocommerce_checkout_fields`, `woocommerce_checkout_process`, `woocommerce_after_order_notes`.
|
|
16
|
+
- Blocks: Store API extensions (`ExtendSchema`), additional-fields API, server-side endpoint validation.
|
|
17
|
+
|
|
18
|
+
An extension claiming general compatibility wires both or declares which one it supports (see compatibility declaration in [hpos-and-crud.md](hpos-and-crud.md)). AI-generated checkout code overwhelmingly targets the legacy surface only — on a Blocks store it simply never runs: a hook on the wrong surface fails silently, no error, no behavior.
|
|
19
|
+
|
|
20
|
+
## Server-side validation
|
|
21
|
+
|
|
22
|
+
```php
|
|
23
|
+
/**
|
|
24
|
+
* Reject checkout when the VAT number is malformed.
|
|
25
|
+
*
|
|
26
|
+
* JS validation on the field is UX; this hook is the actual gate.
|
|
27
|
+
*/
|
|
28
|
+
add_action( 'woocommerce_checkout_process', function () {
|
|
29
|
+
$vat = isset( $_POST['ncs_vat'] ) ? sanitize_text_field( wp_unslash( $_POST['ncs_vat'] ) ) : '';
|
|
30
|
+
|
|
31
|
+
if ( '' !== $vat && ! ncs_vat_is_valid( $vat ) ) {
|
|
32
|
+
wc_add_notice( __( 'Please enter a valid VAT number.', 'ncs-checkout' ), 'error' );
|
|
33
|
+
}
|
|
34
|
+
} );
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
For Blocks, the equivalent lives in the Store API additional-fields/extension schema callbacks. Either way: the server decides, every field is unslashed then sanitized with the type-correct function, and error messages go through `wc_add_notice()`/schema errors — never `die()`.
|
|
38
|
+
|
|
39
|
+
## Cart and session context guards
|
|
40
|
+
|
|
41
|
+
`WC()->cart`, `WC()->session`, and `WC()->customer` are initialized for front-end requests — they are null in REST, cron, CLI, webhooks, and most admin requests:
|
|
42
|
+
|
|
43
|
+
```php
|
|
44
|
+
if ( function_exists( 'WC' ) && WC()->cart instanceof WC_Cart ) {
|
|
45
|
+
$count = WC()->cart->get_cart_contents_count();
|
|
46
|
+
}
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Code that touches the cart inside an API callback or scheduled job is a fatal error wearing a demo-store disguise. Flag it in review even when "it worked locally."
|
|
50
|
+
|
|
51
|
+
## Money handling
|
|
52
|
+
|
|
53
|
+
- Storage and arithmetic inputs: `wc_format_decimal( $value )` — normalizes locale decimals and precision.
|
|
54
|
+
- Display: `wc_price( $amount )` — currency symbol, position, separators, all from store settings. Hardcoded `'$' . $amount` fails on the other 150 currencies.
|
|
55
|
+
- Totals and tax: use order/cart getters (`get_total()`, `get_subtotal()`, `WC_Tax` methods) — they apply the store's rounding mode. Re-deriving totals with raw float math produces penny drift that accountants will find.
|
|
56
|
+
- Comparisons: compare formatted decimals or integer minor units; never `==` on floats.
|
|
57
|
+
- Refund/discount logic: negative amounts have meaning — test the zero and partial cases explicitly (test-guard says hi).
|
|
58
|
+
|
|
59
|
+
## Gateway and webhook callbacks
|
|
60
|
+
|
|
61
|
+
- Verify webhook signatures/secrets before touching any order; fail closed with the provider's expected status code.
|
|
62
|
+
- Look up orders from gateway references via `wc_get_orders( array( 'transaction_id' => … ) )` or stored CRUD meta — not custom SQL.
|
|
63
|
+
- Callbacks run unauthenticated by design: capability checks don't apply, signature verification is the authentication, and every input is still unslashed and sanitized before use.
|
|
64
|
+
- Idempotency: providers retry. Processing the same payment event twice must not complete an order twice.
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
# Woo Guard — HPOS and CRUD Reference
|
|
2
|
+
|
|
3
|
+
## Contents
|
|
4
|
+
|
|
5
|
+
- Why HPOS breaks legacy code
|
|
6
|
+
- Order access patterns
|
|
7
|
+
- Order meta done right
|
|
8
|
+
- Products, stock, and lookup tables
|
|
9
|
+
- Status transitions
|
|
10
|
+
- Declaring compatibility
|
|
11
|
+
- Violation table for review
|
|
12
|
+
|
|
13
|
+
## Why HPOS breaks legacy code
|
|
14
|
+
|
|
15
|
+
High-Performance Order Storage moved orders out of `wp_posts`/`wp_postmeta` into dedicated tables, and it is the default on new stores. Code that treats orders as posts returns empty results or stale data on HPOS stores — silently, with no error. Code written "from memory" almost always targets the legacy storage, because that is what most training-era tutorials show.
|
|
16
|
+
|
|
17
|
+
## Order access patterns
|
|
18
|
+
|
|
19
|
+
```php
|
|
20
|
+
// Wrong — assumes orders are posts. Fails on HPOS.
|
|
21
|
+
$total = get_post_meta( $order_id, '_order_total', true );
|
|
22
|
+
$orders = get_posts( array( 'post_type' => 'shop_order', 'numberposts' => 20 ) );
|
|
23
|
+
|
|
24
|
+
// Right — storage-agnostic CRUD API.
|
|
25
|
+
$order = wc_get_order( $order_id );
|
|
26
|
+
$total = $order ? $order->get_total() : 0;
|
|
27
|
+
$orders = wc_get_orders( array( 'status' => 'wc-processing', 'limit' => 20 ) );
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
`wc_get_orders()` takes its own argument schema (not `WP_Query` args): `limit`, `status`, `customer_id`, `date_created`, `meta_query` equivalents via `field_query`. Never run an unbounded order query — always set a `limit` (wp-guard covers query discipline in depth when installed).
|
|
31
|
+
|
|
32
|
+
## Order meta done right
|
|
33
|
+
|
|
34
|
+
```php
|
|
35
|
+
$order = wc_get_order( $order_id );
|
|
36
|
+
$order->update_meta_data( '_ncs_sync_status', 'queued' );
|
|
37
|
+
$order->save(); // persists to whichever storage backend is active
|
|
38
|
+
|
|
39
|
+
$value = $order->get_meta( '_ncs_sync_status' ); // single value, unserialized
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
`save()` is not optional — without it, meta changes exist only in memory. Batched changes: set everything, save once.
|
|
43
|
+
|
|
44
|
+
## Products, stock, and lookup tables
|
|
45
|
+
|
|
46
|
+
Product meta writes through `update_post_meta()` skip `wc_product_meta_lookup` sync, skip `woocommerce_update_product`-family hooks, and skip cache invalidation — three classes of bugs other plugins will blame on you.
|
|
47
|
+
|
|
48
|
+
```php
|
|
49
|
+
$product = wc_get_product( $product_id );
|
|
50
|
+
$product->set_stock_quantity( $new_qty );
|
|
51
|
+
$product->set_regular_price( wc_format_decimal( $price ) );
|
|
52
|
+
$product->save();
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Stock specifically: `wc_update_product_stock()` and the CRUD setters handle backorders, stock status flips, and concurrency better than any hand-rolled meta math. Direct increments via meta are race-prone on busy stores.
|
|
56
|
+
|
|
57
|
+
## Status transitions
|
|
58
|
+
|
|
59
|
+
```php
|
|
60
|
+
$order->update_status( 'completed', 'Synced to fulfillment.' ); // fires emails + hooks
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
Never set status by writing meta or post fields — `update_status()` triggers the `woocommerce_order_status_*` hooks and customer emails the rest of the store depends on. If suppressing side effects is the goal, that is a design discussion to surface, not a meta write to sneak in.
|
|
64
|
+
|
|
65
|
+
## Declaring compatibility
|
|
66
|
+
|
|
67
|
+
```php
|
|
68
|
+
add_action( 'before_woocommerce_init', function () {
|
|
69
|
+
if ( class_exists( \Automattic\WooCommerce\Utilities\FeaturesUtil::class ) ) {
|
|
70
|
+
\Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'custom_order_tables', __FILE__, true );
|
|
71
|
+
\Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'cart_checkout_blocks', __FILE__, true );
|
|
72
|
+
}
|
|
73
|
+
} );
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
Declare only what is true — a false `custom_order_tables` declaration on postmeta-reading code converts a visible warning into an invisible data bug.
|
|
77
|
+
|
|
78
|
+
## Violation table for review
|
|
79
|
+
|
|
80
|
+
| Grep hit | Why it fails |
|
|
81
|
+
|---|---|
|
|
82
|
+
| `get_post_meta( $order_id` | HPOS: order meta is not postmeta |
|
|
83
|
+
| `post_type => 'shop_order'` (or `shop_order_refund`) | HPOS: orders are not posts |
|
|
84
|
+
| `update_post_meta( $product_id` | Skips lookup tables, hooks, caches |
|
|
85
|
+
| `wp_update_post` on order/product IDs | Same class of bypass |
|
|
86
|
+
| `$wpdb` joins on `postmeta` for order data | HPOS + fragile schema coupling |
|
|
87
|
+
| `posts_per_page => -1` over products/orders | Unbounded query, store-sized blast radius |
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# Woo Guard — Review Checklist
|
|
2
|
+
|
|
3
|
+
Structured walk for review mode. First sweep the security floor on the same files — output escaping, unslash-then-sanitize on request data, capability plus nonce on state changes, prepared queries — money code gets zero security slack (wp-guard covers the full WordPress layer when installed). Cite file:line.
|
|
4
|
+
|
|
5
|
+
## Contents
|
|
6
|
+
|
|
7
|
+
- Pass 1: HPOS and CRUD greps
|
|
8
|
+
- Pass 2: Checkout and money
|
|
9
|
+
- Pass 3: Runtime context
|
|
10
|
+
- Pass 4: Compatibility and packaging
|
|
11
|
+
- Reporting
|
|
12
|
+
|
|
13
|
+
## Pass 1: HPOS and CRUD greps (must fix)
|
|
14
|
+
|
|
15
|
+
Run the violation table in [hpos-and-crud.md](hpos-and-crud.md):
|
|
16
|
+
|
|
17
|
+
- `get_post_meta` / `update_post_meta` / `wp_update_post` touching order or product IDs
|
|
18
|
+
- `post_type => 'shop_order'` in any query; `$wpdb` joins on postmeta for order data
|
|
19
|
+
- Meta changes without a following `save()`
|
|
20
|
+
- Stock or order status set by meta/post-field writes instead of `wc_update_product_stock()` / `$order->update_status()`
|
|
21
|
+
- Unbounded `wc_get_orders()` / product queries (no `limit`)
|
|
22
|
+
|
|
23
|
+
## Pass 2: Checkout and money (must fix)
|
|
24
|
+
|
|
25
|
+
- Checkout rules enforced server-side (`woocommerce_checkout_process` or Store API schema)? JS-only validation is a finding.
|
|
26
|
+
- Which checkout does the code target — and does that match what it claims to support?
|
|
27
|
+
- Money: `wc_format_decimal()` on inputs, `wc_price()` on display, store rounding on totals; flag float arithmetic, `number_format()`, hardcoded symbols, float `==`.
|
|
28
|
+
- Webhook/gateway callbacks: signature verified before order access? Idempotent on retries?
|
|
29
|
+
|
|
30
|
+
## Pass 3: Runtime context (should fix)
|
|
31
|
+
|
|
32
|
+
- `WC()->cart` / `WC()->session` / `WC()->customer` reachable from REST, cron, CLI, or webhooks without guards?
|
|
33
|
+
- `woocommerce_*` hooks and `wc_*` functions verified to exist in the supported version range?
|
|
34
|
+
- WooCommerce-active checks before hooking (`class_exists` / feature checks)?
|
|
35
|
+
|
|
36
|
+
## Pass 4: Compatibility and packaging (should fix)
|
|
37
|
+
|
|
38
|
+
- `FeaturesUtil` declarations present and truthful (`custom_order_tables`, `cart_checkout_blocks`)?
|
|
39
|
+
- Template overrides shipped inside the plugin? (Always a finding — hooks or `woocommerce_locate_template`.)
|
|
40
|
+
- Background/batch work on Action Scheduler, idempotent handlers?
|
|
41
|
+
|
|
42
|
+
## Reporting
|
|
43
|
+
|
|
44
|
+
Use the SKILL.md format (What / Risk / Fix). Lead with Pass 1–2 findings and an overall verdict (merge / fix first / do not merge). Note explicitly when security-floor findings exist on the same files so the user sees the full bill at once.
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# Woo Guard — Sources
|
|
2
|
+
|
|
3
|
+
Central bibliography. Operational guidance lives in the other references; read this file only when a source URL is needed.
|
|
4
|
+
|
|
5
|
+
## Contents
|
|
6
|
+
|
|
7
|
+
- WooCommerce developer documentation
|
|
8
|
+
|
|
9
|
+
## WooCommerce developer documentation
|
|
10
|
+
|
|
11
|
+
- HPOS (High-Performance Order Storage): https://developer.woocommerce.com/docs/features/high-performance-order-storage/
|
|
12
|
+
- HPOS recipe book (compatibility patterns): https://developer.woocommerce.com/docs/features/high-performance-order-storage/recipe-book/
|
|
13
|
+
- CRUD objects: https://developer.woocommerce.com/docs/category/data-management/crud-objects/
|
|
14
|
+
- Store API: https://developer.woocommerce.com/docs/apis/store-api/
|
|
15
|
+
- Cart and Checkout Blocks — extensibility: https://developer.woocommerce.com/docs/category/cart-and-checkout-blocks/
|
|
16
|
+
- Action Scheduler: https://actionscheduler.org/
|
|
17
|
+
- Payment gateway API: https://developer.woocommerce.com/docs/woocommerce-payment-gateway-api/
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: "wp-guard"
|
|
3
|
+
description: "Review generated or changed WordPress plugins, themes, and blocks for security, internationalization, performance, and API correctness."
|
|
4
|
+
risk: "offensive"
|
|
5
|
+
source: "community"
|
|
6
|
+
source_repo: "amElnagdy/guard-skills"
|
|
7
|
+
source_type: "community"
|
|
8
|
+
date_added: 2026-07-13
|
|
9
|
+
author: "community"
|
|
10
|
+
tags: []
|
|
11
|
+
tools: []
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
# WP Guard
|
|
16
|
+
|
|
17
|
+
> [!WARNING]
|
|
18
|
+
> **Authorized Use Only.** Review only WordPress code and environments the user owns or is explicitly authorized to assess. Keep checks non-destructive and inside the approved scope.
|
|
19
|
+
|
|
20
|
+
You are reviewing generated or changed WordPress code before it ships. Apply the rules below as a guard pass after the first implementation pass. Be a sharp reviewer, not a pedantic one: flag what creates vulnerabilities, breaks translations, or melts servers — ignore cosmetic preferences WPCS tooling already handles.
|
|
21
|
+
|
|
22
|
+
These rules exist because AI agents produce WordPress code with systematic failures: raw `echo` of request data, AJAX handlers with neither nonce nor capability check, SQL built by string interpolation, English hardcoded into user-facing strings, `posts_per_page => -1` on sites with a million posts, and hand-rolled replacements for APIs core already ships. Each one looks fine in a demo and fails in production.
|
|
23
|
+
|
|
24
|
+
## When to Use
|
|
25
|
+
|
|
26
|
+
Use this skill when reviewing generated or changed WordPress code — plugins, themes, and blocks — before it ships. Activate it reactively after an agent writes, edits, or reviews code touching WordPress APIs: hooks, custom post types, REST endpoints, database queries, and block editor integrations.
|
|
27
|
+
|
|
28
|
+
## How to use this skill
|
|
29
|
+
|
|
30
|
+
**Guard-pass mode** (recommended): after WordPress code has been generated or edited, apply the rules to the diff or target files, then run the self-check before delivery. Fix violations before showing the user.
|
|
31
|
+
|
|
32
|
+
**Live mode** (explicit): when the user invokes this skill before writing WordPress code, apply the same rules while writing, then run the self-check before delivery.
|
|
33
|
+
|
|
34
|
+
**Review mode** (the user asks you to review, audit, or rate WordPress code): walk [references/review-checklist.md](references/review-checklist.md) against the target files and produce a structured findings report. Do not edit code in review mode unless asked.
|
|
35
|
+
|
|
36
|
+
Pair this skill with clean-code-guard when both are installed: clean-code-guard owns generic code quality; wp-guard owns the WordPress layer.
|
|
37
|
+
|
|
38
|
+
## Adapt to the project first
|
|
39
|
+
|
|
40
|
+
1. Read the project's agent instructions (CLAUDE.md, AGENTS.md), `phpcs.xml`/WPCS config, and `composer.json`. Project conventions win on conflict.
|
|
41
|
+
2. Identify the established prefix (functions, options, meta keys, handles) and the minimum supported WP/PHP versions. Match both.
|
|
42
|
+
3. Detect context: WooCommerce APIs in play → apply woo-guard alongside this skill when it is installed; otherwise apply WooCommerce's HPOS, CRUD, and checkout rules from its developer documentation. Multilingual site (WPML/Polylang/multisite) → i18n rules are blocking, not advisory.
|
|
43
|
+
4. Read one neighboring file before writing. Mirror its error handling, hook registration style, and escaping habits — unless they violate the security rules below, which are non-negotiable.
|
|
44
|
+
|
|
45
|
+
## The Rules
|
|
46
|
+
|
|
47
|
+
### Security — must fix, no exceptions
|
|
48
|
+
|
|
49
|
+
1. **Escape late, escape everything.** Every variable crossing into HTML output goes through the context-correct function: `esc_html()`, `esc_attr()`, `esc_url()`, or `wp_kses()`/`wp_kses_post()` for rich content. Data passed to inline JS goes through `wp_json_encode()` + `wp_add_inline_script()` — `esc_js()` is legacy, for single-quoted strings in inline attributes only. Escaping happens at output, not at storage. `echo $anything;` without an `esc_*` wrapper fails review.
|
|
50
|
+
|
|
51
|
+
2. **Sanitize early, and unslash first.** Request data (`$_POST`, `$_GET`, `$_REQUEST`, `$_SERVER`) never touches logic raw: `wp_unslash()` first, then the type-correct sanitizer (`sanitize_text_field()`, `sanitize_key()`, `absint()`, `sanitize_email()`, …). Sanitization is not escaping; doing one never excuses the other.
|
|
52
|
+
|
|
53
|
+
3. **Every state change proves identity and intent.** Form handlers, AJAX endpoints, and REST routes that change anything require BOTH a capability check (`current_user_can()`) AND a nonce (`check_admin_referer()`, `check_ajax_referer()`, or REST nonce handling). A nonce is not authorization. A REST `permission_callback` of `__return_true` on a writing route fails review.
|
|
54
|
+
|
|
55
|
+
4. **`$wpdb->prepare()` for every query containing a variable.** Placeholders (`%s`, `%d`, `%f`, and `%i` for identifiers on WP ≥ 6.2), never interpolation or concatenation. Prefer `WP_Query`, the meta and options APIs over raw SQL when they can express the query.
|
|
56
|
+
|
|
57
|
+
### Core API discipline
|
|
58
|
+
|
|
59
|
+
5. **Use the platform; don't reinvent it.** Outbound HTTP via `wp_remote_get()`/`wp_remote_post()`, never curl. Assets via `wp_enqueue_script()`/`wp_enqueue_style()`, never echoed `<script>`/`<style>` tags. Scheduling via WP-Cron or Action Scheduler. Redirects via `wp_safe_redirect()` followed by `exit`. File writes via `WP_Filesystem`. Simple persistent data via options/transients, not a custom table.
|
|
60
|
+
|
|
61
|
+
6. **Verify every hook and function exists.** Before `add_action()`, `add_filter()`, or calling a core/plugin function, confirm it exists in the supported versions — read the source or the project's installed code. Hallucinated hooks fail silently in WordPress: no error, no behavior. Also match the hook to the moment — front-end code does not load on `admin_init`, queries do not run before `init` expects them.
|
|
62
|
+
|
|
63
|
+
7. **Prefix or namespace everything public.** Functions, classes, options, transients, meta keys, script handles, AJAX actions, REST namespaces — all carry the project prefix. Generic names (`get_settings`, `data`, `api_key`) are collisions waiting for the next active plugin.
|
|
64
|
+
|
|
65
|
+
8. **Guard direct access.** Every PHP file that does work starts with the `ABSPATH` check (or equivalent project convention).
|
|
66
|
+
|
|
67
|
+
### Internationalization
|
|
68
|
+
|
|
69
|
+
9. **Every user-facing string is translation-ready.** The correct wrapper for the context (`__()`, `_e()`, `_x()`, `_n()`, or the escaping combos `esc_html__()`, `esc_attr__()`), a literal text domain matching the plugin slug — never a variable or constant — translator comments on every placeholder, `_n()` for plurals (never `sprintf` with a hardcoded singular/plural choice), and no sentence assembly by concatenation. Dates and numbers through `date_i18n()`/`wp_date()` and `number_format_i18n()`. Details and JS i18n: [references/i18n.md](references/i18n.md).
|
|
70
|
+
|
|
71
|
+
### Performance
|
|
72
|
+
|
|
73
|
+
10. **Query discipline.** No `posts_per_page => -1` and no `query_posts()`, ever. Use `'fields' => 'ids'` when only IDs are needed, `'no_found_rows' => true` when not paginating, and never query inside a loop what could be primed once (meta/term caches). Details: [references/performance.md](references/performance.md).
|
|
74
|
+
|
|
75
|
+
11. **Cache expensive work, load assets where used.** Remote calls and heavy computations go behind transients or the object cache with a deliberate TTL. Options that are large or rarely read register with `autoload => false`. Scripts and styles enqueue only on the screens that use them.
|
|
76
|
+
|
|
77
|
+
## Self-check before delivery
|
|
78
|
+
|
|
79
|
+
1. Grep your diff for `echo`, `print`, `<?=`: is every variable output escaped with the context-correct function?
|
|
80
|
+
2. Grep for `$_POST`, `$_GET`, `$_REQUEST`: unslashed? sanitized? nonce-verified? capability-checked?
|
|
81
|
+
3. Grep for `$wpdb->`: every variable behind a placeholder?
|
|
82
|
+
4. Any user-facing string outside an i18n wrapper? Any non-literal text domain?
|
|
83
|
+
5. Any hook or function you did not verify exists?
|
|
84
|
+
6. Any unbounded query, uncached remote call, or unconditional enqueue?
|
|
85
|
+
7. Does every new public name carry the project prefix?
|
|
86
|
+
8. Would this survive WPCS (`WordPress-Extra` + `WordPress-Security`) without warnings you cannot justify?
|
|
87
|
+
|
|
88
|
+
If any answer is wrong, fix it before showing the user.
|
|
89
|
+
|
|
90
|
+
## Reporting format (review mode)
|
|
91
|
+
|
|
92
|
+
```
|
|
93
|
+
**Rule N violation** in `path/file.php:<line or function>`
|
|
94
|
+
- What: <one sentence>
|
|
95
|
+
- Risk: <XSS / SQLi / CSRF / broken i18n / scaling — one phrase>
|
|
96
|
+
- Fix: <one sentence>
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
Group by file, lead with security findings. If a file is clean, don't mention it.
|
|
100
|
+
|
|
101
|
+
## Severity guide
|
|
102
|
+
|
|
103
|
+
- **Must fix:** Rules 1–4 — these are exploitable (XSS, SQLi, CSRF, privilege escalation)
|
|
104
|
+
- **Should fix:** Rules 5–9 — conflicts, silent failures, untranslatable releases
|
|
105
|
+
- **Worth noting:** Rules 10–11 — they decide whether the code survives traffic; block on them for code that runs on every request
|
|
106
|
+
|
|
107
|
+
## References
|
|
108
|
+
|
|
109
|
+
- [references/security.md](references/security.md) — escaping/sanitization function tables, nonce lifecycle, REST permissions, `$wpdb->prepare` details, file uploads
|
|
110
|
+
- [references/i18n.md](references/i18n.md) — wrapper selection, text domain rules, plurals, translator comments, JS translations, RTL, multilingual-plugin gotchas
|
|
111
|
+
- [references/performance.md](references/performance.md) — WP_Query flags, transients vs object cache, autoload hygiene, asset loading, cron, scaling traps
|
|
112
|
+
- [references/review-checklist.md](references/review-checklist.md) — structured walk-through for review mode
|
|
113
|
+
- [references/sources.md](references/sources.md) — handbook and research URLs; read only when citing a source
|
|
114
|
+
|
|
115
|
+
## What this skill does not do
|
|
116
|
+
|
|
117
|
+
- Run PHPCS, PHPStan, or Plugin Check — use the project's tooling for mechanical verification; this skill is the judgment layer above it.
|
|
118
|
+
- Decide plugin architecture or business logic — it guards how WordPress code ships, not what it does.
|
|
119
|
+
- Replace clean-code-guard or test-guard — generic code quality and test quality remain their jurisdiction.
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
# WP Guard — Internationalization Reference
|
|
2
|
+
|
|
3
|
+
## Contents
|
|
4
|
+
|
|
5
|
+
- Wrapper selection
|
|
6
|
+
- Text domain rules
|
|
7
|
+
- Placeholders and translator comments
|
|
8
|
+
- Plurals
|
|
9
|
+
- Sentence assembly
|
|
10
|
+
- JavaScript i18n
|
|
11
|
+
- Dates, numbers, RTL
|
|
12
|
+
- Multilingual-plugin gotchas
|
|
13
|
+
|
|
14
|
+
## Wrapper selection
|
|
15
|
+
|
|
16
|
+
| Situation | Use |
|
|
17
|
+
|---|---|
|
|
18
|
+
| Return a translated string | `__( 'Text', 'my-plugin' )` |
|
|
19
|
+
| Echo a translated string | `_e( 'Text', 'my-plugin' )` — or better, `esc_html_e()` |
|
|
20
|
+
| Translate + escape for HTML | `esc_html__()` / `esc_html_e()` |
|
|
21
|
+
| Translate + escape for attribute | `esc_attr__()` / `esc_attr_e()` |
|
|
22
|
+
| Ambiguous word needing context | `_x( 'Post', 'verb', 'my-plugin' )` |
|
|
23
|
+
| Plural | `_n( '%s item', '%s items', $count, 'my-plugin' )` |
|
|
24
|
+
| Plural + context | `_nx()` |
|
|
25
|
+
|
|
26
|
+
When a string is both translated and output, the combined wrappers (`esc_html__`) are required — translations are untrusted input like any other (a compromised translation file is an XSS vector).
|
|
27
|
+
|
|
28
|
+
## Text domain rules
|
|
29
|
+
|
|
30
|
+
- Literal string, always: `__( 'Text', 'my-plugin' )`. Never `__( 'Text', PLUGIN_DOMAIN )`, never a variable — static analysis tools and translate.wordpress.org both fail on non-literal domains.
|
|
31
|
+
- Must match the plugin slug exactly (the WordPress.org directory enforces this).
|
|
32
|
+
- One domain per plugin/theme. AI agents copying snippets from other projects routinely import foreign text domains — grep for domains that don't match the project's.
|
|
33
|
+
|
|
34
|
+
## Placeholders and translator comments
|
|
35
|
+
|
|
36
|
+
```php
|
|
37
|
+
/* translators: 1: customer name, 2: order number. */
|
|
38
|
+
$message = sprintf(
|
|
39
|
+
__( 'Hi %1$s, your order #%2$d is on its way.', 'my-plugin' ),
|
|
40
|
+
$customer_name,
|
|
41
|
+
$order_id
|
|
42
|
+
);
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
- Numbered placeholders (`%1$s`) whenever there is more than one — translators reorder words.
|
|
46
|
+
- A `/* translators: … */` comment on every string with placeholders, immediately above the line.
|
|
47
|
+
- Never put variables or HTML soup inside the translatable string when it can sit outside.
|
|
48
|
+
|
|
49
|
+
## Plurals
|
|
50
|
+
|
|
51
|
+
`_n()` exists because languages have between one and six plural forms. Never:
|
|
52
|
+
|
|
53
|
+
```php
|
|
54
|
+
// Wrong — English-only logic.
|
|
55
|
+
$label = $count === 1 ? __( 'item', 'my-plugin' ) : __( 'items', 'my-plugin' );
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Always `_n( '%s item', '%s items', $count, 'my-plugin' )`, then `sprintf()` with `number_format_i18n( $count )`.
|
|
59
|
+
|
|
60
|
+
## Sentence assembly
|
|
61
|
+
|
|
62
|
+
Never build sentences by concatenation — word order differs across languages:
|
|
63
|
+
|
|
64
|
+
```php
|
|
65
|
+
// Wrong: translators get fragments they cannot reorder.
|
|
66
|
+
echo __( 'Imported', 'my-plugin' ) . ' ' . $count . ' ' . __( 'products', 'my-plugin' );
|
|
67
|
+
|
|
68
|
+
// Right: one string, one placeholder, full context.
|
|
69
|
+
/* translators: %s: number of imported products. */
|
|
70
|
+
printf( esc_html__( 'Imported %s products.', 'my-plugin' ), number_format_i18n( $count ) );
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## JavaScript i18n
|
|
74
|
+
|
|
75
|
+
- `wp_set_script_translations( 'my-handle', 'my-plugin' )` after enqueueing; use `__()` from `@wordpress/i18n` in the JS.
|
|
76
|
+
- Legacy pattern (`wp_localize_script` with pre-translated strings) is acceptable in legacy codebases — match the project.
|
|
77
|
+
|
|
78
|
+
## Dates, numbers, RTL
|
|
79
|
+
|
|
80
|
+
- Dates: `wp_date()` / `date_i18n()` with the site's format options — never raw `date()` for display.
|
|
81
|
+
- Numbers: `number_format_i18n()`.
|
|
82
|
+
- CSS: logical properties (`margin-inline-start`, not `margin-left`) for new styles; don't hand-write directional CSS — build `-rtl.css` files with RTLCSS. Auto-loading them applies only to core styles and block.json-registered styles; classic plugin/theme handles must opt in with `wp_style_add_data( $handle, 'rtl', 'replace' )`.
|
|
83
|
+
|
|
84
|
+
## Multilingual-plugin gotchas (WPML / Polylang)
|
|
85
|
+
|
|
86
|
+
- Strings stored in options/meta are NOT translated by `__()` — they need string registration (WPML String Translation / `pll_register_string`). Flag stored user-facing strings during review.
|
|
87
|
+
- IDs are language-specific: a hardcoded `page_id` points at one language's page. Resolve through the multilingual plugin's API or filters when the project uses one.
|
|
88
|
+
- Queries on multilingual sites are language-filtered by default — explicitly note when a query intentionally crosses languages.
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# WP Guard — Performance Reference
|
|
2
|
+
|
|
3
|
+
## Contents
|
|
4
|
+
|
|
5
|
+
- WP_Query discipline
|
|
6
|
+
- Meta and term cache priming
|
|
7
|
+
- Transients vs object cache
|
|
8
|
+
- Options autoload hygiene
|
|
9
|
+
- Asset loading
|
|
10
|
+
- Cron and background work
|
|
11
|
+
- Scaling traps checklist
|
|
12
|
+
|
|
13
|
+
## WP_Query discipline
|
|
14
|
+
|
|
15
|
+
- `posts_per_page => -1` is forbidden. There is always a bound; if the caller "needs everything," page through with a loop or use a bounded cap the project agrees on.
|
|
16
|
+
- `query_posts()` is forbidden — it clobbers the main query. Use `WP_Query` or `pre_get_posts`.
|
|
17
|
+
- Only IDs needed → `'fields' => 'ids'` (skips row hydration and caches).
|
|
18
|
+
- Not paginating → `'no_found_rows' => true` (skips `SQL_CALC_FOUND_ROWS`).
|
|
19
|
+
- Not using meta/terms in the loop → `'update_post_meta_cache' => false`, `'update_post_term_cache' => false`.
|
|
20
|
+
- Avoid `'meta_query'` on unindexed scans for high-traffic paths — meta queries do not scale on large `postmeta` tables; consider a lookup table or taxonomy when the access pattern is hot.
|
|
21
|
+
- Never run queries inside `foreach` when one query (or cache priming) can fetch the set.
|
|
22
|
+
|
|
23
|
+
## Meta and term cache priming
|
|
24
|
+
|
|
25
|
+
The N+1 killer. When iterating IDs and reading meta per item:
|
|
26
|
+
|
|
27
|
+
```php
|
|
28
|
+
$ids = get_posts( array( 'fields' => 'ids', /* … */ ) );
|
|
29
|
+
update_meta_cache( 'post', $ids ); // one query primes the cache
|
|
30
|
+
foreach ( $ids as $id ) {
|
|
31
|
+
$sku = get_post_meta( $id, '_sku', true ); // served from cache
|
|
32
|
+
}
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
`update_meta_cache()` and `update_object_term_cache()` exist for exactly this; on WP ≥ 6.1, `_prime_post_caches()` batches posts, meta, and terms in one call (public API since 6.1 despite the underscore). AI-generated loops skip them every time.
|
|
36
|
+
|
|
37
|
+
## Transients vs object cache
|
|
38
|
+
|
|
39
|
+
- `set_transient()` / `get_transient()` — persistent cache with TTL; backed by the object cache when a drop-in exists, by the options table otherwise.
|
|
40
|
+
- `wp_cache_get()` / `wp_cache_set()` — request-scope by default, persistent only with an object-cache drop-in (Redis/Memcached). Use cache groups and deliberate TTLs.
|
|
41
|
+
- Expensive remote calls (Rule 11) always go behind one of these. Choose TTL consciously; never cache user-specific data in a shared key — include the user/locale in the key when output varies by them.
|
|
42
|
+
- On failure paths, decide explicitly whether to cache the failure (short TTL) or retry every request — and say which in a comment.
|
|
43
|
+
|
|
44
|
+
## Options autoload hygiene
|
|
45
|
+
|
|
46
|
+
Every `autoload => true` option loads on EVERY request into `alloptions`. Rules:
|
|
47
|
+
|
|
48
|
+
- `add_option( 'ncs_big_report_cache', $data, '', false )` — large or rarely-read data never autoloads (pass `false` as the third arg of `update_option` too; the parameter exists since WP 4.2).
|
|
49
|
+
- Keep individual autoloaded options small; an `alloptions` blob over ~1 MB is a known site-killer on high-traffic sites.
|
|
50
|
+
- One serialized settings array per plugin beats twenty separate options.
|
|
51
|
+
|
|
52
|
+
## Asset loading
|
|
53
|
+
|
|
54
|
+
- Enqueue only where used: check `is_admin()`, screen IDs (`get_current_screen()`), shortcode presence, or block usage before enqueueing.
|
|
55
|
+
- Front-end assets registered on `wp_enqueue_scripts`, admin on `admin_enqueue_scripts` with the `$hook_suffix` check.
|
|
56
|
+
- Version assets with the plugin version (cache busting); load non-critical JS with `defer`/`async` strategies (`wp_register_script` args on WP ≥ 6.3).
|
|
57
|
+
|
|
58
|
+
## Cron and background work
|
|
59
|
+
|
|
60
|
+
- WP-Cron is traffic-driven and can stack: guard handlers against overlap (a lock transient), keep events idempotent.
|
|
61
|
+
- Long or high-volume jobs → Action Scheduler when WooCommerce (or the library) is present.
|
|
62
|
+
- Never `sleep()` in a request; never do batch work on `init` for every visitor.
|
|
63
|
+
|
|
64
|
+
## Scaling traps checklist
|
|
65
|
+
|
|
66
|
+
- Unbounded `get_users()` / `get_terms()` on large sites — same rules as posts.
|
|
67
|
+
- `switch_to_blog()` in loops without batching (multisite).
|
|
68
|
+
- Per-request remote HTTP without caching — one slow third party becomes your TTFB.
|
|
69
|
+
- Writing to options on front-end requests (cache invalidation storm under traffic).
|
|
70
|
+
- Counting rows with `found_posts` when an indexed count query or cached counter would do.
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# WP Guard — Review Checklist
|
|
2
|
+
|
|
3
|
+
Structured walk for review mode. Lead with findings, not summary. Cite file:line. Prioritize: security → silent breakage → i18n → performance.
|
|
4
|
+
|
|
5
|
+
## Contents
|
|
6
|
+
|
|
7
|
+
- Pass 1: Security sweep
|
|
8
|
+
- Pass 2: API and hook correctness
|
|
9
|
+
- Pass 3: i18n
|
|
10
|
+
- Pass 4: Performance
|
|
11
|
+
- Pass 5: Packaging hygiene
|
|
12
|
+
- Reporting
|
|
13
|
+
|
|
14
|
+
## Pass 1: Security sweep (must fix)
|
|
15
|
+
|
|
16
|
+
Grep-driven; check every hit:
|
|
17
|
+
|
|
18
|
+
- `echo`, `print`, `<?=`, `printf` — every variable escaped with the context-correct `esc_*`/`wp_kses`? (Rule 1)
|
|
19
|
+
- `$_POST`, `$_GET`, `$_REQUEST`, `$_SERVER`, `$_COOKIE` — `wp_unslash()` then sanitized? (Rule 2)
|
|
20
|
+
- `add_action( 'wp_ajax_`, `admin_post_`, `rest_api_init` — every state-changing handler has BOTH `current_user_can()` and a nonce check / real `permission_callback`? (Rule 3)
|
|
21
|
+
- `$wpdb->` — every variable behind `prepare()` placeholders? `esc_like()` for LIKE? (Rule 4)
|
|
22
|
+
- `$_FILES` — handled via `wp_handle_upload()` with type allowlist?
|
|
23
|
+
- Secrets: API keys hardcoded? Logged? In autoloaded options when they belong in constants/env?
|
|
24
|
+
|
|
25
|
+
## Pass 2: API and hook correctness (should fix)
|
|
26
|
+
|
|
27
|
+
- Every hooked hook and called function exists in supported WP/plugin versions? (Rule 6 — hallucinated hooks fail silently)
|
|
28
|
+
- Hook timing right? (No front-end work on admin hooks, no early queries, no `init`-heavy work per request)
|
|
29
|
+
- Core API replacements: curl, raw `<script>` echoes, manual cron loops, direct file ops? (Rule 5)
|
|
30
|
+
- Prefixes on every public name: functions, options, transients, meta keys, handles, AJAX actions? (Rule 7)
|
|
31
|
+
- `ABSPATH` guard present in working files? (Rule 8)
|
|
32
|
+
- `wp_safe_redirect()` + `exit` after state changes?
|
|
33
|
+
|
|
34
|
+
## Pass 3: i18n (should fix; blocking on multilingual projects)
|
|
35
|
+
|
|
36
|
+
- User-facing strings without wrappers? Wrong/non-literal text domain? (Rule 9)
|
|
37
|
+
- Placeholders without translator comments? Plural logic without `_n()`?
|
|
38
|
+
- Concatenated sentence fragments?
|
|
39
|
+
- Stored user-facing strings (options/meta) that multilingual plugins can't see? (see [i18n.md](i18n.md))
|
|
40
|
+
- Raw `date()`/`number_format()` for display?
|
|
41
|
+
|
|
42
|
+
## Pass 4: Performance (worth noting; blocking on every-request paths)
|
|
43
|
+
|
|
44
|
+
- `posts_per_page => -1`, `query_posts()`, unbounded `get_users()`/`get_terms()`? (Rule 10)
|
|
45
|
+
- Queries or `get_post_meta()` inside loops without cache priming?
|
|
46
|
+
- Remote calls without transient/object caching? (Rule 11)
|
|
47
|
+
- Large options autoloading? Unconditional asset enqueues?
|
|
48
|
+
|
|
49
|
+
## Pass 5: Packaging hygiene
|
|
50
|
+
|
|
51
|
+
- WooCommerce code in scope → hand off to woo-guard when it is installed; otherwise apply WooCommerce's HPOS, CRUD, checkout, and money rules from its developer documentation.
|
|
52
|
+
- Activation/deactivation/uninstall: scheduled events cleared, transients cleaned, uninstall removes its data?
|
|
53
|
+
- Direct entry files, readme version mismatches, debug code (`error_log`, `var_dump`) left in?
|
|
54
|
+
|
|
55
|
+
## Reporting
|
|
56
|
+
|
|
57
|
+
Use the SKILL.md reporting format. Lead with the security findings and an overall verdict (merge / fix first / do not merge). End with at most three positives worth keeping — reviewers who only list faults get ignored.
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
# WP Guard — Security Reference
|
|
2
|
+
|
|
3
|
+
## Contents
|
|
4
|
+
|
|
5
|
+
- Escaping: context → function
|
|
6
|
+
- Sanitization: input type → function
|
|
7
|
+
- The unslash-then-sanitize order
|
|
8
|
+
- Nonce + capability lifecycle
|
|
9
|
+
- REST API permissions
|
|
10
|
+
- $wpdb->prepare details
|
|
11
|
+
- File uploads
|
|
12
|
+
- Common AI-generated violations
|
|
13
|
+
|
|
14
|
+
## Escaping: context → function
|
|
15
|
+
|
|
16
|
+
Escape at the moment of output, with the function matching the destination context:
|
|
17
|
+
|
|
18
|
+
| Output context | Function |
|
|
19
|
+
|---|---|
|
|
20
|
+
| HTML body text | `esc_html()` |
|
|
21
|
+
| HTML attribute | `esc_attr()` |
|
|
22
|
+
| URL (href/src/action) | `esc_url()` (display) / `esc_url_raw()` (storage/redirects) |
|
|
23
|
+
| Data for inline JS | `wp_json_encode()` + `wp_add_inline_script()`; `esc_js()` is legacy — single-quoted strings in inline attributes only |
|
|
24
|
+
| Textarea content | `esc_textarea()` |
|
|
25
|
+
| Rich/user HTML | `wp_kses_post()` or `wp_kses()` with an explicit allowlist |
|
|
26
|
+
| Translation + output | `esc_html__()`, `esc_html_e()`, `esc_attr__()` — escape and translate in one call |
|
|
27
|
+
|
|
28
|
+
Trust nothing at output time — not even your own stored options; another plugin or a compromised import may have written them. "Escaped on save" is not a defense.
|
|
29
|
+
|
|
30
|
+
## Sanitization: input type → function
|
|
31
|
+
|
|
32
|
+
| Expected input | Function |
|
|
33
|
+
|---|---|
|
|
34
|
+
| Plain text line | `sanitize_text_field()` |
|
|
35
|
+
| Multiline text | `sanitize_textarea_field()` |
|
|
36
|
+
| Integer / ID | `absint()` or `intval()` |
|
|
37
|
+
| Slug/key | `sanitize_key()` / `sanitize_title()` |
|
|
38
|
+
| Email | `sanitize_email()` + `is_email()` check |
|
|
39
|
+
| URL | `esc_url_raw()` |
|
|
40
|
+
| HTML payload | `wp_kses_post()` / `wp_kses()` |
|
|
41
|
+
| File name | `sanitize_file_name()` |
|
|
42
|
+
| Anything enumerable | strict allowlist comparison (`in_array( $v, $allowed, true )`) |
|
|
43
|
+
|
|
44
|
+
## The unslash-then-sanitize order
|
|
45
|
+
|
|
46
|
+
WordPress adds slashes to superglobals. The correct pipeline is always:
|
|
47
|
+
|
|
48
|
+
```php
|
|
49
|
+
$status = sanitize_key( wp_unslash( $_POST['ncs_status'] ?? '' ) );
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
`wp_unslash()` first, sanitizer second. Sanitizing slashed data corrupts legitimate input and hides bugs.
|
|
53
|
+
|
|
54
|
+
## Nonce + capability lifecycle
|
|
55
|
+
|
|
56
|
+
Both checks, always, for any state change. They answer different questions:
|
|
57
|
+
|
|
58
|
+
- `current_user_can( 'manage_options' )` — is this user *allowed* to do this? (authorization)
|
|
59
|
+
- `check_admin_referer( 'ncs_save_settings' )` / `check_ajax_referer( 'ncs_action', 'nonce' )` — did this request *intend* this action? (CSRF protection)
|
|
60
|
+
|
|
61
|
+
A nonce without a capability check lets any logged-in subscriber fire admin actions. A capability check without a nonce leaves CSRF open. AI-generated handlers routinely have one, the other, or neither — verify both exist on every `admin_post_*`, `wp_ajax_*`, and form handler.
|
|
62
|
+
|
|
63
|
+
Generate nonces with `wp_nonce_field()` (forms) or `wp_create_nonce()` (AJAX/REST payloads). Nonces are per-user and time-limited; do not cache pages containing them.
|
|
64
|
+
|
|
65
|
+
## REST API permissions
|
|
66
|
+
|
|
67
|
+
- Every route registers a real `permission_callback`. `__return_true` is acceptable only for genuinely public read-only data — never for writes.
|
|
68
|
+
- Validate and sanitize via the route's `args` schema (`validate_callback`, `sanitize_callback`) instead of manual checks inside the handler.
|
|
69
|
+
- Cookie-authenticated REST requests require the `X-WP-Nonce` header (`wp_rest` nonce); custom auth schemes must fail closed.
|
|
70
|
+
|
|
71
|
+
## $wpdb->prepare details
|
|
72
|
+
|
|
73
|
+
```php
|
|
74
|
+
$row = $wpdb->get_row(
|
|
75
|
+
$wpdb->prepare(
|
|
76
|
+
"SELECT * FROM {$wpdb->prefix}ncs_log WHERE user_id = %d AND event = %s",
|
|
77
|
+
$user_id,
|
|
78
|
+
$event
|
|
79
|
+
)
|
|
80
|
+
);
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
- Placeholders: `%s`, `%d`, `%f`; `%i` for table/column identifiers (WP ≥ 6.2).
|
|
84
|
+
- `IN ( … )` lists: build placeholders dynamically — `implode( ',', array_fill( 0, count( $ids ), '%d' ) )` — then prepare with the spread array.
|
|
85
|
+
- LIKE queries: `$wpdb->esc_like()` the term *before* passing it as a `%s` parameter.
|
|
86
|
+
- Never interpolate `$_REQUEST` data anywhere near SQL, even "validated" data.
|
|
87
|
+
- Prefer `WP_Query`, `get_posts()`, meta/term/option APIs when they can express the query — they bring caching for free.
|
|
88
|
+
|
|
89
|
+
## File uploads
|
|
90
|
+
|
|
91
|
+
Use `wp_handle_upload()` / media APIs — never move `$_FILES` manually. Validate type with `wp_check_filetype_and_ext()` against an allowlist; never trust the client MIME. Store outside executable paths; WordPress handles this when you use its APIs.
|
|
92
|
+
|
|
93
|
+
## Common AI-generated violations
|
|
94
|
+
|
|
95
|
+
1. `echo '<div>' . $title . '</div>';` — unescaped output (Rule 1). Published research: XSS appears in 86% of AI generations tested on XSS-prone tasks (see [sources.md](sources.md)).
|
|
96
|
+
2. `wp_ajax_` handler with neither `check_ajax_referer()` nor `current_user_can()` (Rule 3).
|
|
97
|
+
3. `"SELECT * FROM {$wpdb->posts} WHERE post_title = '$title'"` — interpolated SQL (Rule 4).
|
|
98
|
+
4. `permission_callback => '__return_true'` on a POST route (Rule 3).
|
|
99
|
+
5. `curl_init()` inside a plugin (Rule 5) — breaks proxies, blocks, and filters that `wp_remote_*` honors.
|
|
100
|
+
6. Echoed `<script>` blocks with interpolated PHP — combines Rules 1 and 5; use `wp_enqueue_script()` + `wp_add_inline_script()`/`wp_localize_script()`.
|