woocommerce-backend-dev

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

WooCommerce Backend Development

WooCommerce后端开发

This skill provides guidance for developing WooCommerce backend PHP code according to project standards and conventions.
本技能提供了根据项目标准和规范开发WooCommerce后端PHP代码的指导。

When to Use This Skill

何时使用此技能

ALWAYS invoke this skill before:
  • Writing new PHP unit tests (
    *Test.php
    files)
  • Creating new PHP classes
  • Modifying existing backend PHP code
  • Adding hooks or filters
在以下操作前必须调用此技能:
  • 编写新的PHP单元测试(
    *Test.php
    文件)
  • 创建新的PHP类
  • 修改现有后端PHP代码
  • 添加钩子或过滤器

Instructions

操作指南

Follow WooCommerce project conventions when adding or modifying backend PHP code:
  1. Creating new code structures: See file-entities.md for conventions on creating classes and organizing files (but for new unit test files see unit-tests.md).
  2. Naming conventions: See code-entities.md for naming methods, variables, and parameters
  3. Coding style: See coding-conventions.md for general coding standards and best practices
  4. Type annotations: See type-annotations.md for PHPStan-aware PHPDoc annotations
  5. Working with hooks: See hooks.md for hook callback conventions and documentation
  6. Dependency injection: See dependency-injection.md for DI container usage
  7. Data integrity: See data-integrity.md for ensuring data integrity when performing CRUD operations
  8. Writing tests: See unit-tests.md for unit testing conventions
添加或修改后端PHP代码时,请遵循WooCommerce项目规范:
  1. 创建新代码结构:有关创建类和组织文件的规范,请参阅file-entities.md(但新单元测试文件请参阅unit-tests.md)。
  2. 命名规范:有关方法、变量和参数的命名规则,请参阅code-entities.md
  3. 编码风格:有关通用编码标准和最佳实践,请参阅coding-conventions.md
  4. 类型注解:有关支持PHPStan的PHPDoc注解,请参阅type-annotations.md
  5. 钩子使用:有关钩子回调规范和文档,请参阅hooks.md
  6. 依赖注入:有关DI容器的使用,请参阅dependency-injection.md
  7. 数据完整性:有关执行CRUD操作时确保数据完整性的方法,请参阅data-integrity.md
  8. 编写测试:有关单元测试规范,请参阅unit-tests.md

Key Principles

核心原则

  • Always follow WordPress Coding Standards
  • Use class methods instead of standalone functions
  • Place new internal classes in
    src/Internal/
    by default
  • Use PSR-4 autoloading with
    Automattic\WooCommerce
    namespace
  • Write comprehensive unit tests for new functionality
  • Run linting and tests before committing changes
  • 始终遵循WordPress编码标准
  • 使用类方法而非独立函数
  • 默认将新的内部类放置在
    src/Internal/
    目录中
  • 使用带有
    Automattic\WooCommerce
    命名空间的PSR-4自动加载机制
  • 为新功能编写全面的单元测试
  • 提交更改前运行代码检查和测试

Version Information

版本信息

To determine the next WooCommerce version number for
@since
annotations:
  • Read the
    $version
    property in
    includes/class-woocommerce.php
    on the trunk branch
  • Remove the
    -dev
    suffix if present
  • Example: If trunk shows
    10.4.0-dev
    , use
    @since 10.4.0
  • Note: When reviewing PRs against trunk, the version in trunk is correct even if it seems "future" relative to released versions
@since
注解确定下一个WooCommerce版本号的方法:
  • 读取主干分支上
    includes/class-woocommerce.php
    文件中的
    $version
    属性
  • 如果存在
    -dev
    后缀,请将其移除
  • 示例:如果主干分支显示
    10.4.0-dev
    ,则使用
    @since 10.4.0
  • 注意:在审核针对主干分支的PR时,即使主干分支的版本相对于已发布版本看起来是“未来版本”,该版本仍然是正确的