主题开发文档

💡 云策文档标注

概述

本文档介绍了 WordPress 主题测试的核心流程,包括使用主题单元测试数据填充站点以模拟内容,以及执行手动测试来验证主题功能和边缘情况响应。

关键要点

  • 使用主题单元测试数据(WordPress 导入文件)为站点生成测试用的文章、媒体和用户等存根数据。
  • 执行手动主题单元测试,检查主题功能和对内容、设置边缘情况的响应。
  • 修复 PHP 和 WordPress 错误,例如在 wp-config.php 中设置 define('WP_DEBUG', true) 以显示弃用函数调用和其他错误。
  • 根据模板文件清单检查模板文件。
  • 验证 HTML 和 CSS,检查 JavaScript 错误。
  • 在目标浏览器(如 Safari、Chrome、Opera、Firefox 和 Microsoft Edge)中进行测试。
  • 清理多余的注释、调试设置或 TODO 项。
  • 如果主题要公开发布并提交到主题目录,请参考主题审查指南。

代码示例

define('WP_DEBUG', true);

注意事项

  • 主题单元测试是手动过程,需逐步执行以确保全面覆盖。
  • 调试设置仅用于测试环境,发布前应移除或禁用。
  • 浏览器测试应覆盖所有目标平台,以确保兼容性。

📄 原文内容

The Theme Unit Test data is a WordPress import file will fill a WordPress site with enough stub data (posts, media, users) to test a theme.

The Theme Unit Tests are manual tests to walk through to test theme functionality and how the theme responds to the edge-cases of content and settings.

Theme Unit Test Overview

  1. Fix PHP and WordPress errors. Add the following debug setting to your wp-config.php file to see deprecated function calls and other WordPress-related errors: 
    define('WP_DEBUG', true);
    See Deprecated Functions Hook for more information.
  2. Check template files against Template File Checklist (see above).
  3. Do a run-through using the Theme Unit Test.
  4. Validate HTML and CSS. See Validating a Website.
  5. Check for JavaScript errors.
  6. Test in all your target browsers. For example Safari, Chrome, Opera, Firefox and Microsoft Edge.
  7. Clean up any extraneous comments, debug settings or TODO items.
  8. See Theme Review if you are publicly releasing the Theme by submitting it to the Themes Directory.